How to zero pad the cut image when it reached a boundary on actual image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gopichandh Danala
am 30 Mai 2017
Kommentiert: Gopichandh Danala
am 2 Jun. 2017
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
0 Kommentare
Akzeptierte Antwort
Abel Babu
am 2 Jun. 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
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!