Image Re-size in Matlab

13 Ansichten (letzte 30 Tage)
Bullet200m
Bullet200m am 7 Mär. 2013
I'm trying to re-size a face database to 40x40 images in unit8 format. The code that I have written doesn't seem to be working properly(With my addition of unit8 formatting) Suggestions on how to adapt this would be much appreciated.
clear, close all
posData = 'E:\Mathworks code\fdtool_release\images\train\positives';
if ~isdir(posData)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', posData);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(posData, '*.pgm');
pgmFiles = dir(filePattern);
for k = 1:length(pgmFiles)
baseFileName = pgmFiles(k).name;
fullFileName = fullfile(posData, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray(:,:,k) = imresize(imread(fullFileName)),(40x40), [256 , 256]));
imagesc(imageArray(:,:,k));
axis off, axis image, colormap gray
drawnow;
end

Antworten (1)

Image Analyst
Image Analyst am 7 Mär. 2013
You don't have those args to imresize - those are wrong. It should look like this (untested):
thisImage = imread(fullFileName);
[rows columns, numberOfColorChannels] = size(thisImage);
if numberOfColorChannels > 1
thisImage = rgb2gray(thisImage); % Convert to gray scale so we can append.
end
% Resize
thisImage = imresize(thisImage, [40 40]);
% Append as slice in the 3D array.
imageArray(:,:,k) = thisImage;

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by