下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 手机销户协议书
- 税务代扣税协议书
- 苗木电子合同范本
- 荣誉加身协议书
- 蛇苗购买协议书
- 视频合同协议书
- 设备进场协议书
- 设计包工协议书
- 评标保密协议书
- 试用机器协议书
- 2025年临沂市公安机关第四季度招录警务辅助人员(400名)考试题库新版
- 2025年公务员考试申论真题模拟环境治理与污染对策深度解析
- 2025西藏日喀则市萨嘎县招聘公益性岗位考试笔试参考题库及答案解析
- 2025福建三明市农业科学研究院招聘专业技术人员3人笔试考试备考题库及答案解析
- 2025年10月自考14107人体工程学.试题及答案
- 2025年南网能源公司社会招聘(62人)考试笔试参考题库附答案解析
- 《下肢深静脉血栓形成介入治疗护理实践指南》的解读2025
- 经营区域保护合同范本
- 2025年滁州辅警招聘考试真题及答案详解(历年真题)
- 基于多模型视角下我国A股上市公司财务危机预警的深度剖析与实证检验
- 公园绿化养护景观绿化维护项目迎接重大节会活动的保障措施
评论
0/150
提交评论