Cropping an Imagesc image
20 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Robert Roy
am 27 Mai 2015
Kommentiert: Walter Roberson
am 28 Mai 2015
Hi there, I am currently working on a code which creates an image using imagesc, and then wanting to crop the image, I can do this while using the interactive cropping tool however whenever I try to use the [rect] method to create the crop it comes up with the message:
Error using imcrop>checkCData (line 410)
Invalid input image.
Error in imcrop>parseInputs (line 256) checkCData(a);
Error in imcrop (line 93)
[x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:});
Error in Cropped (line 51)
Cr=imcrop(figure(1),[220 619 650 50]);
The code is
Cr=imcrop(figure(1));
figure(2);
imagesc(flipud(Cr));
set(gca,'YDir','normal');
Figure(1) is an image created from imagesc.Just wondering if anyone can help. Thanks
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Mai 2015
When you pass in a handle, you cannot also pass in the crop vector. I note that the error message corresponds to a line of code that includes the vector but your claimed code does not include the vector.
I notice that you imagesc() the data returned from the crop operation. Are you intending that the crop return the original data that was submitted to be scaled for display? If so then imcrop() that matrix of data. If for some reason you do not have the matrix, then
imh = findobj(figure(1), 'type', 'image');
YourData = get(imh(1),'CData');
Cr = imcrop(YourData, [220 619 650 50]);
2 Kommentare
Walter Roberson
am 28 Mai 2015
If you look at the documented forms of imcrop, one of them is
imcrop(h)
which is the form for passing in a handle. In that form, it locates the image and gives you an interactive cropping session.
There is another form shown in the documentation,
imcrop(I)
where I is an image array; when you pass in an image array in this form, it displays the image and then gives you an interactive cropping session.
There is a third form,
imcrop(I, rect)
In that form, it takes the image array you pass in and does the cropping and returns the cropped image without displaying it.
If you look at the lists of allowed forms, there is no form for
imcrop(h, rect)
That is, it is is not allowed to pass in a handle, have it find the associated image, and automatically perform the specified cropping and return the rectangle. If you pass in a handle, you are not allowed to pass in any other options (though potentially you are allowed to pass in "x" and "y" before the handle; it is an obscure and confusing possibility.)
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!