Cropping image with Bounding Box
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (3)
KALYAN ACHARJYA
am 6 Aug. 2019
Bearbeitet: KALYAN ACHARJYA
am 6 Aug. 2019
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 Kommentare
Neuropragmatist
am 6 Aug. 2019
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 Kommentare
Mohammad Farhad Aryan
am 27 Mär. 2020
Bearbeitet: Mohammad Farhad Aryan
am 27 Mär. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!