Organizing Images based upon their size

2 views (last 30 days)
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

Accepted Answer

Sean de Wolski
Sean de Wolski on 19 May 2011
%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
  4 Comments
Frank
Frank on 19 May 2011
The directories are correct
Frank
Frank on 19 May 2011
Works great, thank you very much!

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!