views:

269

answers:

2

Hi,

I uploaded an example image for better understanding: http://www.imagebanana.com/view/kaja46ko/test.jpg

In the image you can see some scanlines and a marker (the white retangle with the circle in it). I want opencv to go along a specified area (in the example outlined trough the scanlines) that should be around 5x5. If that area contains a gradient from black to white, I want opencv to save the position of that area, so that I can work with it later.

The final result would be to differentiate between the marker and the other retangles separated trough black and white lines.

Is something like that possible? I googled a lot but I only found edge detectors but that's not what I want, I really need the detection of the black to white gradient only.

Thanks in advance.

+1  A: 

it would be a good idea to filter out some of the areas by calculating their histogram. You can use cvCalcHist for the task, then you can establish some threshold to determine if the black-white pixels percentage corresponds to that of a gradient. This will not solve the task but it will help you in reducing complexity.

Then, you can erode the image to merge all the white areas. After applying threshold, it would be possible to find connected components (using cvFindContours) that will separate images in black zones or white zones. You can then detect gradients by finding 5x5 areas that contain both a piece of a white zone and black zone simultaneously.

hope it helps.

dnul
A: 

Thanks for your answerer dnul, but it didn't really help me work this out. I though about a histogram to approach the problem but it's not quite what I want.

I solved this problem by creating a 40x40 matrix which holds 5x5 matrix's containing the raw pixel data in all 3 channels. I iterated trough each 40px-area and inside iterated trough each border of 5px-area. I checked each pixel and saved the ones which are darker then a certain threshold a storage.

After the iteration I had a rough idea of how many black pixels their are, so I checked each one of them for neighbors with white-pixels in all 3 channels. I then marked each of those pixels and saved them to another storage.

I then used the ransac algorithm to construct lines out of these points. It constructs about 5-20 lines per marker edge. I then looked at the lines which meet each other and saved the position of those that meet in a square angle. The 4 points I get from that are the edges of the marker.

If you want to reproduce this you would have to filter the image in beforehand and apply a threshold to make it easier to distinguish between black and white pixels.

A sample picture, save after finding the points and before constructing the lines: http://www.imagebanana.com/view/i6gfe6qi/9.jpg

Robin