美文网首页
C#:三通道图像直方图

C#:三通道图像直方图

作者: 大龙10 | 来源:发表于2023-08-27 13:01 被阅读0次
RGB三通道图像直方图

一、程序

        private void uiButton5_Click(object sender, EventArgs e)
        {         
            //1:  计算直方图
            Mat[] mats = Cv2.Split(src_img); //分割图像(把三通道分割为3个单通道)
            Mat hist_B = new Mat();
            Mat hist_G = new Mat();
            Mat hist_R = new Mat();

            int[] channels0 = { 0 };
            int[] channels1 = { 1 };
            int[] channels2 = { 2 };
            int[] histSize = { 256 };

            Rangef[] rangefs = new Rangef[]
            {
                    new Rangef(0, 256),
            };

            Cv2.CalcHist(mats, channels0, new Mat(), hist_B, 1, histSize, rangefs, true, false);
            Cv2.CalcHist(mats, channels1, new Mat(), hist_G, 1, histSize, rangefs, true, false);
            Cv2.CalcHist(mats, channels2, new Mat(), hist_R, 1, histSize, rangefs, true, false);

            int high = 400;
            int width = 512;
            int bin_w = width / 256;//每个bins的宽度  画布的宽度除以bins的个数
            Mat histImage = new Mat(width, high, MatType.CV_8UC3, new Scalar(0, 0, 0)); //定义一个Mat对象,相当于一个画布

            //归一化,像素值有可能数据量很大,压缩一下。是范围在定义画布的范围内。
            Cv2.Normalize(hist_B, hist_B, 0, histImage.Rows, NormTypes.MinMax, -1, null);
            Cv2.Normalize(hist_G, hist_G, 0, histImage.Rows, NormTypes.MinMax, -1, null);
            Cv2.Normalize(hist_R, hist_R, 0, histImage.Rows, NormTypes.MinMax, -1, null);

            //绘制直方图

            for (int i = 1; i < 256; i++)//遍历直方图的级数
            {
                //B 画线,一条线有两个点组成。首先确定每个点的坐标(x,y) .遍历从1开始。0 ~ 1 两个点组成一条线,依次类推。
                Cv2.Line(histImage, new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_B.At<float>(i - 1))), new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_B.At<float>(i))), new Scalar(255, 0, 0), 1, LineTypes.AntiAlias);

                //G
                Cv2.Line(histImage, new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_G.At<float>(i - 1))), new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_G.At<float>(i))), new Scalar(0, 255, 0), 1, LineTypes.AntiAlias);

                //R
                Cv2.Line(histImage, new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_R.At<float>(i - 1))), new OpenCvSharp.Point(bin_w * (i - 1), high - Math.Round(hist_R.At<float>(i))), new Scalar(0, 0, 255), 1, LineTypes.AntiAlias);

            }
            pictureBox1.Image = histImage.ToBitmap();
        }
    

二、资料

「haixin-561」博客:
https://blog.csdn.net/weixin_41049188/article/details/93401792

相关文章

  • 用python简单处理图片

    一:打开显示保存 二.图像通道几何变换裁剪 三. 添加水印 四.图像中的像素访问 五.图像直方图 (第一部分说明)...

  • Metal图像处理——直方图均衡化

    Metal图像处理——直方图均衡化 Metal图像处理——直方图均衡化

  • exp1-空间域图像增强

    图像灰度变换 计算显示图像直方图、直方图均衡化 空间域图像平滑、锐化

  • 基本的图像数据处理和分析

    skimage的基本用法 直方图是在展平图像上计算的:对于彩色图像,应在每个通道上单独使用该功能,以获得每个颜色通...

  • 第 4 章 用直方图统计像素

    本章包括以下内容: 计算图像直方图; 利用查找表修改图像外观; 直方图均衡化; 反向投影直方图检测特定图像内容; ...

  • 2019-04-10 OpenCV学习

    11边缘保留滤波(EPF) 美化图片 12图像直方图 13直方图应用 直方图均衡化:图像增强的一个手段 直方图比较...

  • 遥感数字图像处理方法

    1.直方图法 对于每幅图像都可作出其灰度直方图。根据直方图的形态可大致推断图像的质量。由于图像包含有大量的像元...

  • 直方图均衡化

    直方图均衡化的介绍 直方图均衡化是一种简单有效的图像增强技术,通过改变图像的直方图来改变图像中各像素的灰度,主要用...

  • 基本图像操作

    基本图像操作 1.直方图(histograms) 定义 直方图是对图像在某个指标的不同值的数量的统计,如亮度直方图...

  • OpenCV 之ios 直方图均衡化

    OpenCV 之ios 直方图均衡化 目标 在这个教程中你将学到: 什么是图像的直方图和为什么图像的直方图很有用 ...

网友评论

      本文标题:C#:三通道图像直方图

      本文链接:https://www.haomeiwen.com/subject/wftbmdtx.html