如何解决当我仅在Y中执行直方图匹配时,为什么Cr和Cb的直方图会略有变化?
我用来匹配直方图和所有import语句的代码:
import skimage.viewer
from skimage import data,io,color
from skimage import exposure
from skimage.exposure import match_histograms
ref1 = io.imread("drive/My Drive/Images_for_Adarsh/DSC_6139.JPG")
orig1 = io.imread("drive/My Drive/Images_for_Adarsh/DSC_6138.JPG")
ref = color.rgb2ycbcr(ref1)
orig = color.rgb2ycbcr(orig1)
f1 = match_histograms(orig,ref,multichannel=True)
f1[:,:,1] = orig[:,1]
f1[:,2] = orig[:,2]
f2 = color.ycbcr2rgb(f1)
我用来绘制直方图的代码:
import numpy as np
import cv2
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
img1 = cv2.imread("drive/My Drive/Images_for_Adarsh/DSC_6176.JPG")
img2 = cv2.imread("drive/My Drive/Y Histogram_Match RESULTS/Y6176.JPG")
img1f = cv2.cvtColor(img1,cv2.COLOR_BGR2YCR_CB)
img2f = cv2.cvtColor(img2,cv2.COLOR_BGR2YCR_CB)
histr1 = cv2.calcHist([img1f],[0],mask,[256],[0,255])
histr2 = cv2.calcHist([img2f],255])
f = figure(num=None,figsize=(9,5),dpi=400,facecolor='w',edgecolor='k')
plt.subplot(1,2,1)
plt.plot(histr1,color = 'pink')
plt.xlim([0,275])
plt.xlabel("Luminance")
plt.ylabel("No. of Pixels")
plt.subplot(1,2)
plt.plot(histr2,275])
plt.xlabel("Luminance")
plt.ylabel("No. of Pixels")
a1 = f.add_subplot(121)
a2 = f.add_subplot(122)
f.suptitle("DSC_6176 -- LUMINANCE HISTOGRAM",fontsize=16)
a1.title.set_text('ORIGINAL')
a2.title.set_text('RESULT(after Y value Histogram Matching)')
plt.subplots_adjust(left=None,bottom=None,right=None,top=None,wspace=0.45,hspace=None)
plt.savefig("drive/My Drive/histograms Y Matching/Luminance6176.JPG",dpi = 400)
This is the Cb histogram for the original image on the left and that of final result on the right
This is the Cr histogram for the original image on the left and that of final result on the right
This is the reference image(I want the luminance histogram of the input image to this image)
在这里,我正在对亮度(YCRCB中的“ Y”值)执行直方图匹配。为此,我要在所有三个通道(Y,Cr和Cb)上执行直方图匹配,然后从原始图像中复制Cr和Cb并将其放入我的最终图像中。因此,实际上,我的代码仅修改了亮度,而Cr和Cb不变。但是,当我绘制3个通道的直方图时,Cr和Cb通道会略有变化。我不明白这一点。为什么会这样呢?请帮忙!提前致谢! 我添加了原始图像的Luminance(Y),Cb和Cr直方图和结果,以供您参考。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。