how to access each superpixel individually?

3 views (last 30 days)
Ad
Ad on 13 Apr 2017
Commented: Ad on 17 Apr 2017
I have followed the procedure and really impressed by the work https://in.mathworks.com/help/images/ref/superpixels.html?s_tid=srchtitle. My question is how to access each superpixel individually like a regular pixel because I would like to perform certain operations on each pixel individually.

Answers (1)

Guillaume
Guillaume on 13 Apr 2017
The thing is that despite the name, a superpixel is nothing like a pixel. It's not square, it's just an arbitrarily shaped region of the image that has been determined to be similar.
You can mask the original image to keep only the portion corresponding to a given superpixel with:
%L = superpixels(originalimage, N);
originalimage(L == superpixelindex)
And certainly you can perform operations on that portion of the image. You could also use regionprops to extract the list of pixel indices belonging to each superpixel:
regionprops(L, 'PixelList')
but there's no way to get an individual superpixel value the same way you can a single pixel value.
  6 Comments
Image Analyst
Image Analyst on 15 Apr 2017
Guillaume - you're right. I was looking at the last "outputImage" in the help demo where the super pixels have been replaced by the mean value, but the original superpixels is basically just a description of where the various ROI outlines are - a boundaryMask. If you applied that to the original image it's possible to get a whole range of colors or gray levels instead of a single one.
Ad, I have no idea. If you have 200 superpixels, then the max value of L should be 200 and the number of elements of allIntensities should also be 200. What is the max value of L for you?
Your variables are badly named. What is I? Is that the labeled image or the original image? Don't just call it I - that's a really lousy name. And what's the point of S? You can get both MeanIntensity and PixelList all in the same call to regionprops() if you really think you need PixelList (though I'm not convinced you do because you have the labeled image which is better in most cases).
Ad
Ad on 17 Apr 2017
Hello! I have changed the code and calculated
[L,N] = superpixels(I,50);
lprops = regionprops(L,I(:,:,1),'MeanIntensity','PixelValues','PixelList');
L1 region MeanIntensity=65.0496
Lend region MeanIntensity=38.0527
original image=291*400
L=Labelled image=291*400; 50 superpixels;pixelindexlist 1*45;S value 45*1 PixelList values.
Q1.How to merge S1 and S2 if they are similar?
Q2. How to get best weighted threshold for an LAB image? for example R*0.299+G*0.587+B*0.114 where green is dominant color ..
Thank you so much for your answers

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!