Connected Components Labeling on Label Matrix

Hello there.
I try to implement SLIC Superpixels Method on MATLAB. I've done the clustering part and as writers said in this paper I need to apply a connected components labeling algorithm to get rid of bad labels. Upper image is output of SLIC code written by writers of paper and the other one is output of my SLIC code but without connected components part. Input of the connected components algorithm must be the "Label Matrix" which has same size as image but contains only labels which have more values than just 0 or 1. So how can I correct the bad labels?

Answers (2)

superpixels() already gives the labeled (connected components) image. https://www.mathworks.com/help/images/ref/superpixels.html?s_tid=srchtitle
Show your code where you called superpixels().
Also define what it is that you think makes a label "bad" as opposed to good. It doesn't make sense to have labels as only 0 or 1. You will have numbers up as high as the number of superpixel regions that were found. Virtually every region in there will have label numbers more than 1.
And you say "Input of the connected components algorithm must be the "Label Matrix"" Not true. Labeling and determining the connected components are the same thing. There are two functions for that - bwlabel() and bwconncomp() - and they both work off binary images. It doesn't make sense to send an already-labeled image into bwlabel() or bwconncomp() as you said. Actually the output of the connected components algorithm will be the "Label Matrix", NOT the input.
Bottom line - I don't know what you need to do. Your said your overall task is "to implement SLIC Superpixels Method" and that is done by the superpixels() function. Use it, if you haven't already. I don't know what else to answer.

4 Comments

At first, many thanks for your quick answer.
As you stated "superpixels()" function is built-in and it only works for RGB, Grayscale etc. (3 bands or lower banded) images. I needed to write a SLIC code that works on Hyperspectral images which have 100 or more channels. The picture at down is output of my own code but I write my own code to detect if input is an RGB/Grayscale Image or Hyperspectral Image so it can work on both Hyperspectral Images and 3 or 1 Band Images. I used an RGB image to show my problem because native SLIC code only supports 3 or 1 Band Images. Since bwlabel() and bwconncomp() are written for Binary Images I can not use them.
If you look my results, you can see some "White regions" inside borders of superpixels. That makes it a bad label.
I've communicated with one of the authors of paper and he said me to use "Label Matrix" and if you look their source code that were written in C they also used "Label Matrix" as input and as an output they created a "Updated Label Matrix".
So the problem I am dealing here with writing my own SLIC code. From scratch.
Here are the .m files those I've written.
slic.m is the main function. All of the others are called inside of "slic.m"
Sorry, but that looks like a substantial code base for me to delve into. I'm sorry that I won't be able to donate the time it might take to solve it for you. Generally I only spend a few minutes on code for each question, and it looks like your situation might take substantially more than that. Good luck with it. If it's important, perhaps you can hire the author to finish it or get it working for you.
I do not have money to hire and even if I had money I do not think that he accept that. Thanks for your help anyway.

Sign in to comment.

If you want to implement SLIC yourself, rather than use the implementation that is already in the Image Processing Toolbox as superpixels(), then I would recommend looking at the following site which includes reference implementations of SLIC:
The MATLAB implementation of SLIC already performs the post-processing step you are referring to in which labeled regions below some minimum size are merged with adjacent regions.

Asked:

on 4 Jun 2017

Answered:

on 5 Jun 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!