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
2014-3-7
Don't use evalc(). Don't create variables like that in a loop. Read this http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!