문제 설명
두 개의 유사한 이미지에서 노이즈를 추출하는 방법은 무엇입니까? (How to extract noise from two similar images?)
두 개의 유사한(동일하지 않은) 이미지가 있습니다. 하나는 노이즈가 있고 다른 하나는 노이즈가 없는 원본입니다. 두 이미지의 차이로 노이즈를 추출하고 원본 이미지에 추출한 노이즈를 추가하여 두 이미지가 동일하게 만들고 싶습니다. 원본 이미지는 디지털 카메라로 캡처됩니다. 웹캠을 사용하여 모니터(원본 이미지 표시)에서 노이즈가 있는 이미지를 캡처합니다.
참조 솔루션
방법 1:
In order to find the differences between two images, you can utilize the Structural Similarity Index (SSIM) which was introduced in Image Quality Assessment: From Error Visibility to Structural Similarity. This method is already implemented in the scikit‑image library for image processing. You can install scikit‑image
with pip install scikit‑image
.
Using the compare_ssim()
function from scikit‑image, it returns a score
and a difference image, diff
. The score
represents the structual similarity index between the two input images and can fall between the range [‑1,1] with values closer to one representing higher similarity. But since you're only interested in where the two images differ, the diff
image what you're looking for. The diff
image contains the actual image differences between the two images.
Here are the actual differences between the two images. Consider using .png
images since they are lossless. .jpg
images are lossy and have noise due to image compression.
Code
from skimage.measure import compare_ssim
import cv2
# Load images
image1 = cv2.imread('1.jpg')
image2 = cv2.imread('2.jpg')
# Convert images to grayscale
image1_gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
image2_gray = cv2.cvtColor(image2, cv2.COLOR_BGR2GRAY)
# Compute SSIM between two images
(score, diff) = compare_ssim(image1_gray, image2_gray, full=True)
# The diff image contains the actual image differences between the two images
# and is represented as a floating point data type in the range [0,1]
# so we must convert the array to 8‑bit unsigned integers in the range
# [0,255] before we can use it with OpenCV
diff = (diff * 255).astype("uint8")
cv2.imshow('diff',diff)
cv2.waitKey()
Note: Your two input images are not exactly the same, they are slightly shifted so SSIM picks up the shifted pixels
방법 2:
I'm not sure if you are aware of the complexity of your problem. Your issues are: ‑ Different resolution of the original and the 'noisy' image ‑ Translational error ‑ Perspective distortion when taking the photo of the original
Theoretically you can find tools for image processing in cv2 that can handle those problems. When you are able to get rid of the distortions you can simply apply the code that you posted to see the noise as a result of the systematic errors of the camera, monitor and all calculations that you did.
(by Mitesh Patel、nathancy、Meredith Hesketh Fortescue)