two-dimensional Otsu's method
古いコメントを表示
I am trying to implement 2D Otsu segmentation method, but i am facing problem in my code. in 2D otsu the gray-level value of each pixel as well as the average value of its immediate neighborhood is studied so that the binarization results are greatly improved. I am attaching code,but it is not working and also hyperlink http://en.wikipedia.org/wiki/Otsu%27s_method
function inputs and output:
%hists is a 256\times 256 2D-histogram of grayscale value and neighborhood average grayscale value pair.
%total is the number of pairs in the given image.
%threshold is the threshold obtained.
function threshold = 2D_otsu(hists, total)
maximum = 0.0;
threshold = 0;
helperVec = 0:255;
mu_t0 = sum(sum(repmat(helperVec',1,256).*hists));
mu_t1 = sum(sum(repmat(helperVec,256,1).*hists));
p_0 = zeros(256);
mu_i = p_0;
mu_j = p_0;
for ii = 1:256
for jj = 1:256
if jj == 1
if ii == 1
p_0(1,1) = hists(1,1);
else
p_0(ii,1) = p_0(ii-1,1) + hists(ii,1);
mu_i(ii,1) = mu_i(ii-1,1)+(ii-1)*hists(ii,1);
mu_j(ii,1) = mu_j(ii-1,1);
end
else
p_0(ii,jj) = p_0(ii,jj-1)+p_0(ii-1,jj)-p_0(ii-1,jj-1)+hists(ii,jj);
mu_i(ii,jj) = mu_i(ii,jj-1)+mu_i(ii-1,jj)-mu_i(ii-1,jj-1)+(ii-1)*hists(ii,jj);
mu_j(ii,jj) = mu_j(ii,jj-1)+mu_j(ii-1,jj)-mu_j(ii-1,jj-1)+(jj-1)*hists(ii,jj);
end
if (p_0(ii,jj) == 0)
continue;
end
if (p_0(ii,jj) == total)
break;
end
tr = ((mu_i(ii,jj)-p_0(ii,jj)*mu_t0)^2 + (mu_j(ii,jj)-p_0(ii,jj)*mu_t0)^2)/(p_0(ii,jj)*(1-p_0(ii,jj)));
if ( tr >= maximum )
threshold = ii;
maximum = tr;
end
end
end
3 件のコメント
Geoff Hayes
2016 年 1 月 29 日
pramod - please clarify what you mean by it is not working. Are you observing an error, and if so, what is it (please copy and paste the full error message)? Or, are the results not what you expect. If this is the case, please describe your inputs (which you can attach as a mat file), what the outputs from the above are, and what they should be. Also, in the future, rather than copying and pasting your code into the question body, just attach the code (m file).
Harsha
2016 年 1 月 29 日
編集済み: Geoff Hayes
2016 年 1 月 29 日
Prabhu Bevinamarad
2020 年 11 月 13 日
Hi,
I am new to Matlab. I wanted to apply two-dimensional Otsu's method for thresholding. I am not getting how to find hists i.e. 2D-histogram of grayscale value and neighborhood average grayscale value pair and total is the number of pairs in the given image which are passed as a parameters for otsu_2D function.Can anybody suggest which functions are used.
Thank you
採用された回答
その他の回答 (1 件)
Harsha
2016 年 12 月 4 日
0 投票
5 件のコメント
Madhava Teja Munagala
2018 年 2 月 23 日
Hii harsha bro, im doing project on otsu 2d,,, im not understanding code,how to implement,plz help me
Harsha
2018 年 2 月 23 日
Madhava Teja Munagala
2018 年 2 月 23 日
編集済み: Madhava Teja Munagala
2018 年 2 月 25 日
thank u harsha bro, i get output, how to analyze loop
Image Analyst
2018 年 2 月 23 日
Madhava, I don't understand what you said.
MAS
2018 年 4 月 5 日
It works absolutely fine for two clusters. Any suggestions to update it for handling multi-level thresholding!?
カテゴリ
ヘルプ センター および File Exchange で Computer Vision with Simulink についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
