Cropping a particular object in an image

1 回表示 (過去 30 日間)
Aditya
Aditya 2016 年 3 月 30 日
回答済み: Image Analyst 2016 年 3 月 30 日
Hello,
I need to crop a specific object from an image, I have the object annotated and I also have the pixels of the boundaries of the object. Now I want to crop that particular object and nothing else. Please help me out.
Thanks.

採用された回答

Image Analyst
Image Analyst 2016 年 3 月 30 日
You said you " have the pixels of the boundaries of the object", so simply use them as indexes:
croppedImage = originalImage(row1:row2, col1:col2); % Gray scale.
croppedImage = originalImage(row1:row2, col1:col2, :); % If color RGB image.

その他の回答 (1 件)

Charles Dunn
Charles Dunn 2016 年 3 月 30 日
編集済み: Charles Dunn 2016 年 3 月 30 日
You might find Point in Polygon algorithms useful: https://en.wikipedia.org/wiki/Point_in_polygon
It would be a lot simpler if the object were guaranteed to be convex, but I doubt that is the case.
Here is a simple-ish method. Do a cumsum() horizontally on the binary boundary image. For any pixels with an odd cumsum value, they are in the shape. Or that binary mask with the boundary pixels, and you'll get a binary mask for your full shape.
There is an edge case where a boundary is horizontal, so your cumsum will run exactly along the boundary. I'm not sure how to handle that case robustly...
There are probably more efficient/robust methods as well.

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by