0

I implemented SLIC algorithm to find labels and I obtained the labels. I would like to compute a color feature vector that contains the average of the color features for each region. For each pair of neighboring regions, if the Euclidean distance between their feature vectors is less than a threshold, I will merge the two regions. I will do this for all pairs of neighboring regions. Then, I will repeat steps until no pair of regions can be merged. However, I don't know how to implement those steps.

michael scolfield
  • 411
  • 1
  • 5
  • 20
  • what is a neighbor? for pixels there are typically two neighborhoods. a 4 pixel (up, down, left right) or the 8 pixel (up, down, left, right, and all diagonals)? The same goes for regions. even if your region is a 3x3 pixel area, how do you define what its neighboring regions are? I don't think you can truly "merge" the regions. The best you could do is duplicate one region to both places (or possibly do an average between the two) – andrew Apr 30 '15 at 16:48
  • I am impliying 8 pixel by saying neighborhood. Could you guide me on how to compute color feature vector? – michael scolfield Apr 30 '15 at 17:22
  • I noticed you posted alot of questions about SLIC, have you seen this webpage http://www.peterkovesi.com/projects/segmentation/ it shows SLIC implemented in matlab with all code. it was literally the first google result for "SLIC algorithm matlab" im sure this will help you – andrew Apr 30 '15 at 18:20

1 Answers1

0

there are a few choices for your color features, and they really depend on your colorspace, and what information you are looking for.

  1. If your objective is to find objects that are the same color (invariant to lighting) I would strongly suggest the hsv colorspace you convert your regular rgb image using rgb2hsv the HSV colorspace has three channels (just like RGB) which are channel 1 = H = Hue = the color, channel 2 = S = Saturation = how vivid the color is, channel 3 = V = brightness Value = how bright a color is. all values are between 0 and 1. again if you wanted to find colors invariant of lighting, your feature would simply be the Hue channel. One thing to not about the hue channel is it is actually cyclic so 0 and 1 are actually the same (red). so your distance would have to wrap around. for instance pixel A has h=.7 pixel B has H=.3 pixel C has H=.01. which is closer to pixel A? you would immediately guess pixel B since delta_H=.4 but actually delta_H for a and c is only 0.31

  2. If you are interested in more than just the simplistic color model by hue other choices are YCbCr, YUV (most people just use YCbCr since there is no TRUE YUV in matlab), CIE (also not completely native to matlab but it is supported as in this example). each of these represent the image brightness in the first channel. and the colors are represented by the last 2 channels. Using the last two channels, you could easily plot colors on a 2d cartesian plane, with one axis being channel2 and the other being channel 3 something like this (this example is specifically YCbCr colorspace) enter image description here

    and the similarity measure could be the euclidean distance between two colors

Im guessing your overall goal is some kind of compression. So what I would do is simply replace pixel values. So if pixel A and B are similar, then make the value of pixel B = pixel A. This means that every iteration you are reducing the total number of different colors in the image. Whereas with averages, you are still maintaining lots of different colors. think of it this way

replace 1. iteration 1, pixel A=x B=x+delta, and they are close enough so you say A=B=x 2. iteration 2, pixel B=x, C=x-delta, they are close so you say B=C=x 3. at this point you have A=B=C=x so there is a reduction in the number of colors from 3 to 1

average 1. iteration 1, pixel A=x B=x+delta, they are close so now A=B=x+.5delta 2. iteration 2, pixel B=x+.5delta, C=x-delta, they are so now B 3. at this point you have A=B=C=x so there is a reduction in the number of colors from 3 to 1

andrew
  • 2,451
  • 1
  • 15
  • 22
  • Thanks. I can compute the color feature vector of an image. However, I would like to implement the same operation for local image regions by using superpixels which are the output of SLIC algorithm as labels. How can I handle it? @andrew – michael scolfield May 02 '15 at 14:02
  • you can try averaging all the pixels in the region. Or you can combine them using a weighted mask, like a gaussian distribution centered about the pixel of interest – andrew May 03 '15 at 03:18