Organizing Images based upon their size

2 次查看(过去 30 天)
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

采纳的回答

Sean de Wolski
Sean de Wolski 2011-5-19
%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 个评论
Frank
Frank 2011-5-19
Works great, thank you very much!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by