Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between opencv ximgproc.slic and skimage segmentation.slic?

I run the SLIC (Simple Linear Iterative Clustering) superpixels algorithm from opencv and skimage on the same picture with, but got different results, the skimage slic result is better, Shown in the picture below.First one is opencv SLIC, the second one is skimage SLIC. I got several questions hope someonc can help.

  1. Why opencv have the parameter 'region_size' while skimage is 'n_segments'?
  2. Is convert to LAB and a guassian blur necessary?
  3. Is there any trick to optimize the opecv SLIC result?

===================================

  • OpenCV SLIC

Opencv SLIC

  • Skimage SLIC

Skimage SLIC

# Opencv
src = cv2.imread('pic.jpg') #read image
# gaussian blur
src = cv2.GaussianBlur(src,(5,5),0)
# Convert to LAB
src_lab = cv.cvtColor(src,cv.COLOR_BGR2LAB) # convert to LAB

# SLIC
cv_slic = ximg.createSuperpixelSLIC(src_lab,algorithm = ximg.SLICO, 
region_size = 32)
cv_slic.iterate()



# Skimage
src = io.imread('pic.jpg')
sk_slic = skimage.segmentation.slic(src,n_segments = 256, sigma = 5)

Image with superpixels centroid generated with the code below

# Measure properties of labeled image regions
regions = regionprops(labels)
# Scatter centroid of each superpixel
plt.scatter([x.centroid[1] for x in regions], [y.centroid[0] for y in regions],c = 'red')

but there is one superpixel less(top-left corner), and I found that

len(regions) is 64 while len(np.unique(labels)) is 65 , why?

enter image description here

like image 824
Yifeng_Li Avatar asked Jul 15 '19 12:07

Yifeng_Li


People also ask

What is super pixel segmentation?

β€œIn computer vision, image segmentation is the process of partitioning a digital image into multiple segments (sets of pixels, also known as super-pixels). The goal of segmentation is to simplify and/or change the representation of an image into something that is more meaningful and easier to analyze.

What is SLIC in image processing?

The SLIC algorithm is used for segmentation based on the similarity of LAB color and spatial distance. Its advantages of short time consumption, uniform size of superpixel block, and regular contour are widely used in color image, optical remote sensing, natural scene, and other image segmentation tasks.

What is simple linear iterative clustering?

Simple Linear Iterative Clustering (SLIC) is one of the most excellent superpixel segmentation algorithms with the most comprehensive performance and is widely used in various scenes of production and living.


1 Answers

I'm not sure why you think skimage slic is better (and I maintain skimage! πŸ˜‚), but:

  • different parameterizations are common in mathematics and computer science. Whether you use region size or number of segments, you should get the same result. I expect the formula to convert between the two will be something like n_segments = image.size / region_size.
  • The original paper suggests that for natural images (meaning images of the real world like you showed, rather than e.g. images from a microscope or from astronomy), converting to Lab gives better results.
  • to me, based on your results, it looks like the gaussian blur used for scikit-image was higher than for openCV. So you could make the results more similar by playing with the sigma. I also think the compactness parameter is probably not identical between the two.
like image 153
Juan Avatar answered Oct 02 '22 19:10

Juan