Hi,

   I want to make u clear what my problem is.Actually i was given 
some matlab code.By using that matlab code i have to write a c 
program which is similar to matlab code and scales an image and save 
the image into another file..
Here i am giving the matlab code.If possible go through the code and 
try to give me what went wrong in my code.i dont know any thing 
about matlab that's why the problem arises i think can u solve me 
the problem..

function [imout, phasex, phasey]=scaler(im, OutHeight, OutWidth)
%
% im :  Input image
% OutHeight : Output image height
% OutWidth  : Output image width
%
% Mohammad Usman.
% March 21, 2007.
%

f = [0.25 0.5 0.25];
ntapsx = length(f);
ntapsy = length(f);

InHeight = size(im, 1);
InWidth = size(im, 2);

kx = InWidth / OutWidth;
ky = InHeight / OutHeight;

% Resize the input image for edge pixels.
im = [zeros(InHeight, fix(ntapsx/2+0.5), 3) ...
    im zeros(InHeight, fix(ntapsx/2+0.5), 3)];

% Horizontal filtering.
fprintf(1, 'Performing horizontal filtering ... \n');
for k = 1:3
    for i = 1: InHeight
        step = kx;
        for j = 1: OutWidth
            Ptr_in = j*kx;

            % Interger and fractional part.
            ptr = fix(Ptr_in);
            ph = Ptr_in-ptr;

            % Load the data.
            if (ptr > 3) & (ptr < (InWidth-3))
                x = double(im(i,ptr-1:ptr+2, k));
                % Get the output sample.
                imout(i, j, k) = (x(1)*(1-ph) + x(2)*ph)*f(1) ...
                    +  (x(2)*(1-ph) + x(3)*ph)*f(2) ...
                    +  (x(3)*(1-ph) + x(4)*ph)*f(3);
            else
                imout(i,j,k) = 0;
            end
        end
    end
end

% Output image of this stage is input to the next one.
im = imout;

% Resize the output image size.
im = [zeros(fix(ntapsy/2+0.5), OutWidth, 3);
    im;
    zeros(fix(ntapsy/2+0.5), OutWidth, 3)];

% Vertical filtering.
fprintf(1, 'Performing vertical filtering ... \n');
for k = 1:3
    % Go over the columns
    for j = 1: OutWidth
        step = ky;
        for i = 1: OutHeight
            Ptr_in = i*ky;
            
            % Find interger and fractional part.
            ptr = fix(Ptr_in);
            ph = Ptr_in-ptr;

            % Get the output sample.
            if (ptr > 3) & (ptr < (InWidth-3))
                
                % Load the data.
                x = double(im(ptr-1:ptr+2, j, k));
                imout(i, j, k) = (x(1)*(1-ph) + x(2)*ph)*f(1) ...
                    +  (x(2)*(1-ph) + x(3)*ph)*f(2) ...
                    +  (x(3)*(1-ph) + x(4)*ph)*f(3);
            else
                imout(i,j,k) = 0;
            end
        end
    end
end

imout = imout(1:OutHeight, 1:OutWidth, :);



--- In [email protected], Thomas Hruska <[EMAIL PROTECTED]> wrote:
>
> rafiuddin syed wrote:
> > Hi,
> >   Sorry to trouble you
> >    
> >       what does this mean..
> >   1. rolling your own library (instead of using a 
> > third-party library)
> >   2.nearest neighbor scaling 
> 
> 1)  "Rolling your own library" means you opted to write your own 
code 
> instead of using something someone else (or, in the case of 
ImageMagick, 
> many "someones") has written and debugged and generally worked out 
most 
> issues (e.g. performance).  Most libraries also have built-in 
scaling 
> algorithms (that are also debugged).  There are merits to rolling 
your 
> own library but you should have a good reason to do so before 
doing such 
> things.  The BMP file format is a lot more complex than your code 
> currently handles.
> 
> 2)  There are different scaling algorithms.  Start Photoshop and 
scale 
> an image using "Nearest Neighbor".  That's roughly the output 
you'll get 
> from your code and it looks ugly when scaling smaller and usually 
pretty 
> ugly when scaling larger on non-25% increments.  It is easy to do 
> nearest neighbor.  For more complex algorithms, you should rely on 
a 
> third-party library.
> 
> -- 
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
> 
> *NEW* VerifyMyPC 2.5
> Change tracking and management tool.
> Reduce tech. support times from 2 hours to 5 minutes.
> 
> http://www.CubicleSoft.com/VerifyMyPC/
>


Reply via email to