简体   繁体   English

OpenCV 颜色直方图 calcHist 仅考虑特定像素(而非完整图像)

[英]OpenCV color histogram calcHist considering only specific pixels (and not full image)

I want to calculate the color histogram of an image but only taking into account specific pixels (whose 2D coordinates I know).我想计算图像的颜色直方图,但只考虑特定像素(我知道其 2D 坐标)。

Is it possible to use calcHist specifying that only these concrete pixels should be taken into consideration (instead of the whole cv::Mat and all the pixels in it)?是否可以使用 calcHist 指定只考虑这些具体像素(而不是整个 cv::Mat 及其中的所有像素)? If not, is it possible to create a new Mat including only those specific pixels at known positions, and how?如果没有,是否可以创建一个新的 Mat 只包含已知位置的那些特定像素,以及如何创建? (Considering that for a histogram the pixel coordinates do not matter, could they be added to a (1 x number_of_specific_pixels)-dim Mat keeping the original type of the Mat?) (考虑到对于直方图,像素坐标无关紧要,是否可以将它们添加到 (1 x number_of_specific_pixels)-dim Mat 中以保持 Mat 的原始类型?)

Thanks a lot in advance!非常感谢!

The third parameter of clalHist is called Mask . clalHist的第三个参数称为Mask

So, you create a new single channel 8 bit cv::Mat that has the same size of your input image.因此,您创建了一个新的单通道 8 位cv::Mat ,它与输入图像的大小相同。 It should contain 255's where you want to calculate the histogram and 0's where you do not.它应该包含255's您想要计算直方图0's地方,以及0's您不需要0's地方。 Then, pass it as Mask .然后,将其作为Mask传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM