how should i modify the below code so that i could be able to resize the grayscale image..instead of resizing the original image..please do guide me..

2 views (last 30 days)
close all; clear all; clc;
for i=1:50 img =imread(['C:\Users\shree\Desktop\final data\target\' num2str(i) '.jpg']); evalc(['o' num2str(i) '=img;']); %original image
evalc(['g' num2str(i) '=rgb2gray(img);']); %grayscale
evalc(['r' num2str(i) '=imresize(img,[50 50]);']); %resized original image
end figure,imshow(o35); title('original'); figure,imshow(g35); title('gray'); figure ,imshow(r35); title('resized');

Answers (1)

Image Analyst
Image Analyst on 7 Mar 2014
Try this:
folder = 'C:\Users\shree\Desktop\final data\target\';
counter = 1;
for k=1:50
baseFileName = sprintf('%d.jpg', k);
fullFileName = fullfile(folder, baseFileName);
if exists(fullFileName, 'file')
% If file exists, read it in.
img =imread(fullFileName);
imshow(img);
drawnow; % Force it to display.
o{counter} = img; %original image
grayImage{counter} = rgb2gray(img); %grayscale
% Resize gray scale image
r{counter}=imresize(grayImage{counter}, [50 50]);
% Increment counter
counter = counter + 1;
else
message = sprintf('Warning: File does not exist:\n%s', fullFileName);
uiwait(warndlg(message));
end
end
% Display for image #35 only.
subplot(2,2,1);
imshow(o{35});
title('original');
subplot(2,2,2);
imshow(g{35});
title('gray');
subplot(2,2,3);
imshow(r{35});
title('resized');
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
but I don't see why you're storing all those images in the first place, unless you need them later for some reason that's not shown.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!