MATLAB: How to count the number of pixels of each region in an image ( searching for big regions)

Image Processing Toolboxsearching for big regions

I want to count the number of pixels in each region of an image. The image contains more than one region and i want to ignore the big regions, so i want to search for big regions. Does any one know how to do this

Best Answer

  • Use regionprops(). Assuming you already have a binary image of your regions, get all the areas like this:
    % Measure all blob areas.
    blobMeasurements = regionprops(binaryImage, 'Area');
    allAreas = [blobMeasurements.Area]
    % Sort in ascending order
    [sortedAreas, sortIndexes] = sort(allAreas, 'ascend');
    % Take the first 10 smallest:
    smallAreas = sortedAreas(1:10);