问题描述
我有一个图像保持不变,另一个图像是第一个图像,但是上面应用了滤镜.我想创建第三个图像,该图像应该是前两个图像的合成.
I have one image that remains unchanged and another image which is the first one, but with a filter applied on it. I want to create the third image which should be the composite of these first two images.
我知道在MATLAB中有一个名为 imfuse()
的函数,其默认颜色通道为绿色-品红色.我想用完全相同的颜色通道在Python中执行相同的操作.我该怎么办?
I know that in MATLAB there is a function called as imfuse()
with the default color channel green-magenta. I want to do the same thing in Python, with exactly the same color channel. How can I do this ?
以下是图像(第一张是原始图片,第二张是应用了滤镜的第一张图片,第三张是MATLAB结果):
Here are the images (first is the original picture, second is the first picture with the filter applied, third is the MATLAB result):
感谢您的帮助!
推荐答案
默认情况下, imfuse
仅覆盖不同色带中的图像对(默认为 Method = falsecolor
和 ColorChannels = green-magenta
)
以下是MATLAB中的一个示例来说明(用Python/OpenCV编写起来应该很容易):
Here is an example in MATLAB to illustrate (it should should be easy to write this in Python/OpenCV):
% a pair of grayscale images
A = imread('cameraman.tif');
B = imrotate(A,5,'bicubic','crop'); % image "A" rotated a bit
% use IMFUSE
C = imfuse(A,B);
imshow(C)
% use our version where: Red=B, Green=A, Blue=B
C = cat(3, B, A, B);
imshow(C)
两者都应该给你同样的东西:
Both should give you the same thing:
这是Python/OpenCV版本:
Here is the Python/OpenCV version:
import numpy as np
import cv2
A = cv2.imread(r"C:\path\to\a.png", 0)
B = cv2.imread(r"C:\path\to\b.png", 0)
#C = cv2.merge((B,A,B))
C = np.dstack((B,A,B))
cv2.imshow("imfuse",C)
cv2.waitKey(0)
这篇关于如何使用Python在OpenCV中制作两个图像的合成物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!