'Possible solutions to process two images into one [closed]

Hi Im new to computing vision and I am currently stuck at this problem. I have 2shots of component(One is classing RGB and other is IR) and I would like them to overlap with small opacity. Problem is shots are in different dimensions and on slightly different zoom/angle so simlpe resize of smaller one wont put component on correct place. I was able to achieve it using programs like Inkscape but would like to have it automatic since there are more pictures and sets might be from different angle as well. Here are pictures and something I would like to achieve: RGB shot, IR shot and final merged. I would appreciate and possible solutions for this problem, since Im new its hard for me to choose path to take and Im not sure if there is anything programs can do with bad quallity of IR shots. Thanks for possible help.



Solution 1:[1]

As as Jeru Luke says

you will have to figure out the placement of overlapping images due to different size

#!/usr/bin/env python3.9.2
#OpenCV 4.5.5, Raspberry pi3B/+, 4b/4g/8g 
#Date: 26th April, 2022

import cv2
import numpy as np

img1 = cv2.imread('shot.png')
overlay_img1 = np.ones(img1.shape,np.uint8)*255

img2 = cv2.imread('shot1.png')
rows,cols,channels = img2.shape
overlay_img1[450:rows+450, 450:cols+450 ] = img2

img2gray = cv2.cvtColor(overlay_img1,cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray,220,55,cv2.THRESH_BINARY_INV)
mask_inv = cv2.bitwise_not(mask)
temp1 = cv2.bitwise_and(img1,img1,mask = mask_inv)
temp2 = cv2.bitwise_and(overlay_img1,overlay_img1, mask = mask)

result = cv2.add(temp1,temp2)
cv2.imshow("Result",result)
cv2.imwrite("Result.jpg",result)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output: What you see in shot1 overlay is getting smaller. enter image description here

Solution 2:[2]

Edit: I do not understanding your question. Ok. I cannot go any further resolution, because you took picture from smartphone. So no overlay. So here is source code:

#!/usr/bin/env python3.9.2
#OpenCV 4.5.5, Raspberry pi3B/+, 4b/4g/8g 
#Date: 29th April, 2022


import cv2
import numpy as np

img1 = cv2.imread('RGB_shot.png')
img2 = cv2.imread('IR_shot.png')

# I want to put logo on top-left corner, So I create a ROI
rows,cols,channels = img2.shape

roi = img1[0:rows, 0:cols]

# Now create a mask of logo and create its inverse mask also
img2gray = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 10, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)

# Now black-out the area of logo in ROI
img1_bg = cv2.bitwise_and(roi, roi, mask=mask_inv)

# Take only region of logo from logo image.
img2_fg = cv2.bitwise_and(img2, img2, mask=mask)

# Put logo in ROI and modify the main image
dst = cv2.add(img1_bg, img2_fg)
img1[15:rows+15, 15:cols+15] = dst
cv2.imwrite('photo.png', img1)
cv2.imshow('res', img1)
cv2.waitKey(0)
cv2.destroyAllWindows()

Output for wider IR_shot: enter image description here

And here is output result: enter image description here

Is that the way you wanted?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 toyota Supra
Solution 2