Filter löschen
Filter löschen

Organizing Images based upon their size

1 Ansicht (letzte 30 Tage)
Frank
Frank am 19 Mai 2011
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

Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 19 Mai 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 Kommentare
Frank
Frank am 19 Mai 2011
The directories are correct
Frank
Frank am 19 Mai 2011
Works great, thank you very much!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by