# Surface detection

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:

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.

• I see several gray areas clearly distinguishable. Could you show your desired result? Dec 8, 2011 at 13:26
• 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 Dec 8, 2011 at 14:11
• 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? Dec 13, 2011 at 7:45
• 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 Dec 13, 2011 at 7:53

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 ?)

• 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? Dec 6, 2011 at 18:07
• /* 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 );
– nav
Dec 7, 2011 at 13:25
• 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) ? Dec 7, 2011 at 17:06

In Mathematica you could do something like:

Colorize[MorphologicalComponents[
ColorNegate@
Erosion[Dilation[
DeleteSmallComponents[
Erosion[Binarize[