OpenCV之图像直方图

Posted MachineLP

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV之图像直方图相关的知识,希望对你有一定的参考价值。

python代码:

import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt


def custom_hist(gray):
    h, w = gray.shape
    hist = np.zeros([256], dtype=np.int32)
    for row in range(h):
        for col in range(w):
            pv = gray[row, col]
            hist[pv] += 1

    y_pos = np.arange(0, 256, 1, dtype=np.int32)
    plt.bar(y_pos, hist, align=\'center\', color=\'r\', alpha=0.5)
    plt.xticks(y_pos, y_pos)
    plt.ylabel(\'Frequency\')
    plt.title(\'Histogram\')

    # plt.plot(hist, color=\'r\')
    # plt.xlim([0, 256])
    plt.show()


def image_hist(image):
    cv.imshow("input", image)
    color = (\'blue\', \'green\', \'red\')
    for i, color in enumerate(color):
        hist = cv.calcHist([image], [i], None, [256], [0, 256])
        plt.plot(hist, color=color)
        plt.xlim([0, 256])
    plt.show()


src = cv.

以上是关于OpenCV之图像直方图的主要内容,如果未能解决你的问题,请参考以下文章

OpenCV之图像直方图反向投影

OpenCV之图像直方图比较

图像处理之直方图均衡化拉伸

Opencv之图像灰度化

OpenCV之直方图处理

OpenCV基础之模板匹配与直方图