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 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Image Analyst
el 7 de Mzo. de 2014
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
Respuestas (1)
Image Analyst
el 7 de Mzo. de 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.
0 comentarios
Ver también
Categorías
Más información sobre Image Processing and Computer Vision en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!