Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

sampling of an image matlab code



Aim: To perform sampling of an image

Equipments:

Operating System :-     Windows XP
Software:-                    Matlab 7.5, Image Processing Toolbox.

Program:

if (nargin==0)
    hFig    = figure( 'visible','off' );
    hImage  = image;
    Child   = get( hImage,'cdata' );
    close( hFig );
            out     = updownsample( Child,300,300,0,1 );
            figure;
            colormap gray;
            subplot( 1,2,1 );
            imagesc( Child );
            subplot( 1,2,2 );
            imagesc( out );
    return
elseif (nargin<5)
    error( 'UpDownSample - insufficient input parameters' );
end
% get input image size, and calculate the gain
[in_y_sz,in_x_sz] = size( in_m );
gain_x = out_x_sz/in_x_sz;
gain_y = out_y_sz/in_y_sz;
% check if up/down sampling is needed at all
if (gain_x == 1) & (gain_y==1)
    % same gain -> do not change sampling rate
    if is_fourier_flag
        switch is_real_flag
            case 0, out_m = ifft2( in_m );
            case 1, out_m = real( ifft2( in_m ) );
            case 2, out_m = abs( ifft2( in_m ) );
        end
    else
        out_m = in_m;
    end
else
    % upsample or downsample as needed
    % convert to fourier domain, if input is given in the space domain
    if ~is_fourier_flag
        in_m = fft2(in_m);
    end
      % if the input is even & output is odd-> use floor for all
    % if the output is even & input is odd -> use ceil for all
    % for downsampling -> the opposite
    if (~mod( in_x_sz,2 ) & (out_x_sz>in_x_sz)) | (mod( in_x_sz,2 ) & (out_x_sz<in_x_sz))
        x_output_space  = max(floor((out_x_sz-in_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)];
        x_input_space   = max(floor((in_x_sz-out_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)];
    else
        x_output_space  = max(ceil((out_x_sz-in_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)];
        x_input_space   = max(ceil((in_x_sz-out_x_sz)/2),0) + [1:min(in_x_sz,out_x_sz)];
    end
    if (~mod( in_y_sz,2 ) & (out_y_sz>in_y_sz)) | (mod( in_y_sz,2 ) & (out_y_sz<in_y_sz))
       y_output_space  = max(floor((out_y_sz-in_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)];
       y_input_space   = max(floor((in_y_sz-out_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)];
   else
       y_output_space  = max(ceil((out_y_sz-in_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)];
       y_input_space   = max(ceil((in_y_sz-out_y_sz)/2),0) + [1:min(in_y_sz,out_y_sz)];
   end
       % perform the up/down sampling
    padded_out_m    = zeros( out_y_sz,out_x_sz );
    in_m            = fftshift(in_m);
    padded_out_m( y_output_space,x_output_space ) = in_m(y_input_space,x_input_space);
    out_m           = (gain_x*gain_y)*ifft2(ifftshift(padded_out_m));  
          switch is_real_flag
        case 0, % do nothing
        case 1, out_m   = real( out_m );
        case 2, out_m   = abs( out_m );
    end
   
end


Result:-


1 comments:

Anonymous said...

Can anyone help me? i need program code for quantum radial basis function neural networks as a classifier circuit for EEG signals ... really need help on this where the matlab programme code is able tomake classification and prove the enhanciments
.. i hope you will reply soon

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.