0

I have a bunch of images like the following: https://resultados2019.registraduria.gov.co/assets/img/logo/1305.png

I would like to split the party logos of each image, in this case, two separate images.

I tried using the contours but there are many contours within each logo so I don´t know which could be a better alternative to separate the logos from this image. Sometimes there can be more than two logos as for example in this image: https://resultados2019.registraduria.gov.co/assets/img/logo/1566.png

web="https://resultados2019.registraduria.gov.co/assets/img/logo/1305.png"
urlretrieve(web, "nombre.jpg")

original_image = cv2.imread("nombre.jpg")
image = original_image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (3, 3), 0)
canny = cv2.Canny(blurred, 120, 255, 1)

# Find contours in the image
cnts = cv2.findContours(canny.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
user2246905
  • 1,029
  • 1
  • 12
  • 31
  • if all images look similar then you could split it in the middle without any calculations. And eventually remove white margin around logo - [How to remove whitespace from an image in OpenCV?](https://stackoverflow.com/questions/49907382/how-to-remove-whitespace-from-an-image-in-opencv) – furas Feb 20 '20 at 22:44
  • Sometimes there could be more than two logos as in this image https://resultados2019.registraduria.gov.co/assets/img/logo/1566.png so I would need something that identifies how many logos there are and split it. – user2246905 Feb 20 '20 at 22:50
  • Do you have higher quality resolution pictures? – nathancy Feb 20 '20 at 22:56
  • Sadly no. That's the highest resolution – user2246905 Feb 20 '20 at 23:07
  • Assuming that the background is always the same, namely white, you could segment the non-white parts, probably do some morphological operation to close holes and gaps, and segment it into separate objects. Then for each such detected object you could create a mask and a bounding rectangle and extract that part from the original image. – Andreas Feb 21 '20 at 15:03
  • Thank you. Do you know where I could find how to do that segmentation in the way you suggest? – user2246905 Feb 21 '20 at 21:28
  • 1
    The idea is to load image, grayscale, Otsu's threshold, connect logo into its individual contour using morph close or dilate, then find contours, iterate through contours, and extract ROI using Numpy slicing. – nathancy Feb 21 '20 at 21:59
  • Thank you, that worked perfectly. – user2246905 Feb 21 '20 at 23:03
  • I have found some problems when there are more logos into one image as in this case: https://resultados2019.registraduria.gov.co/assets/img/logo/1566.png. At the end, many logos are put together as only one. How could I fix that? – user2246905 Feb 24 '20 at 16:43

0 Answers0