Image Re-size in Matlab
13 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 7 Mar 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;
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!