フィルターのクリア

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 Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by