I am working on a Computer Vision problem, in which I have to merge regions of an image. A region (or blob) is defined by its lines, i.e. the following region of O:
0123456789
0 XXXXOXXXXX
1 XXXOOOXXXX
2 XXXOOXXXXX
3 XXXOXXXXXX
4 XXXXXXXXXX
is defined by :
row: 0, cols: 4-4
row: 1, cols: 3-5
row: 2, cols: 3-4
row: 3, cols: 3-3
I chose this datastructure because I need to be able to find quickly the neighbors of a region, i.e. all the pixels that “touch” it.
Now, my problem is that I want to merge two regions, i.e. compute the union of them. This means that I may end up with several ranges of columns in my data structure shown above.
With this setup, I have two questions:
-
In
C, what is the best datastructure for this data ? A typical image is 16×16, which means not that many rows/columns. I will do a lot of merging (the goal of the thing is to start with one region per pixel and end with one big region, i.e. 16×16 – 1 merges). I could go with a pointer and allocate/free the things, or use a char* to store the cols and parse it afterwards, for instance. -
How to efficiently merge two regions? I need to find potential columns that are adjacent to merge them (e.g.,
3-5and6-9become3-9), preferably without always reallocating and copying things.
If your data is for a two color image…black and white, why not just use an array of unsigned shorts that is 16 elements long?
The merging could be done with bitwise logic which is pretty efficient over a 16 element array.