Search code examples
pythonnumpyimage-segmentationscikit-image

merge region based on area


i need to merge small regions from the Label product of scikit-image slic until reach an area regions threshold

the slic itself has a min_size_factor which is not the solution in my case because it has unwanted affect at overall result of labeling.

the way i can calc regions area :

def pixelcount(regionmask):
    return np.sum(regionmask)
props = regionprops(label_img, extra_properties=(pixelcount,))

there is a way same as cut_normalized function (which work on colors similarity of pre-calculated RAG) for regions area?

any help appreciated.


Solution

  • for someone who may encounter this :

    • build a RAG by scikit_image with "pixel count" as data attached to nodes

    • define "weight" equal to below code and merge normalize :

        for x, y, d in graph.edges(data=True):
            diff = graph.nodes[x]['pixel count'] - graph.nodes[y]['pixel count']
            diff = np.linalg.norm(diff)