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

4 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Abel Babu
Abel Babu le 2 Juin 2017
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 commentaire
Gopichandh Danala
Gopichandh Danala le 2 Juin 2017
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by