pythonimageopencvimage-processing

Generic detection of subimages in images with openCV


Disclaimer: I'm a computer vision rookie.

I have seen a lot of stack overflow posts of how to find a specific sub-image in a larger image.

My usecase is a bit different since I don't want it to be specific and I'm not sure how I can do this (if it's even possible, but I have a feeling it should).

I have a large datasets of images, of sometimes, some of this images are a combination of two or more other images of the dataset. I'd like to automatically crop theses "combinations" to isolate the sub-images.

So the tasks would be to process each image of the dataset, and check if there are abnormal boundaries that could mean the image is a combination.

Example using great stock images:

combination of two images

What I've tried:

I've seen that houghs transform could be used for line detection in images but I'm couldn't achieve anything using this.


Solution

  • edge map:

    edge map

    edgy plot:

    edgy plot

    slices to take:

    array([[   0,  578],
           [ 578, 1135],
           [1135, 1136]], dtype=int64)
    

    Pictures:

    pic 1 pic 2

    complete notebook: https://gist.github.com/crackwitz/e1ba1ce7a6fba446288275d91f66261c