




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、圖像分割的閾值算法matlab實現(xiàn)【OTSU,1DEntropy,2DEntropy】今天看了幾篇論文,實現(xiàn)了一下,沒有驗證各算法的有效性也沒有進(jìn)行定量比較OTSU% OTSU method% 2006/9/4clc;clear;%I = imread('E:testchinalake.bmp','bmp');I = imread('E:testlena.png','png');I = double(I);I = Medianfilter(I); &
2、#160; % median filterh_Tmean = mean(mean(I);height,width = size(I);Size = height * width; % the size of the imageh_T = sum(sum(I); % the total gray value of the imageG_min = min(min(I); % the min gray value of the imageG_max = max(max(I);
3、160; % the max gray value of the iamgeI_seg = zeros(height,width); % the array to store the segmented imagethresh = 0; % the thresholdnum1 = 0;num2 = 0;
4、0; % count the num of the pixel from the diffrient classP1 = 0;P2 = 0; % the probability of the different classh_T1 = 0;h_T2 = 0; % the total gray value of
5、different class h_T1mean = 0;h_T2mean = 0; % the mean value of the classmax = 0;for thresh=G_min:G_max % find the best threshold h_T1 = 0; h_T2 = 0; num1 = 0; for
6、 h=1:height for w=1:width if I(h,w) <= thresh num1 = num1 + 1; &
7、#160; h_T1 = h_T1 + I(h,w); end end end num2 = Size -
8、num1; h_T2 = h_T - h_T1; P1 = num1/Size; P2 = num2/Size; h_T1mean = h_T1/num1; h_T2mean = h_T2/num2; %D =
9、P1*(h_T1mean - h_Tmean)2 + P2*(h_T2mean - h_Tmean)2; D1 = P1*P2*(h_T1mean - h_T2mean)2; % the tow equation i
10、s equal if D1 > max max = D1; T_best = thresh; % T record the best thresh end end&
11、#160; % Seg the image % for i=1:height for j=1:width if I(i,j) > T_best I_seg(i,j) = 255; end
12、160; end end T_best figure; imshow(uint8(I_seg); figure; imhist(uint8(I); * 一維直方圖熵閾值算法% 1D entropy thresholding method% Pun提出,Kapur對其閾值和熵進(jìn)行改進(jìn)% 兩類:object 和background% P1 = sum(pi) i:1T% P2
13、 = sum(pi) i:T+1255% HO = ln(P1) + H1/P1;% HB = ln(P2) + H2/P2;% H1 = -sum(pi*ln(pi); i:1T% H2 = -sum(pi*ln(pi); i:T+1255% H = HO + HB;% T_best = argmax(H);clc;clear;%I = imread('E:testchinalake.bmp','bmp');I = imread('E:testlena.png','png');I = double(I);
14、I = Medianfilter(I); % median filterheight,width = size(I);Size = height * width; % the size of the imageh_T = sum(sum(I); % the total gray value of the imageG_min = min(min(I); % the min gray value
15、 of the imageG_max = max(max(I); % the max gray value of the iamgeI_seg = zeros(height,width); % the array to store the segmented imageI_hist = zeros(1,256); % the array to store the hist of the ima
16、gethresh = 0; % the thresholdnum1 = 0;num2 = 0; % count the num of the pixel from the diffrient classP1 = 0;P2 = 0;
17、; % the probability of the different classh_T1 = 0;h_T2 = 0; % the total gray value of different class max = 0;H1 = 0;H2 = 0; % the middle varH_object
18、 = 0;H_background = 0;H_total = 0; % the total entropyT_best = 0; % the best thresh% 計算直方圖 %for i=1:height % calculate the hist of the image for j=1:w
19、idth I_hist(I(i,j)+1) = I_hist(I(i,j)+1) + 1; endendfor thresh=G_min:G_max % find the best threshold H1 = 0; h_T1 = 0; H2 = 0; for h=1:height
20、60; for w=1:width if I(h,w) <= thresh num1 = num1 + 1;
21、60; h_T1 = h_T1 + I(h,w); end end end num2 = Size - num1;
22、60; h_T2 = h_T - h_T1; P1 = num1/Size; P2 = num2/Size; for i=1:thresh px = I_hist(i+1)/Size; H1 = H1 + (-px*ln(px);
23、; end for i=thresh+1:G_max px = I_hist(i+1)/Size; H2 = H2 + (-px*ln(px); end H_object = l
24、n(P1) + H1/P1; H_background = ln(P2) + H2/P2; H_total = H_object + H_background; if H_total > max max = H_total;
25、60; T_best = thresh; end end % Seg the image % for i=1:height for j=1:width if I(i,j) > T_best &
26、#160; I_seg(i,j) = 255; end end end T_best figure; imshow(uint8(I_seg); figure; imhist(uint8(I);*2維直方圖熵閾值算法% 二維直方圖熵閾值法% 參考 基于2D 熵閾值的鐵譜磨粒圖像分割方法,傅建平%廖振強,張培林,汪傳忠,(南京理工大學(xué)機械學(xué)院,南京 ),%(軍械工程學(xué)院,石家莊)%
27、160; pixel gray% % |% | => 2D histgram% |% |% |_> local grayclc;clear;%I = imread('E:testchinalake.bmp','bmp');I = imread(
28、'E:testlena.png','png');I = double(I);height,width = size(I);Size = height * width; % the size of the imageG_min = min(min(I); % the min gray value of the imageG_max = max(max(I); % the max gray value of the iamgeI_2Dhist = zeros(G_max+1,G_ma
29、x+1); % the array to store the 2D hist of the imageI_mean = zeros(height,width); % the mean value of the local imageI_seg = zeros(height,width);WS = 3;
30、; % mean filter's window size 3*3nr = floor(WS/2);I_big = zeros(height+2*nr,width+2*nr); % the bigger array used to mean filterI_big(nr+1:height+nr,nr+1:width+nr) = I; % copy data from the original image% mean filter % 獲取局部區(qū)域灰度信息 %for i=1:height
31、60; for j=1:width sum = 0; num = 0; for h=-nr:nr for w=-nr:nr
32、; sum = sum + I_big(i+h,j+w); num = num + 1; end
33、 end I_mean(i,j) = sum/num; end end % 構(gòu)建2D直方圖,橫軸上以點象素灰度表示,縱軸上以局部區(qū)域灰度表示 % for i=1:height for j=1:width
34、0; h = I(i,j)+1; % 橫軸信息,避免0,所以加1,象素灰度 w = I_mean(i,j)+1; % 縱軸信息,避免0,所以加1,局部區(qū)域灰度
35、; I_2Dhist(h,w) = I_2Dhist(h,w) + 1; % 統(tǒng)計灰度對<pixel,local>的出現(xiàn)次數(shù),構(gòu)建2D直方圖 end end % find the best thresh : hor_thresh,and ver_thresh % for ver_thresh=0:G_max for hor_thresh=0:G_max
36、 sum1 = 0; sum2 = 0; H1 = 0; H2 = 0; for i=0:ver_thresh
37、; for j=0:hor_thresh sum1 = sum1 + I_2Dhist(i+1,j+1); end
38、60; end for i=0:ver_thresh for j=0:hor_thresh P1 = I_2Dhist(
39、i+1,j+1)/sum1; H1 = H1 + P1*log(P1); end end
40、0; if i < G_max & j < G_max for i=ver_thresh+1:G_max for j=hor_thresh+1:G_max
41、160; sum2 = sum2 + I_2Dhist(i+1,j+1); end &
42、#160; end for i=ver_thresh+1:G_max for j=hor_thresh+1:G_max P2 = I_2Dhist(i+1,j+1)/sum2; H2 = H2 +P2*log(P2);
溫馨提示
- 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)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中國幼兒托管行業(yè)市場調(diào)研分析及投資戰(zhàn)略咨詢報告
- 中國ERP軟件行業(yè)市場供需現(xiàn)狀及未來發(fā)展趨勢報告
- 2025年中國除雪設(shè)備行業(yè)市場全景調(diào)研及投資規(guī)劃建議報告
- 2025年中國儀表行業(yè)市場前景預(yù)測及投資戰(zhàn)略研究報告
- 2025年中國現(xiàn)代農(nóng)業(yè)行業(yè)發(fā)展前景預(yù)測及投資戰(zhàn)略研究報告
- 電機培訓(xùn)課件圖片
- 轉(zhuǎn)正實習(xí)報告
- 2025年中國大米蛋白行業(yè)發(fā)展前景預(yù)測及投資戰(zhàn)略研究報告
- 2025年中國微型繼電器行業(yè)競爭格局分析及投資規(guī)劃研究報告
- 廠房租賃合同
- 膀胱灌注課件完整版
- 給水排水管網(wǎng)系統(tǒng)智慧樹知到答案章節(jié)測試2023年廣州大學(xué)
- 2022版義務(wù)教育音樂課程標(biāo)準(zhǔn)解讀一PPT
- GB/T 26059-2010鈦及鈦合金網(wǎng)板
- GB/T 19673.2-2013滾動軸承套筒型直線球軸承附件第2部分:5系列外形尺寸和公差
- 《士兵突擊》課件
- 蘇教版六年級科學(xué)下冊期末考試卷及答案
- 孕產(chǎn)期保健管理及工作規(guī)范(喀什)
- 二、施組報審表
- 無砟軌道底座板首件施工總結(jié)(最新)
- 油藏數(shù)值模擬中幾種主要的數(shù)學(xué)模型
評論
0/150
提交評論