9
$\begingroup$

How would one segment large area's of gray (ranging from white to black) from an image ? (If you know this in opencv, you may answer by saying what you would do in opencv). For example given this picture:

enter image description here

You see that this is a large area of gray and it is clearly distinguishable from the rest. How can you segment this if this area can have any shade of gray and it has to work in real-time.

Thx in advance.

$\endgroup$
  • $\begingroup$ I see several gray areas clearly distinguishable. Could you show your desired result? $\endgroup$ – Dr. belisarius Dec 8 '11 at 13:26
  • $\begingroup$ my desired result is the coordinates of the top right & left corners and the coordinate of the left bottom corner of the middle gray rectangle $\endgroup$ – Olivier_s_j Dec 8 '11 at 14:11
  • $\begingroup$ Can you tell us anything else about the environment and the potential variance in the images you will need to process? Will the target always be near the middle of the image? Will there be other gray rectangles present, possibly of the same size? What if they show up as the same shade of gray? Are there any other things we could use to identify it? Will it always have the small "T" shape at the top? $\endgroup$ – justis Dec 13 '11 at 7:45
  • $\begingroup$ Hi, The target wont always be near the middle of the image. The target will always be some kind of rectangle. (It can also be just a wall). If there are multiple rectangles they should also be detected, but they should be large. Small areas can be discarded. If they all show up as the same kind of gray, they should all be detected, but the chance that this happens is very small. The only real property that can be detected is that a surface will have the same gray (more or less) over the entire surface, and that it is a rectangle. There wont be a small T shape top every time $\endgroup$ – Olivier_s_j Dec 13 '11 at 7:53
9
$\begingroup$

You will get a reasonable segmentation of the grey area using the Watershed Algorithm or graph cuts. Watershed is available in opencv but graph cuts are not yet. (BTW Is this a depth map from Kinect ?)

$\endgroup$
  • 1
    $\begingroup$ The watershed function in opencv required a 8-bit 3channel image as input. My depth map is a 8-bit 1 image. Any idea how to solve this? $\endgroup$ – Olivier_s_j Dec 6 '11 at 18:07
  • $\begingroup$ /* get image properties / width = src->width; height = src->height; / create new image for the grayscale version */ IplImage *dst = cvCreateImage( cvSize( width, height ), IPL_DEPTH_8U, 1 ); cvCvtColor( src, dst, CV_RGB2GRAY ); $\endgroup$ – nav Dec 7 '11 at 13:25
  • $\begingroup$ Another question, i just got the watershed function working in another image (just an example from opencv). But they start of with a color image and a binary image. I only have 1 image ... the grascale image. Any idea of what the mask should be (the second input variable) ? $\endgroup$ – Olivier_s_j Dec 7 '11 at 17:06
4
$\begingroup$

In Mathematica you could do something like:

Colorize[MorphologicalComponents[
  ColorNegate@
   Erosion[Dilation[
     DeleteSmallComponents[
      Erosion[Binarize[
        GradientFilter[
         ColorConvert[Import@"http://i.stack.imgur.com/XdnaW.png", 
          "RGB"], 2], .015], 1], 100], 2], 2]], 
 ColorFunction -> "ThermometerColors"]

enter image description here

Probably you can translate this code to any image processing lib.

$\endgroup$
  • $\begingroup$ Hi, looks nice. But i don't have mathematica. But i'm guessing you used thresholding based on the grayscale of this picture ? Maybe you could give a little bit of info with your code ? Thx $\endgroup$ – Olivier_s_j Dec 10 '11 at 12:56
  • 1
    $\begingroup$ @Ojt For each command you can read "reference.wolfram.com/mathematica/ref/xxx.html" for a description. For example reference.wolfram.com/mathematica/ref/… $\endgroup$ – Dr. belisarius Dec 10 '11 at 15:30
  • $\begingroup$ Ok i did as you suggested. But it seems you are using Binarize to threshold at a given value. Which is not possible in my case. Since large areas of can have different shades of gray. (For example the middle surface could be very lightgray). And then the threshold would not work. $\endgroup$ – Olivier_s_j Dec 10 '11 at 16:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.