Cropping image with Bounding Box
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (3)
KALYAN ACHARJYA
le 6 Août 2019
Modifié(e) : KALYAN ACHARJYA
le 6 Août 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 commentaires
Neuropragmatist
le 6 Août 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 commentaires
Mohammad Farhad Aryan
le 27 Mar 2020
Modifié(e) : Mohammad Farhad Aryan
le 27 Mar 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 commentaires
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!