




下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、 直方圖匹配,又稱直方圖規(guī)定化,即變換原圖的直方圖為規(guī)定的某種形式的直方圖,從而使兩幅圖像具有類似的色調(diào)和反差。直方圖匹配屬于非線性點運算。 直方圖規(guī)定化的原理:對兩個直方圖都做均衡化,變成相同的歸一化的均勻直方圖,以此均勻直方圖為媒介,再對參考圖像做均衡化的逆運算 / <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; /逆映射函數(shù) byte mapPixelR = new byte256; byte
5、mapPixelG = new byte256; byte mapPixelB = new byte256; /分別計算RGB三個分量的逆映射函數(shù) /R for (int i = 0; i < 256; i+) diffBR = 1; for (int j = kR; j < 256; j+) /找到兩個累計分布函數(shù)中最相似的位置 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> / 獲取圖像三個分量的直方圖數(shù)據(jù) / </summary> / <param name="srcBmp">圖像</param> / <param name="hR">R分量直方圖數(shù)據(jù)</param> / <par
14、am name="hG">G分量直方圖數(shù)據(jù)</param> / <param name="hB">B分量直方圖數(shù)據(jù)</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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工業(yè)園區(qū)規(guī)劃與可持續(xù)發(fā)展研究
- 工業(yè)廢水處理技術(shù)與設(shè)備發(fā)展研究
- 工業(yè)大數(shù)據(jù)分析與挖掘技術(shù)
- 工業(yè)安全防范系統(tǒng)建設(shè)與優(yōu)化
- 工業(yè)物聯(lián)網(wǎng)與智能化工廠的建設(shè)
- 工業(yè)生產(chǎn)中機器視覺檢測技術(shù)的應(yīng)用
- 工業(yè)綠色轉(zhuǎn)型與技術(shù)革新
- 工業(yè)設(shè)備故障診斷的機器學(xué)習(xí)方案
- 工業(yè)設(shè)計中的智能化技術(shù)應(yīng)用
- 工業(yè)自動化中的電力安全防護措施
- 批判性思維實踐手冊
- 《破產(chǎn)重整》課件
- 提高治療室物品放置規(guī)范率
- 《職場溝通技巧》課件
- 遼寧大學(xué)《生態(tài)學(xué)》2023-2024學(xué)年第一學(xué)期期末試卷
- 《Maya 2022三維動畫制作標準教程(全彩版)》第08章 渲染與輸出
- 2024秋國開《人工智能專題》專題測驗1-3答案
- 《我國上市公司財務(wù)舞弊探析案例-長園集團為例》14000字(論文)
- DB12-T 3035-2023 建筑消防設(shè)施維護保養(yǎng)技術(shù)規(guī)范
- 2024年湖北省初中學(xué)業(yè)水平考試地理試卷含答案
- DB35T 2067-2022 鍋爐用固體廢棄物燃料性能評價規(guī)則
評論
0/150
提交評論