Cropping an Imagesc image
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2015-5-27
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 个评论
Walter Roberson
2015-5-28
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.)
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!