codelearn22
codelearn22

Reputation: 43

How to extract content of each superpixel and resize them?

SuperPixeled image

This is the image and I want to save only the non-black region superpixels after resizing them to 56x56. I am working on superpixel classification.

Upvotes: 0

Views: 878

Answers (1)

mannyglover
mannyglover

Reputation: 2319

You can use skimage.measure.regionprops.

from skimage.segmentation import slic
from skimage.measure import regionprops

# Assume image is given
segments = slic(image, n_segments=numSegments, compactness=0.1,enforce_connectivity=True)
props = regionprops(segments,intensity_image=image)

segmentsToExclude = []
for s, segment in enumerate(segments):
    if props[s].mean_intensity < 5: # basically black
        segmentsToExclude.append(s)

Something along those lines. Check out this skimage link for more information on regionprops.

Upvotes: 1

Related Questions