# islands

Hi everybody

I am working on image processing, and right know I have the next problem. From the original image I have got an array of 1's and 0's (by the way, in part thanks to the help of this list). Lets say I have something like this

000000000000000000000000000
000000000000000100000000000
000000000001111111000000000
000000011111111111100000000
000001111111100000000000000
000000001100000000000000000
000000000000000000111100000
000000000000001111111000000
000000000000000001110000000
000000000000000000100000000
000000000000000000000000000

Well, here we have have what I call two islands of 1's in a sea of 0's. Now, the question is, how to delimitate the extrem values of the islands? i.e., how to get the indexes of the 1's which are more to the left, right, up and down in each island?
I have thought about this: I search for a 1, and when I find it, I search for its neighbors (two 1's are neigbors if you can go from one to the other by passing only across 1's), and as I find its neighbors I stores the extrem values of the indexes. Well, I guess this can be a way. But actually I don't know how to define a function that tells me either two 1's are neighbors or not. Any idea about how to do it?

Emilio

• : Hi everybody

:
: I am working on image processing, and right know I have the next problem. From the original image I have got an array of 1's and 0's (by the way, in part thanks to the help of this list). Lets say I have something like this
:
: 000000000000000000000000000
: 000000000000000100000000000
: 000000000001111111000000000
: 000000011111111111100000000
: 000001111111100000000000000
: 000000001100000000000000000
: 000000000000000000111100000
: 000000000000001111111000000
: 000000000000000001110000000
: 000000000000000000100000000
: 000000000000000000000000000
:
: Well, here we have have what I call two islands of 1's in a sea of 0's. Now, the question is, how to delimitate the extrem values of the islands? i.e., how to get the indexes of the 1's which are more to the left, right, up and down in each island?
: I have thought about this: I search for a 1, and when I find it, I search for its neighbors (two 1's are neigbors if you can go from one to the other by passing only across 1's), and as I find its neighbors I stores the extrem values of the indexes. Well, I guess this can be a way. But actually I don't know how to define a function that tells me either two 1's are neighbors or not. Any idea about how to do it?
:
: Thanks in advance
:
: Emilio
:
Hi Emilio,
will provide you the solution tomorrow as iam preparing it. BTY, do you wish to solve this issue with the help of Linklist or array. Let me know. you can also mail me : sumit.shah at indoasian.com

______________________________________________________________________
A winner is not the one who never fails , but the one who never quits.
[blue]*** Sumit Shah ***[/blue] :-)

• [b][red]This message was edited by sumitxshah at 2005-6-8 22:5:57[/red][/b][hr]
: Hi everybody
:
: I am working on image processing, and right know I have the next problem. From the original image I have got an array of 1's and 0's (by the way, in part thanks to the help of this list). Lets say I have something like this
:
: 000000000000000000000000000
: 000000000000000100000000000
: 000000000001111111000000000
: 000000011111111111100000000
: 000001111111100000000000000
: 000000001100000000000000000
: 000000000000000000111100000
: 000000000000001111111000000
: 000000000000000001110000000
: 000000000000000000100000000
: 000000000000000000000000000
:
: Well, here we have have what I call two islands of 1's in a sea of 0's. Now, the question is, how to delimitate the extrem values of the islands? i.e., how to get the indexes of the 1's which are more to the left, right, up and down in each island?
: I have thought about this: I search for a 1, and when I find it, I search for its neighbors (two 1's are neigbors if you can go from one to the other by passing only across 1's), and as I find its neighbors I stores the extrem values of the indexes. Well, I guess this can be a way. But actually I don't know how to define a function that tells me either two 1's are neighbors or not. Any idea about how to do it?
:
: Thanks in advance
:
: Emilio
^**^*^*^*^*^*^*^*^*^*^*^*^*^*
Hi! Emilio,
It's nice to see that image processing guys are also here. I am not ACTUALLY worked in image processing. Howerver, matrix is always an intresting topic to solve. I can only give you an idea how to resolve this issue. You have to give it a try.

There are 2way to resolve this issue. Either you use static variable i.e with the help of ARRAYS or you resolve it with the help of Linklist.
Iam providing you resolution by first method.

MY idea goes as follows:

You are using the matrix[R,C] of [10x26]
Compare each element's position with it's adjacent elements. i.e you have 8 comparision. For instance
123
4X6
789
if you are at X position with the coordinate X[R,C] then you have to compare one by one for 8 positions mentioned below with it's coordinate.
1 X[R-1],[C-1]
2 X[R-1],[C]
3 X[R-1],[C+1]

4 X[R],[C-1]
6 X[R],[C+1]

7 X[R+1],[C-1]
8 X[R+1],[C]
9 X[R+1],[C+1]

if "ANY" of these 8 comparision holds TRUE value then you are working on a same image
if "ALL" of these comparision holds FALSE value then the image you are working in is finished. and it's time for second island in the sea of 0's.
You will have to increase the sub-script variable of "myimage" array by one, if you finds any 1 in the matrix again.

Declare a structure arrays
typedef struct image
{
int top_row;
int top_col;
int bottom_row;
int bottom_col;
int left_row;
int left_col;
int right_row;
int right_col;
}IMAGE;
IMAGE myimage[n];

'n' will be the maximum no of island in a given pattern.
Initilize all the sub-script element's members of the structure with zero.
i.e you must be knowing the max value of the structure image and then the following
myimage[0].top_row=-1;
myimage[0].top_col=-1;

myimage[0].bottom_row=-1;
myimage[0].bottom_col=-1;

myimage[0].left_row=-1;
myimage[0].left_col=-1;

myimage[0].right_row=-1;
myimage[0].right_col=-1;
for n numbers of images.

Scan the matrix through [0,0]th element to [10,26]th element.
assuming that you are travesing the given matrix with the help of 2 nested for loops
for (i=0;itop_row) && (top_changed==FALSE))
{
myimage[n].top_row=i;
myimage[n].top_col=j;
top_changed==TRUE;
}

if((j>left_row) && (left_changed==FALSE))
{
myimage[n].left_col=j;
myimage[n].left_row=i;
left_changed==TRUE;
}

if(j>right_col)
{
myimage[n].right_col=j;
myimage[n].right_row=i;
}
if(i>bottom_row)
{
myimage[n].bottom_row=i;
myimage[n].bottom_col=j;
}
______________________________________________________________________
A winner is not the one who never fails , but the one who never quits.
[blue]*** Sumit Shah ***[/blue] :-)