0

We have a scanned white page - A4 size that contains multiple thumbnails. The thumbnails are similar but not exactly the same. The thumbnails can be in random order and not in a very clear rows and columns. They are not totally random but they are in rows, however these are not a very accurate rows.

  1. A4 page background color is white.
  2. All thumbnails have black border of 5px and border-radius of 10 px Everyone of the thumbnails contains a green circle (Could be in the center or somewhere close to that).

    1. How can we detect the Hard Edges of every thumbnail and store the coordinates so we can crop the thumbnails for later processing and analyzing colors?

    2. How can we detect the circle in the center. We want to analyze and get all pixels RGB values contained into this circle and then calculate average RGB value.


Update

This is the image:

enter image description here

Thank you

Kinght 金
  • 14,440
  • 4
  • 49
  • 62
  • 1
    Post your image – Kinght 金 Jan 16 '18 at 01:51
  • And some links maybe useful: https://stackoverflow.com/questions/48244328/copy-shape-to-blank-canvas-opencv-python/48246500#48246500 https://stackoverflow.com/questions/48259724/cv2-drawcontours-unfill-circles-inside-characters-python-opencv/48263593#48263593 https://stackoverflow.com/questions/47342025/how-to-detect-colored-patches-in-an-image-using-opencv/47343587#47343587 https://stackoverflow.com/questions/47899132/edge-detection-on-colored-background-using-opencv/47899313#47899313 – Kinght 金 Jan 16 '18 at 01:53
  • Thank you. I am uploading an image to the post. @Silencer –  Jan 16 '18 at 23:54
  • It sounds like a class homework, doesn't it? – Bartłomiej Jan 17 '18 at 00:03
  • The image is regular, so it's not hard to process. The links I posted may not that helpful for this image. – Kinght 金 Jan 17 '18 at 06:10

1 Answers1

2

Main idea: As there are enough blank between the regions, so just crop each region by contours. Then for each region, use houghCircle to detect the circle in it.


Your image is this:

enter image description here

After find external contours and calculate the bounding boxes:

enter image description here

For each contour, crop and find hough circle in it.

enter image description here


Notice: I'll not provide my code for this question.

But post some links maybe useful for you. Learn and do by yourself:

  1. Copy shape to blank canvas (OpenCV, Python)
  2. cv2.drawContours() - unfill circles inside characters (Python, OpenCV)
  3. How to detect colored patches in an image using OpenCV?
  4. Edge detection on colored background using OpenCV
  5. How can I get the minimum enclosing circle with OPENCV?
  6. How can I prepare circle path text image for OCR program?

Update:

To detect the circle, you should select the right parameters, depends on your source image.

enter image description here

Try! Try! TRY!

Here is the circle detection I tried:

circles = cv2.HoughCircles(gray, cv2.HOUGH_GRADIENT,
                    dp=1, minDist=20, circles=None,
                    param1=200 , param2=50,
                    minRadius=120, maxRadius=150
                )
Kinght 金
  • 14,440
  • 4
  • 49
  • 62
  • I have succeeded to detect external boundaries , and crop them and save them into new folder. Now I need to work on the circles. I want to loop over all of the coped rectangles and detect the circle in everyone of them, and then crop the circles. I want finally to be able to take everyone of the circles and analyze the colors in as many pixles as I can within every circle so I can find the average color value in every circle. Any help? :-) –  Jan 18 '18 at 18:09
  • As the colors of pixels in each circle are almost the same, you don't need to find exact circle. Use hough circle detection (such as in the link 6) to detect circle in each rectangle, the result maybe just like what I posted in this answer. As you can see, the detected circle is not really the same as origin, because of it's black border. Then decrease the radius, make sure the detected circle is in the original circle. Then crop the circle and analysis. – Kinght 金 Jan 19 '18 at 01:51
  • I am lready following the code in link 6. However, I guess there is a problem in circles = np.int0(np.array(circles)) where you are trying to Get the mean of centers and do offset. circles = np.int0(np.array(circles)) TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType' –  Jan 19 '18 at 12:13
  • Seems that circles is always equals to None... and that is why I am getting the previous error in previous comment. However I am not sure why I am getting Circles=None. What I am trying to do here and in order to check the circle detection. I am working on only one cropped rectangle thumbnail which contains one circle. –  Jan 19 '18 at 13:11
  • I just give you a link to show `there is a way to detect circle`. The parameters I used were adjusted for that project. Of course, it was taken the mean of all circles detected. In that situation, it was right. I your image, you should try to adjust your parameter. Such as, taking means is not needed. And the result I posted was ok(Because I set the right parameters) – Kinght 金 Jan 19 '18 at 13:22
  • Thank you. After playing with parameters, and changing some more values regarding circle center and radios. I have succeed to crop the circle exactly as I want. :-) Thank you a lot Now. every image is a rectangle. and in order to show only the circle, I want to build a mask so. Green circle and the image background should be as the circle border color. Assuming the border is black so it should look like as in the following image: https://imgur.com/a/4xvsu How can we achieve bit-masking for that ? see snippet of the code here: https://imgur.com/a/lCDuQ –  Jan 19 '18 at 19:47
  • It's another question. – Kinght 金 Jan 20 '18 at 00:07
  • ok... I will add a new question and let you know.. Thanx alot –  Jan 20 '18 at 12:09
  • https://stackoverflow.com/questions/48356398/opencv-remove-background-of-an-image –  Jan 20 '18 at 12:57
  • @Mark Done! https://stackoverflow.com/questions/48356398/opencv-remove-background-of-an-image/48356640#48356640 – Kinght 金 Jan 20 '18 at 13:25
  • One of the strange things is that when I crop the image in this question which contains 3 rows and 4 columns, this should generate 12 rectangles. How come I am getting 14? :-) –  Jan 20 '18 at 23:52
  • You can save/display the regions to see where is wrong. Mostly because your regions are overlapped. – Kinght 金 Jan 21 '18 at 00:47
  • ok. Thank you I will create a new question and explain everything. and give the real image I have and what I have succeeded to do with your help. –  Jan 22 '18 at 14:40