当我仅在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 Luminance histogram for the original image on the left and that of final result on the right

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 input image

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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...