0

I need to know the location of black portions such as in the following image enter image description here.

So far I am able to get the coordinates for the biggest contour in the image, which is the image without the black part, by help of the code given here.

For example, coordinates for the first image (1598 x 1288):

(Please note **cv2.approxPolyDP()** outputted the coordinates as (y,x), opposite to convention)

[column# row#]

[[[ 1 358]]

[[ 1 1288]]

[[ 1598 1288]]

[[1598 1]]

[[677 1]]

[[677 358]]

In this case I can find coordinates for black patch as follows:

1)Since patch is located top left (assuming we know this), so there must be 2 pair of coordinates like [min.col.# , row#]. Here, [1 358] and [1 1288]. Take the minimum row# (here 358) from this. This will be the maximum row# for the black patch. (assuming top left is [1 1] not [0 0])

2) Search for a coordinate like [some_col.# 358] (row # extracted from above step). Here, we get [677 358]. So 677 is the maximum column# for the black patch.

3) So points for black patch become [1 1], [1 358], [677 358], [677 1]

This is of course a very clumsy way of determining the coordinates, and also requires knowledge about location (top left, top right, bottom right, bottom left) of the patch.

After determining the contour, it should be fairly easy to know the coordinates of black patch.

What can you suggest?

Any other way of finding black patch in an image, besides finding contours and bounding rectangle, as suggested in the link?

Community
  • 1
  • 1
Nancy
  • 215
  • 1
  • 4
  • 14
  • what about `regionprops`? – Ander Biguri Dec 14 '15 at 15:13
  • @AnderBiguri I tried `regionprops` as explained here http://goo.gl/BSR22N. But could not gain anything. It gives me coordinates of say `256` regions for this image, but how am I to know which of these `0-255` regions is my black portion? – Nancy Dec 15 '15 at 09:50

0 Answers0