Question: I need some help developing some code that segments a binary image into components of a certain pixel density. I've been doing some research in OpenCV algorithms, but before developing my own algorithm to do this, I wanted to ask around to make sure it hasn't been made already.

For instance, in this picture, I have code that imports it as a binary image. However, is there a way to segment objects in the objects from the lines? I would need to segment nodes (corners) and objects (the circle in this case). However, the object does not necessarily have to be a shape. 

The solution I thought was to use pixel density. Most of the picture will made up of lines, and the objects have a greater pixel density than that of the line. Is there a way to segment it out?

Below is a working example of the task.

**Original Picture:**

![Original Picture](https://i.stack.imgur.com/E9ub2.jpg)

**Resulting Images after Segmentation of Nodes** (intersection of multiple lines) and Components (Electronic components like the Resistor or the Voltage Source in the picture)

![Node 1](https://i.stack.imgur.com/YUAfS.jpg)

![Voltage Source](https://i.stack.imgur.com/MKtPN.jpg)

![Node 2](https://i.stack.imgur.com/y0cSm.jpg)

![Resistor](https://i.stack.imgur.com/Ath0Y.jpg)

![Node 3](https://i.stack.imgur.com/x8BwR.jpg)

![Node 4](https://i.stack.imgur.com/NfJ18.jpg)

Answer: 
OpenCV has some [functionality for finding contours](http://docs.opencv.org/doc/tutorials/imgproc/shapedescriptors/find_contours/find_contours.html) that is able to put the contours in a hierarchy. It might be what you are looking for. If not, please add some more information about your expected output!
If I understand correctly, you want to detect the lines and the circle in your image, right?

If it is the case, have a look at the [Hough line transform](http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html) and [Hough circle transform](http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_circle/hough_circle.html).