I am stuck with my assesment. I am given a bitmap with its dimensions (rows and cols) such as this:
4 5
0 0 1 1 1
0 0 1 0 1
1 0 1 1 1
1 1 1 1 1
The task is to find horizontal and vertical longest line and a square (all made of 1). I just need the first kick with the horizontal line.
I have put the bitmap in 1D array and I don't know the next step.
The output of the picture above are the coordinates of the longest horizontal line:
3 0 3 4
Help is very much appreciated.
You have to extract the header into structure and data into an array like a[].
Let R and C be number of rows and columns of image. For a given array a[], each row of image starts at a[C*i] where i is the row number. So you can index the row with i, and access each bit in that row with C*i+j, were j less than C. Next you need to do
processing
for each row to find the length of longest horizontal line. Small change to this can be used to index column j and find longest vertical line.To do the processing I said above, create a structure of point as
Also create a variable called
lenh
which will contain length of the horizontal line found. Also user variablellenh
to store the longest length. For each vertex in row (i, j) indexed by (5i+j). Setllenh
to 0. Starting in row, on seeing 1 updatelenh
, and see if it is greater thanllenh
. If yes updatep1
point. On seeing 0 updatep2
point and setlenh
to 0 and also updatellenh
.I haven't revised this completely. If any errors please comment..