How to get a rectangular subimage from regionprops(Image,'BoundingBox') in Matlab?

后端 未结 2 2008
既然无缘
既然无缘 2020-12-29 01:02

I have some particles that I\'ve identified in a larger image, and need to parse into smaller images for each particle. I\'ve used the regionprops \'BoundingBox\' function,

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-29 01:23

    According to the documentation of REGIONPROPS:

    BoundingBox is [ul_corner width], where:

    • ul_corner: is in the form [x y z ...] and specifies the upper-left corner of the bounding box

    • width: is in the form [x_width y_width ...] and specifies the width of the bounding box along each dimension

    Now you can use IMCROP functions as imcrop(I, rect) where:

    rect is a four-element position vector [xmin ymin width height] that specifies the size and position of the crop rectangle.

    Thus:

    s = regionprops(L, 'BoundingBox');
    
    subImage = imcrop(I, s(1).BoundingBox);
    imshow(subImage)
    

提交回复
热议问题