Hi!
For example I have something like this
http://yfrog.com/73objectj
White background and rectangle object on it and it is black.
The question is how to detect this rectangle object on image and
get his dimensios?
Any link or idea how to start!?
Thanks.
This is a segmentation problem -- plenty of approaches will work. The
simplest is what I've called Method 1 (below), but if your real images
are more complicated than the one you've shown, you might want to look
into more sophisticated methods. A few suitable search terms are:
- Thresholding segmentation
- Region growing
- Watershed segmentation
- Snakes segmentation
- Level sets segmentation
- K-means clustering
- Normalized cuts
- etc.
Hope that helps a bit,
Stu
p.s. Method 2 is *not* a sensible approach. FWIW.
###
Method 1 -- the appropriate way for a simple image like this
###
Walk the image in scanline order from the top-left until you find a
black pixel -- this is the top-left of the rectangle. Do the same in
reverse scanline order from the bottom-right -- this is the bottom-right
of the rectangle. From that point on, it's easy to calculate anything
else you want (like the dimensions).
###
Method 2 -- an extremely silly way for fun
![Smile :) :)](/styles/default/custom/smilies/smile.gif)
###
- Construct a set S containing every pixel in the image.
- Until you find a black pixel or S is empty:
- Pick a random pixel from S.
- Remove it from S.
Assuming there was at least one black pixel in the image, you now have a
seed! (Otherwise, fail.)
- Run a region growing algorithm, starting from your seed. The grow
condition should just say "the adjacent pixel must be black".
- Fit an axis-aligned bounding box to the region you just grew (easy --
just iterate over all the pixels in the region and calculate the
{min|max} {x|y})