我有一个 RGB 图像的直方图,它表示三个分量 R、G 和 B 的三个曲线。我想找到每条曲线的拐点。我使用二阶导数来找到它们,但我不能,二阶导数不会取消其返回空值。那么如何找到拐点呢?有没有其他方法可以找到它们?
import os, cv2, random
import numpy as np
import matplotlib.pyplot as plt
import math
from sympy import *
image = cv2.imread('C:/Users/Xers/Desktop/img.jpg')
CHANNELS = ['r', 'g', 'b']
for i, channel in enumerate( CHANNELS ):
histogram = cv2.calcHist([image], [i], None, [256], [0,256])
histogram = cv2.GaussianBlur( histogram, (5,5), 0)
plt.plot(histogram, color = channel)
x= plt.xlim([0,256])
y = plt.ylim([0, 24000])
derivative1= np.diff(histogram, axis=0)
derivative2= np.diff(derivative1, axis=0)
inf_point = np.where ( derivative2 == 0)[0]
print(inf_point)
plt.show()
Run Code Online (Sandbox Code Playgroud)