2017-02-12 50 views
0

這是可能通過otsu方法找到一個好的二進制圖像?這樣的圖像可以通過otsu方法找到一個好的二值圖像嗎?

這樣的圖像的使用方法大津不顯示我試圖爲這個圖像的任何閾值,良好的輸出值化:

a6.jpg
a6.jpg

這裏是我的代碼:

A=imread('a6.jpg'); 
im=rgb2gray(A); 
figure,imshow(im); title('gray image'); 
im=A(:,:,1); 
[q r]=size(im); 
s=r/2; 
if true 
    %code 
    n1 = im(:, 1 : end/2); %image(x,y,c) c is matrix displayed as image 
    n2 = im(:, end/2+1 : end);%indicate last array index 
    if true 
     D=imhist(n2)-imhist(n1); 
     thresh_level = graythresh(D); %find best threshold level 
     c=zeros(size(im)); 
     [r c1] = size(im); 
     allpix=im; 
     allpix(allpix>thresh_level*200)=1; 
     allpix(allpix<=thresh_level*0)=0; 
     c=allpix; 
     figure,imshow(c); title('binary image'); 

    end 
end 

是否有任何閾值我可以得到一個良好的二進制圖像?

+0

所以,你要求你的程序實現了大津的方法是什麼? – flawr

+0

當然輸出圖像'c'不是一個二進制圖像。此外,似乎有很多不必要的代碼,請保持您的示例最小化。 – flawr

+0

我不明白爲什麼它不是一個二進制圖像,並且實現不是otsu方法。如果你解釋一下,它對我有幫助。 –

回答

0

我不知道你的程序在做,但是這應該是足夠了:

A=imread('a6.jpg'); 
im=rgb2gray(A); 
imshow(im); title('gray image'); 
c=im2bw(im,graythresh(im)); 
imshow(c); title('binary image'); 

,並將其輸出

enter image description here

+0

該圖像對文本識別沒有好處。儘管它作爲二值化遠非災難性的。筆劃寬度轉換使用Canny邊緣檢測來代替。但是,無論您做什麼,模糊區域都將具有挑戰性。 –

+0

你是對的,但是OP沒有提及任何有關文本識別的內容,他在詢問關於Otsu在MATLAB中的方法: – flawr

相關問題