soroush
soroush

Reputation: 1

find rectangle coordinates in a given image

I'm trying to blindly detect signals in a spectra. one way that came to my mind is to detect rectangles in the waterfall (a 2D matrix that can be interpret as an image) . Is there any fast way (in the order of 0.1 second) to find center and width of all of the horizontal rectangles in an image? (heights of rectangles are not considered for me). an example image will be uploaded (Note I know that all rectangles are horizontal.

I would appreciate it if you give me any other suggestion for this purpose.

enter image description here

e.g. I want the algorithm to give me 9 center and 9 coordinates for the above image.

Upvotes: 0

Views: 145

Answers (1)

Jérôme Richard
Jérôme Richard

Reputation: 50816

Since the rectangle are aligned, you can do that quite easily and efficiently (this is not the case with unaligned rectangles since they are not clearly separated). The idea is first to compute the average color of each line and for each column. You should get something like that:

enter image description here enter image description here

Then, you can subtract the background color (blue), compute the luminance and then compute a threshold. You can remove some artefact using a median/blur before.

Then, you can just scan the resulting 1D array filled with binary values so to locate where each rectangle start/stop. The center of each rectangle is ((x_start+x_end)/2, (y_start+y_end)/2).

Upvotes: 1

Related Questions