필터 지우기
필터 지우기

cropping multiple images in the folder automatically using imcrop with same cropping area

조회 수: 1 (최근 30일)
I have 12 images in the folder, i have wrritten a code for cropping those images and saving them automatically with the same cropping area if you crop one image.
Problem i am facing is, it is cropping first image only and saving that first cropped image 12 times (because number images are 12) with different image names (Sample3_ 1, Sample3_ 2,....,Sample3_ 12) as i suggested in the code not cropping remaing 11 images. Can anyone please let me know what is wrong with my code or suggest me how can i get it done.
Below is code for reference
numFiles = numel(FileNames); % no of images 12
for m = 1:numFiles
a = imread(FileNames{m});
if m == 1
ROI=imcrop(a);
drawnow;
end
filename = sprintf('Sample3_ %d.tiff', m);
fpath = 'C:\Users\Admin\Documents\MATLAB\DIC Challenge 1.0/EXAMPLE_SAMPLE'
fullFileName = fullfile(fpath, filename); imwrite(ROI, fullFileName)
end
Thanks in advance
  댓글 수: 2
Rik
Rik 2023년 1월 7일
I don't get notified by a tag. I happened to see this question, but I could easily have missed it.
How exactly did you want to solve the problem that your images are not the same size?
HARISH KUMAR
HARISH KUMAR 2023년 1월 7일
Okay, Images are same size only.
I want to crop all of those images and do some DIC Analysis on them.
Thanks

댓글을 달려면 로그인하십시오.

채택된 답변

KSSV
KSSV 2023년 1월 7일
fpath = 'C:\Users\Admin\Documents\MATLAB\DIC Challenge 1.0/EXAMPLE_SAMPLE' ;
numFiles = numel(FileNames); % no of images 12
for m = 1:numFiles
a = imread(FileNames{m});
if m == 1
[ROI,Rect]=imcrop(a);
drawnow;
[m,n,p] = size(a) ;
else
% a = imresize(a,[m n]) ; % in case images are of different size use this
ROI = imcrop(a,Rect) ;
end
filename = sprintf('Sample3_ %d.tiff', m);
fullFileName = fullfile(fpath, filename); imwrite(ROI, fullFileName)
end
  댓글 수: 1
HARISH KUMAR
HARISH KUMAR 2023년 1월 7일
@KSSV Thank you so much Sir, i was strugling to get this done since today morning. You made my day.
Thanks again :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2023년 1월 7일
Also see the FAQ for how to read a sequence of files:

Community Treasure Hunt

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

Start Hunting!

Translated by