Cropping an Imagesc image

조회 수: 6 (최근 30일)
Robert Roy
Robert Roy 2015년 5월 27일
댓글: Walter Roberson 2015년 5월 28일
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

채택된 답변

Walter Roberson
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
Robert Roy
Robert Roy 2015년 5월 28일
편집: Robert Roy 2015년 5월 28일
Thanks it seems to have worked. Apologies but I dont understand the 'When you pass in a handle, you cannot also pass in the crop vector' If you could explain that it would be appreciated. I made a mistake and can use the imshow function so long as i set the axis.
Walter Roberson
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개)

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by