Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm and data structure to find and store superpixels' neighborhood in C++

I have an image, holding results of segmentation, like this one.enter image description here

I need to build a graph of neighborhood of patches, colored in different colors. As a result I'd like a structure, representing the following enter image description here

Here numbers represent separate patches, and lines represent patches' neighborhood. Currently I cannot figure out where to start, which keywords to google.

Could anyone suggest anything useful?

Image is stored in OpenCV's cv::Mat class, as for graph, I plan to use Boost.Graph library.

So, please, give me some links to code samples and algorithms, or keywords.

Thanks.

Update. After a coffee-break and some discussions, the following has come to my mind.

  1. Build a large lattice graph, where each node corresponds to each image pixel, and links connect 8 or 4 neighbors.
  2. Label each graph node with a corresponding pixel value.
  3. Try to merge somehow nodes with the same label.

My another problem is that I'm not familiar with the BGL (but the book is on the way :)).

So, what do you think about this solution?

Update2 Probably, this link can help.

However, the solution is still not found.

like image 401
wl2776 Avatar asked Dec 18 '12 11:12

wl2776


2 Answers

You could solve it like that:

  1. Define regions (your numbers in the graph)

    • make a 2D array which stores the region number
    • start at (0/0) and set it to 1 (region number)
    • set the whole region as 1 using floodfill algorithm or something.
    • during floodfill you probably encounter coordinates which have different color. store those inside a queue. start filling from those coordinates and increment region number if your previous fill is done.

    .

  2. Make links between regions

    • iterate through your 2D array.
    • if you have neighbouring numbers, store the number pair (probably in a sorted manner, you also have to check whether the pair already exists or not). You only have to check the element below, right and the one diagonal to the right, if you advance from left to right.

Though I have to admit I don't know a thing about this topic.. just my simple idea..

like image 85
duedl0r Avatar answered Sep 21 '22 19:09

duedl0r


You could use BFS to mark regions.

To expose cv::Mat to BGL you should write a lot of code. I think writeing your own bfs is much more simplier.

Than you for every two negbours write their marks to std::set<std::pair<mark_t, mark_t>>. And than build graph from that.

like image 27
kassak Avatar answered Sep 18 '22 19:09

kassak