Cropping image with Bounding Box
13 ビュー (過去 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!