how to select automatic threshold value in otsu method to segment the tumor ina an image?
조회 수: 1 (최근 30일)
이전 댓글 표시
i use these codes.. here k value is choosed manually.. how to choose this value automatically? pls send me the ans..
a=imread('kkk.png') figure;imshow(a); [r c]=size(a); L = 256; k = 150; p=zeros(1,L); %Computing Histogram for level=1:1:L for i=1:1:r for j=1:1:c if(a(i,j)==level) p(level)=p(level)+1; end end p(level) = p(level); end end p1 = zeros(1,L); var = zeros(1,L); temp=0; mg = 0; %-p1 calculation for thresh=1:k for ite= 1:thresh temp=temp+p(ite); end p1(thresh)=temp; temp=0; end p2 = zeros(1,L); temp2 = 0; %p2 calculation for thresh2 = k+1: L for i = thresh2:L
temp2 = temp2 + p(i); end p2(thresh2)=temp2; temp2=0; end m1 = zeros(1,L); temp3 = 0; %m1 calculation for thresh3 =1:k for i =1:thresh3 temp3 = temp3 + i* p(i); end m1(thresh3) = temp3/p1(thresh3); end m2 = zeros(1,L); temp4 = 0 %m2 calculation for thresh4 =k+1:L for i =thresh4:L temp4 = temp4 + i* p(i); end m2(thresh4) = temp4/p2(thresh4); end %global mg = p1(k)*m1(k)+p2(k)*m2(k); % mg = m1(k)+m2(k);
%Between Class Variance for v =1:L var(v) = ( p1(v)*(m1(v)-mg)^2 )+( p2(v)*(m2(v)-mg)^2 ); end
%finidng max var(k*)
[maxNum IndexofMaxNum] = max(var) output=a; for i=1:r for j=1:c if output(i,j) >IndexofMaxNum output(i,j)=255; else output(i,j)=0; end end end
subplot(1,3,1) imshow(a); title('Orignal Image'); subplot(1,3,2) stem(p); title('Histogram'); subplot(1,3,3) title('Output Image'); imshow(output);
댓글 수: 0
답변 (1개)
Image Analyst
2013년 8월 29일
The Otsu method is automatic - there is no subjectivity or interactivity involved, so I'm not sure what you're asking.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!