




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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学年人教版(2012)音乐五年级上册
- 2024秋七年级数学上册 第三章 一元一次方程3.4 实际问题与一元一次方程 6销售中的盈亏问题教学设计(新版)新人教版
- 13《人物描写一组》教学设计-2023-2024学年五年级下册语文统编版
- 2023八年级语文下册 第六单元 21《庄子》二则教学设计 新人教版
- 6 让我们的学校更美好第二课时教学设计-2023-2024学年道德与法治三年级上册(部编版)
- Unit 2 My schoolbag Part B(教学设计)-2024-2025学年人教PEP版英语四年级上册
- 17《松鼠》(教学设计)-2024-2025学年语文五年级上册统编版
- 九年级体育 第6周 第11次课教学设计
- 劳动合同期满不再续签协议书6篇
- 03 小青蛙 教学设计-2024-2025学年语文一年级下册统编版
- 开曼群岛公司法2024版中文译本(含2024年修订主要内容)
- TSGD7002-2023-压力管道元件型式试验规则
- 医院培训课件:《静脉血栓栓塞症(VTE)专题培训》
- 2024年4月自考00150金融理论与实务试题及答案
- 团结就是力量曲谱和歌词
- 2022年交通管制员年终考核个人工作总结
- 热镀锌螺栓检测报告
- 管理制度隐蔽工程验收管理办法
- AQL2.5抽检标准
- 社会支持评定量表SSRS肖水源
- 四线制改变运行方向电路动作细解
评论
0/150
提交评论