MATLAB: Organizing Images based upon their size

image processingorganize

Hello!
I'm trying to organize a set of images by copying them into a specified folder. Only certain images will be copied based upon their size, in this case the image is: 64 pixels in width, and 250 pixels in height. However the script doesn't work, can anyone help?
Thanks
-Frank
Image
This is one of the desired image copied into a different folder
Code
source_dir = 'C:\Users\xuf\Desktop\LineScan-2010_12_08-005';
dest_dir = 'C:\Users\xuf\Desktop\LineScan-2010_12_08-005\Target';
source_files = dir(fullfile(source_dir, '*.tif'));
for i = 1:length(source_files)
data = imread(fullfile(source_dir,source_files(i).name))
[rmax, cmax] = size(source_files)
if rmax == 250;
imwrite(fullfile(dest_dir,source_files(i).name), data)
end
end

Best Answer

%Assuming these are correct, Make sure dest_dir exists
source_dir = 'C:\Users\xuf\Desktop\LineScan-2010_12_08-005\';
dest_dir = 'C:\Users\xuf\Desktop\LineScan-2010_12_08-005\Target\';
cd(source_dir);
directory = dir( '*.tif');
for ii = 1:length(directory)
I = imread(directory(ii).name);
if isequal(size(I),[250 64]); %Edit
imwrite(I,[dest_dir directory(ii).name]);
end
end