




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、圖像分割的閾值算法matlab實(shí)現(xiàn)【OTSU,1DEntropy,2DEntropy】今天看了幾篇論文,實(shí)現(xiàn)了一下,沒(méi)有驗(yàn)證各算法的有效性也沒(méi)有進(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對(duì)其閾值和熵進(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% 計(jì)算直方圖 %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 熵閾值的鐵譜磨粒圖像分割方法,傅建平%廖振強(qiáng),張培林,汪傳忠,(南京理工大學(xué)機(jī)械學(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直方圖,橫軸上以點(diǎn)象素灰度表示,縱軸上以局部區(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)計(jì)灰度對(duì)<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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030運(yùn)動(dòng)光學(xué)裝置行業(yè)項(xiàng)目調(diào)研及市場(chǎng)前景預(yù)測(cè)評(píng)估報(bào)告
- 2025至2030中國(guó)自由潛水鰭行業(yè)市場(chǎng)占有率及投資前景評(píng)估規(guī)劃報(bào)告
- 2025至2030中國(guó)自動(dòng)家庭服務(wù)行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)膿皰病治療行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)能源部門綜合行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)聯(lián)苯雙酯行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)老年教育行業(yè)市場(chǎng)發(fā)展分析及經(jīng)營(yíng)案例與投資發(fā)展報(bào)告
- 2025至2030中國(guó)美體內(nèi)衣行業(yè)發(fā)展研究與產(chǎn)業(yè)戰(zhàn)略規(guī)劃分析評(píng)估報(bào)告
- 2025至2030中國(guó)網(wǎng)絡(luò)遙測(cè)解決方案行業(yè)產(chǎn)業(yè)運(yùn)行態(tài)勢(shì)及投資規(guī)劃深度研究報(bào)告
- 2025至2030中國(guó)網(wǎng)絡(luò)文學(xué)行業(yè)競(jìng)爭(zhēng)狀況與盈利前景研究報(bào)告
- 輸變電工程檔案管理歸檔要求
- SYB創(chuàng)業(yè)培訓(xùn)游戲模塊2課件
- 【超星爾雅學(xué)習(xí)通】航空概論網(wǎng)課章節(jié)答案
- 獸醫(yī)傳染病學(xué)(山東聯(lián)盟)智慧樹(shù)知到答案章節(jié)測(cè)試2023年青島農(nóng)業(yè)大學(xué)
- 腸系膜脈管系統(tǒng)腫瘤的診斷
- 爆破工程技考核試卷
- GB/T 35273-2020信息安全技術(shù)個(gè)人信息安全規(guī)范
- GB 18068-2000水泥廠衛(wèi)生防護(hù)距離標(biāo)準(zhǔn)
- 教師調(diào)動(dòng)登記表(模板)
- 2022年醫(yī)院收費(fèi)員考試試題及答案
- 福建省林業(yè)行政執(zhí)法人員法律考試
評(píng)論
0/150
提交評(píng)論