MATLAB: Get objects from non binarized image

bwareafilt()Image Processing Toolboximage segmentation

I use imbinarize() to prepare an image for bwareafilt() to get objects. Once I get the objects, how can I extract the pixels from the original, non-binary image, that match the objects from bwareafilt() ?

Best Answer

In short, use regionprops() and ask for 'PixelValues':
props = regionprops(binaryImage, grayImage, 'PixelValues');