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