Ask Your Question
0

Extracting groups of adjacent non-white pixels

asked 2013-02-02 07:32:43 -0600

Kay Sarraute gravatar image

updated 2013-02-02 09:21:29 -0600

Given an image, I'd like to extract all groups of adjacent non-white [1] pixels by their rectangular bounding boxes:

Diagonally neighboring pixels ( ) may or may not count as adjacent.

Can you give me a few pointers?

[1] (R, G, B < 255, 255, 255)

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-02-02 08:57:18 -0600

unxnut gravatar image

This is a simple case of blob analysis. You can use one of the blob analysis libraries, for example, cvBlobsLib, and get the information you need. It will give you the coordinates as well as the size of the blobs.

edit flag offensive delete link more
1

answered 2013-02-02 10:33:43 -0600

You task may be solved in several steps. Firstly, convert image to gray scale and apply cv::threshold to it. You get binary image: white pixel (255) means that pixel value is in range, black (0) means that pixel value is not in range. Then apply cv::findContours function to binarised image. it returns contours for all objects. Using this contours you can calculate bounding box for all of them. Also there are cv::dilate and cv::erode function that implements dilatation and erosion for binarized imaged. It helps you to solve problems with diagonally neighboring pixels.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-02-02 07:32:43 -0600

Seen: 30,546 times

Last updated: Feb 02 '13