필터 지우기
필터 지우기

Organizing Images based upon their size

조회 수: 1 (최근 30일)
Frank
Frank 2011년 5월 19일
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일
The directories are correct
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