Wednesday, March 16, 2016

MATLAB Code to read an image and subsample it to sizes 512, 256,128, 64,32.

clear
close all
Input = imread('Flower.jpg');
figure
subplot(2,3,1);
imshow(Input);
m = 1024;
s = num2str(m);
xlabel(s);

for i = 1:5,
    m = m/2;
    J=Input(1:2^i:size(Input,1),1:2^i:size(Input,2));
    subplot(2,3,i+1);
    imshow(J);
    s = num2str(m);
    xlabel(s); 
end;
gtext('using code');

% sampling using imresize()
m=1024;
scale=[512 256 128 64 32]
figure;
subplot(2,3,1);
imshow(Input);
s=num2str(m);
xlabel(s);

for i = 1:5
    m=m/2;
    subplot(2,3,i+1);
    imshow(imresize(Input,[scale(i) scale(i)]));
    s=num2str(m);
    xlabel(s);
end


gtext('using built-in function');

OUTPUT RESULT :


Sampling using Code



Sampling using built-in function imresize()We observe that sampling of an image with the use of manual code results in sharp edged images whereas the one with the built-in function produces a smoothed(blurry) images.

CONCLUSION:

Sampling process was carried out on an input image, subsampling its size to 512 × 512, 256 × 256, 128 × 128, 64 × 64 and 32 × 32 with the help of a built in function and a written code. The outputs are shown in Fig.1 and Fig.2. It can be seen that the output image remains nearly the same for 512 × 512, but a slow degradation starts for 128 × 128 and the image becomes virtually unusable for 32 × 32. Thus, it is safe to sample the image at half the original sampling rate as it does not cause any significant loss of information.

No comments:

Post a Comment