필터 지우기
필터 지우기

Cropping rectangular part of an image

조회 수: 5 (최근 30일)
Elie
Elie 2014년 2월 11일
댓글: Elie 2014년 2월 11일
I'm building a project based on the example stated in this link : http://www.mathworks.com/help/vision/gs/object-detection-and-tracking.html#btt5qyu , "Detect Objects in a Cluttered Scene Using Point Feature Matching.
After detecting the needed part of the target image , a rectangular polygon is plotted around it, i need to crop the part of the target image enclosed by this polygon.
i tried the following method.
Icropped=imcrop(II,newBoxpolygon);
This snap of the code
if true
boxPolygon = [1, 1;... % top-left
size(boxImage, 2), 1;... % top-right
size(boxImage, 2), size(boxImage, 1);... % bottom-right
1, size(boxImage, 1);... % bottom-left
1, 1]; % top-left again to close the polygon
% Transform the polygon into the coordinate system of the target image. The transformed polygon indicates the location of the object in the scene.
newBoxPolygon = transformPointsForward(tform, boxPolygon);
%Display the detected object.
figure();
imshow(sceneImage);
hold on;
line(newBoxPolygon(:, 1), newBoxPolygon(:, 2), 'Color', 'R');
title('Detected Box');
Icropped=imcrop(II,newBoxPolygon);
imshow(Icropped);
end
and also i tried Icropped=imcrop(II,line); (Note:II is my target image) in both cases im getting an error i dont know whats the problem can any one tell me whats the problem with the method im using. this is the error im getting " [x,y,a,cm,spatial_rect,h_image,placement_cancelled] = parseInputs(varargin{:}); "
Thanks in return.

채택된 답변

Iain
Iain 2014년 2월 11일
If you want to get a rectangular part of an image, all you need is:
cropped = original(top:bottom, left:right,:);
If you want another shape, then you need to use a slightly different method:
mask = logical([0 1 0;
1 1 1;
0 0 0]); % this needs thought on your part.
image = [1 2 3;
2 2 2;
3 1 0];
cropped_ish = image .* mask
  댓글 수: 1
Elie
Elie 2014년 2월 11일
Thank you , but how im supposed to get the coordinates of the rectangle that is plotted around the image as shown above in order to crop it. am lost.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by