フィルターのクリア

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