Question

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.

Was it helpful?

Solution

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

struct point 
{
  int x;
  int y;

}p1, p2;

Also create a variable called lenh which will contain length of the horizontal line found. Also user variable llenh to store the longest length. For each vertex in row (i, j) indexed by (5i+j). Set llenh to 0. Starting in row, on seeing 1 update lenh, and see if it is greater than llenh. If yes update p1 point. On seeing 0 update p2 point and set lenh to 0 and also update llenh.

I haven't revised this completely. If any errors please comment..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top