0

I have the following original image:

enter image description here

and the cropped image:

enter image description here

I will like to obtain the left (a), right (c), upper (b) and lower shifts (d) from the original image to obtain the crop:

enter image description here

As of now, I can only think of matching the pixel array values (row and column-wise) and then subtracting the the overlapping pixel arrays coordinates from the original image's coordinates to get the shifts. However this approach seems computationally expensive and a search on 4 sides will have to be undertaken. Also if it helps, I do not have the transformations that led to the cropped image, and I'm assuming that there are no pixel value changes between the original and cropped image on regions of overlap.

Is there a more efficient approach for this? I'm not sure if there are existing built-in functions in OpenCV or other imaging libraries that can do this, so some insights on this will be deeply appreciated.

Stoner
  • 846
  • 1
  • 10
  • 30
  • See https://docs.opencv.org/2.4/modules/imgproc/doc/object_detection.html?highlight=matchtemplate#cv2.matchTemplate for starters. – Selcuk Aug 26 '20 at 03:09
  • @Selcuk Thanks for the suggestion. I just tried `cv.matchTemplate` in the link alongside an implementation here https://stackoverflow.com/questions/9709631/how-do-i-use-opencv-matchtemplate by JHolta and got `x, y` as a result. Am I right to interpret this `x, y` output as the top-left corner's coordinate of the cropped image? – Stoner Aug 26 '20 at 03:29
  • I have no idea, and that user seems to be inactive but maybe give it try? – Selcuk Aug 26 '20 at 03:41

0 Answers0