Image Re-size in Matlab

1 visualización (últimos 30 días)
Bullet200m
Bullet200m el 7 de Mzo. de 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

Respuestas (1)

Image Analyst
Image Analyst el 7 de Mzo. de 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;

Categorías

Más información sobre Convert Image Type en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by