M.R.
M.R.

Reputation: 1073

How to find morphological components in an image?

I'm looking for a python function that gives the morphological components of an image. That is, will return a metric in which each pixel of image is replaced by an integer index representing the connected foreground image component in which the pixel lies. Something like this:

enter image description here

Ideally I could then compute properties of each components like mean color, area, standard deviation.

References:

Upvotes: 3

Views: 672

Answers (2)

Yngve Moe
Yngve Moe

Reputation: 1167

What you are looking for is superpixel algorithms. These normally work by performing some clustering on the images where both colour and position are features used during clustering. As far as I know, SLIC are the most popular superpixel algorithm, but I might be wrong here.

Slic (and other superpixel algorithms) are implemented in SciKit Image and they have a tutorial where they compare different superpixel algorithms that they have implemented here.

Here's a quick script to illustrate how to use SLIC with SciKit Image.

from skimage.segmentation import slic 
from skimage.data import astronaut 
import matplotlib.pyplot as plt  

image = astronaut()                                           
superpixels = slic(image, n_segments=200) # n_segments is approximate 

# Plot the figure                                                    
plt.figure()                                                 
plt.subplot(121)                                             
plt.imshow(image) 
plt.title('Original image') 
ax = plt.subplot(122)       
plt.imshow(superpixels)    
plt.title('Superpixels') 
plt.colorbar()                
plt.show() 

Here is the output of this. Output image from the script above

Edit: Some people have reported good results by using superpixels several times on an image, setting the colour of each superpixel to their mean value (and maybe some texture features such as standard deviation).

Edit 2: Here is the image from the SciKit Image comparison Comparison of superpixel algorithms

Upvotes: 2

buffalo974
buffalo974

Reputation: 53

The problem is in defining areas.with a list of dicts: You can take RGB value each time you meet another one and register it as a key, xy as a list of value for pixel having same color.

The big problem is for splitting same group color with geographic distinct areas. You will need iteration to test neighboorhood colors To know if dame group or not.

Upvotes: -1

Related Questions