Skip to content
Advertisement

Identify an embedded image within an image in Python [closed]

I have, for example, the following image:

Is there any way of identifying the embedded image between the text?

I know you can use OpenCV’s match_by_template but that is if you already know what the embedded image is. I have spent a lot of time searching how to identify an image within an image in Python when not already knowing what the embedded image is, but I have not been able to find anything. Please let me know what I can do.

Advertisement

Answer

Here’s my attempt. This is how it works:

  1. To detect text, check how different pixels are from their neighbors. This is done using an absolute difference.
  2. The previous step only detects the edges of text. Expand this with a gaussian blur.
  3. Threshold this, and remove text.
  4. Crop remaining whitespace.

It uses numpy, opencv, and scipy to do it.

Full code:

JavaScript

Output:

found image

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement