




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 直方图匹配,又称直方图规定化,即变换原图的直方图为规定的某种形式的直方图,从而使两幅图像具有类似的色调和反差。直方图匹配属于非线性点运算。 直方图规定化的原理:对两个直方图都做均衡化,变成相同的归一化的均匀直方图,以此均匀直方图为媒介,再对参考图像做均衡化的逆运算 / <summary> / 直方图匹配 / </summary> / <param name="srcBmp">原始图像</param> / <param name="
2、matchingBmp">匹配图像</param> / <param name="dstBmp">处理后图像</param> / <returns>处理成功 true 失败 false</returns> public static bool HistogramMatching(Bitmap srcBmp, Bitmap matchingBmp, out Bitmap dstBmp) if (srcBmp = null | matchingBmp = null) dstBmp = null; ret
3、urn false; dstBmp = new Bitmap(srcBmp); Bitmap tempSrcBmp = new Bitmap(srcBmp); Bitmap tempMatchingBmp = new Bitmap(matchingBmp); double srcCpR = null; double srcCpG = null; double srcCpB = null; double matchCpB = null; double matchCpG = null; double matchCpR = null; /分别计算两幅图像的累计概率分布 getCumulativePr
4、obabilityRGB(tempSrcBmp, out srcCpR, out srcCpG, out srcCpB); getCumulativeProbabilityRGB(tempMatchingBmp, out matchCpR, out matchCpG, out matchCpB); double diffAR = 0, diffBR = 0, diffAG = 0, diffBG = 0, diffAB = 0, diffBB = 0; byte kR = 0, kG = 0, kB = 0; /逆映射函数 byte mapPixelR = new byte256; byte
5、mapPixelG = new byte256; byte mapPixelB = new byte256; /分别计算RGB三个分量的逆映射函数 /R for (int i = 0; i < 256; i+) diffBR = 1; for (int j = kR; j < 256; j+) /找到两个累计分布函数中最相似的位置 diffAR = Math.Abs(srcCpRi - matchCpRj); if (diffAR - diffBR < 1.0E-08) /当两概率之差小于0.000000001时可近似认为相等 diffBR = diffAR; /记录下此时的
6、灰度级 kR = (byte)j; else kR = (byte)Math.Abs(j - 1); break; if (kR = 255) for (int l = i; l < 256; l+) mapPixelRl = kR; break; mapPixelRi = kR; /G for (int i = 0; i < 256; i+) diffBG = 1; for (int j = kG; j < 256; j+) diffAG = Math.Abs(srcCpGi - matchCpGj); if (diffAG - diffBG < 1.0E-08) d
7、iffBG = diffAG; kG = (byte)j; else kG = (byte)Math.Abs(j - 1); break; if (kG = 255) for (int l = i; l < 256; l+) mapPixelGl = kG; break; mapPixelGi = kG; /B for (int i = 0; i < 256; i+) diffBB = 1; for (int j = kB; j < 256; j+) diffAB = Math.Abs(srcCpBi - matchCpBj); if (diffAB - diffBB <
8、; 1.0E-08) diffBB = diffAB; kB = (byte)j; else kB = (byte)Math.Abs(j - 1); break; if (kB = 255) for (int l = i; l < 256; l+) mapPixelBl = kB; break; mapPixelBi = kB; /映射变换 BitmapData bmpData = dstBmp.LockBits(new Rectangle(0, 0, dstBmp.Width, dstBmp.Height), ImageLockMode.ReadWrite, PixelFormat.F
9、ormat24bppRgb); unsafe byte* ptr = null; for (int i = 0; i < dstBmp.Height; i+) ptr = (byte*)bmpData.Scan0 + i * bmpData.Stride; for (int j = 0; j < dstBmp.Width; j+) ptrj * 3 + 2 = mapPixelRptrj * 3 + 2; ptrj * 3 + 1 = mapPixelGptrj * 3 + 1; ptrj * 3 = mapPixelBptrj * 3; dstBmp.UnlockBits(bmp
10、Data); return true; / <summary> / 计算各个图像分量的累计概率分布 / </summary> / <param name="srcBmp">原始图像</param> / <param name="cpR">R分量累计概率分布</param> / <param name="cpG">G分量累计概率分布</param> / <param name="cpB">B分量累计概率分布&l
11、t;/param> private static void getCumulativeProbabilityRGB(Bitmap srcBmp, out double cpR, out double cpG, out double cpB) if (srcBmp = null) cpB = cpG = cpR = null; return; cpR = new double256; cpG = new double256; cpB = new double256; int hR = null; int hG = null; int hB = null; double tempR = ne
12、w double256; double tempG = new double256; double tempB = new double256; getHistogramRGB(srcBmp, out hR, out hG, out hB); int totalPxl = srcBmp.Width * srcBmp.Height; for (int i = 0; i < 256; i+) if (i != 0) tempRi = tempRi - 1 + hRi; tempGi = tempGi - 1 + hGi; tempBi = tempBi - 1 + hBi; else tem
13、pR0 = hR0; tempG0 = hG0; tempB0 = hB0; cpRi = (tempRi / totalPxl); cpGi = (tempGi / totalPxl); cpBi = (tempBi / totalPxl); / <summary> / 获取图像三个分量的直方图数据 / </summary> / <param name="srcBmp">图像</param> / <param name="hR">R分量直方图数据</param> / <par
14、am name="hG">G分量直方图数据</param> / <param name="hB">B分量直方图数据</param> public static void getHistogramRGB(Bitmap srcBmp, out int hR, out int hG, out int hB) if (srcBmp = null) hR = hB = hG = null; return; hR = new int256; hB = new int256; hG = new int256; BitmapData bmpData = srcBmp.LockBits(new Rectangle(0, 0, srcBmp.Width, srcBmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); unsafe byte*
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 离职工资结算协议书范本
- 餐饮连锁企业厨师长职位竞聘及培训协议
- 餐饮品牌授权与餐厅承包合同
- 个人美容院租赁合同模板
- 代驾泊车服务合同模板(含事故处理)
- 餐饮店租赁承包合作协议
- 【课件】弹力+2024-2025学年人教版物理八年级下册+
- 产后抑郁生活护理常规
- 组织管理方法论
- 中班健康保护眼睛教案
- 显示屏幕抗反光技术研究-洞察分析
- 地磅及地磅房施工方案
- 16S518雨水口标准图集
- T-CECA-G 0307-2024 数字化碳管理平台 建设评价指南
- 《建立特种设备“日管控、周排查、月调度”工作机制》专题培训
- 《破产重整》课件
- 提高治疗室物品放置规范率
- 2024年河南省中等职业教化技能大赛汽车运用与修理类竞赛方案
- 膝关节骨关节炎的临床护理
- 《职场沟通技巧》课件
- 辽宁大学《生态学》2023-2024学年第一学期期末试卷
评论
0/150
提交评论