필터 지우기
필터 지우기

Read, Crop and then Save multiple images

조회 수: 33 (최근 30일)
Marco Beccarini
Marco Beccarini 2018년 4월 12일
댓글: Mustafa Yildiz 2020년 3월 29일
I am really new to Matlab, but I need for a project to crop multiple images with the same rectangle and then save them into a new folder.
(I have 172 images in the folder, first one is called frame10.jpg, last one is frame182.jpg)
Here's my code so far:
for n=10:182
image_{n}=imread(sprintf('frame%s.jpg', num2str(n)));
end
[x rect] = imcrop(image_{10})
for n=11:182
imcrop(image_{n}, rect)
end
When I Run it, it opens up all the figures of the images correctly cropped.
My questions are: how can I tell matlab not to open up all the figures of the cropped images since I do not need to see them?
How do I save all the cropped images in a new folder 'Cropped' inside the current folder? (possibly using imwrite but it's not necessary)

채택된 답변

KSSV
KSSV 2018년 4월 12일
편집: KSSV 2018년 4월 14일
images = dir('*.jpg') ; % GEt all images of the folder
N = length(images) ; % number o fimages
I = imread(images(1).name) ; % crop one to get rect
[x, rect] = imcrop(I) ;
for i = 1:N
I = imread(images(i).name) ; % REad image
I = imcrop(I,rect) ; % crop image
[filepath,name,ext] = fileparts(images(i).name) ;
imwrite(I,strcat(name,'cropped',ext)) ; % Save image
end
  댓글 수: 8
hana razak
hana razak 2018년 9월 6일
Thank you very much dear experts. Your answers really made my day :)
nisa sarfraz
nisa sarfraz 2020년 1월 14일
I = imread(images(1).name) ; % crop one to get rect
this line gives error of index matrix dimension exceeds. please suggest some solution.

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

추가 답변 (1개)

Ismail Nasri
Ismail Nasri 2020년 2월 7일
</matlabcentral/answers/uploaded_files/270469/Captureblm.PNG> Hiw can i use this script for detecting crop and saving multiples images
  댓글 수: 1
Mustafa Yildiz
Mustafa Yildiz 2020년 3월 29일
Hello did you find any way for do that ?

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by