Cropping image with Bounding Box
조회 수: 12 (최근 30일)
이전 댓글 표시
I keep getting this error when I am trying to crop the image, any advice?
??? Error using ==> imageDisplayParseInputs at 173
Invalid input arguments.
Error in ==> imshow at 173
[common_args,specific_args] = ...
Error in ==> imcrop>parseInputs at 242
imshow(a,cm);
Error in ==> imcrop at 94
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
Error in ==> TestMeasure at 69
subImage = imcrop(Q, bound);
This is my code:
Q = imread('IMG_1800.jpg');
bound = regionprops(Q, 'BoundingBox');
subImage = imcrop(Q, bound);
imshow(subImage);
Thank you!
댓글 수: 0
답변 (3개)
KALYAN ACHARJYA
2019년 8월 6일
편집: KALYAN ACHARJYA
2019년 8월 6일
Please note imcrop creates an interactive Crop Image tool with the image displayed in the current figure. See detail
Q = imread('.....');
bound=regionprops(Q,'BoundingBox');
Here regionprops measure properties of image regions, which return in structure
>> whos bound
Name Size Bytes Class Attributes
bound 255x1 40864 struct
Now you try to crop??
subImage = imcrop(Q,bound);
It would be better if you define the region of subimage as like
subImage=imcrop(Q,[R1 C1 R2 C2];
Please elaborate, if you need further help.
댓글 수: 0
Neuropragmatist
2019년 8월 6일
What sort of image is 'IMG_1800.jpg'?
Because regionprops expects a logical or labelled image as the first input.
If your image is a logical or labelled image the output of regionprops will likely have multiple values (in struct format in your code) and the error results because imcrop doesn't know what to do with that.
댓글 수: 0
Mohammad Farhad Aryan
2020년 3월 27일
편집: Mohammad Farhad Aryan
2020년 3월 27일
You can use the edited version of your code as below:
Q = imread('IMG_1800.jpg');
binaryImage = im2bw(Q);
labeledImage = bwlabel(binaryImage);
bound = regionprops(binaryImage, 'BoundingBox');
coord = bound.BoundingBox;
subimage = imcrop(Q, [coord(1), coord(2), coord(3), coord(4]); % You can x, y, height and width for coord(k)
imshow(subImage);
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!