필터 지우기
필터 지우기

crop multiple images with freehand

조회 수: 3 (최근 30일)
talayeh ghodsi
talayeh ghodsi 2020년 3월 25일
댓글: Image Analyst 2020년 8월 28일
hi every body. i want to crop multiple images with freehand , and i have written the code below, but i have this eror
Error in Untitled2 (line 19)
I = imcrop(I,BW) ; % crop image
could any body help me please?
images = dir('E:\phd\zahra taati\matlabprozhe\50%\ct50.0% - Copy\*.jpg'); % GEt all images of the folder
N = length(images) ; % number o fimages
I = imread(images(1).name) ;
h_im = imshow(I);
e = imfreehand ;
BW = createMask(e,h_im)
BW(:,:,2) = BW;
BW(:,:,3) = BW(:,:,1);
ROI = I;
ROI(BW == 0) = 0;
figure, imshow(ROI);
for i = 1:N
I = imread(images(i).name) ; % REad image
I = imcrop(I,BW) ; % crop image
[filepath,name,ext] = fileparts(images(i).name) ;
imwrite(I,strcat(name,'cropped',ext)) ; % Save image
end

채택된 답변

Ilian
Ilian 2020년 4월 8일
imcrop should have a rectangle as input, but you have a mask. You could use
roi = drawrectangle();
instead of imfreehand and then change imcrop to
I = imcrop(I,roi.Position);
  댓글 수: 3
Ilian
Ilian 2020년 8월 28일
If you want help I need a bit more than that.
Image Analyst
Image Analyst 2020년 8월 28일
You need to prepend the folder since the images are not in the current folder:
fullFileName = fullfile(images(i).folder, images(i).name);
I = imread(fullFileName) ; % Read image

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by