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..

1 次查看(过去 30 天)
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');

回答(1 个)

Image Analyst
Image Analyst 2014-3-7
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.

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by