フィルターのクリア

How to zero pad the cut image when it reached a boundary on actual image

2 ビュー (過去 30 日間)
Gopichandh Danala
Gopichandh Danala 2017 年 5 月 30 日
コメント済み: Gopichandh Danala 2017 年 6 月 2 日
Hi, I am trying to cut some images into smaller images based on some segmentation results.
Actual images size: 665x512 double
Cut Images size: 411x223 uint8
img = imread('FK0123000_1002_RML.jpg');
imgSize = size(img);
BW = bwlabel(img);
props = regionprops(BW,'centroid');
centroids = round(cat(1, props.Centroid));
cutImg = img(centroids(2)-204:centroids(2)+ 206, centroids(1)-110:centroids(1)+ 112);
figure, imshow(cutImg,[]);
In case if the segment in the actual image is within the below condition I am able to cut it, else I get an error. how to adjust this so it pads zeros for columns or rows if error condition comes?
The problem comes here:
cutImg = img(centroids(2)-204:centroids(2)+ 206, centroids(1)-110:centroids(1)+ 112);
Working Case:
Failed Case:
The second or failed case crosses the matrix dimensions to get the cut image, is there any way to automatically zero pad missing rows or columns?
Thanks

採用された回答

Abel Babu
Abel Babu 2017 年 6 月 2 日
Hi Gopichandh,
In order to cut out the portion of the image that has the segmented section, the best way would be to use a bounding box that is specified by the 'regionprops' function directly. This can be obtained by adding the 'Bounding Box' property for the 'regionprops' function. More about the same can be found in this link: https://in.mathworks.com/help/images/ref/regionprops.html#buoixjn-3
In effect, 'Bounding Box' will give you the smallest bounding box that can enclose the segmented section. This would be a better approach than hard-coding the values.
Abel
  1 件のコメント
Gopichandh Danala
Gopichandh Danala 2017 年 6 月 2 日
Thanks, BoundingBox helps me in getting the cords of rect around blob, I can append zeros around in all regions and get what I needed.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by