1
$\begingroup$

I am working on a project where I have two grayscale images of different sizes, named part1 and part2. Each image has some pixels that are interpolated or superposed from the other image. My goal is to combine these two images into a single one without any overlapping. The resulting image should look good and real, meaning that it should only contain the pixels that are the same or almost the same in both images.

Here is my desired output, (orginal image), and the two parts that are overlapped: enter image description here

Here is the code I have so far:

import cv2
import numpy as np
import matplotlib.pyplot as plt

original_image = cv2.imread('umbrella.tif', cv2.IMREAD_GRAYSCALE)
part1 = original_image[:, 79:]
part2 = original_image[:, :171]

# Resizing to make it same size
part1 = cv2.resize(part1, (part2.shape[1], part2.shape[0]))

# Perform average pixel composition
average_image = (part1 + part2) / 2


plt.figure(figsize=(12, 4))
plt.subplot(1, 4, 1)
plt.imshow(original_image, cmap='gray') #original image
plt.title('Original Image')

plt.subplot(1, 4, 2)
plt.imshow(part1, cmap='gray') #part1 image
plt.title('Part 1')

plt.subplot(1, 4, 3)
plt.imshow(part2, cmap='gray') #part2 image
plt.title('Part 2')
plt.tight_layout()

plt.show()

The problem with this code is that it simply averages the pixel values of the two images, which results in a blurry image if the images are not perfectly aligned. I want to create a new image that only contains the pixels that are the same or almost the same in both images.

How can I achieve this using OpenCV functions in Python and display the result using Matplotlib? Any help would be greatly appreciated.

Here it is the original image if you want to try it: enter image description here

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.