daily pastebin goal
12%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. close all; clear all; clc;
  2.  
  3. Im=imread('pout.tif');
  4. figure, imshow(Im)
  5. title('Init image')
  6. [nr, nc]=size(Im);
  7. Imsize=nr*nc;
  8. figure
  9. [P,x]=imhist(Im);
  10. bar(x,P);
  11. title('histogram')
  12. p=P/Imsize;
  13.  
  14. for k=1:256
  15.        c0(1:k)=p(1:k);
  16.        c1(k+1:256)=p(k+1:256);
  17.        W0=sum(c0);
  18.        if W0>0
  19.            W1=1-W0;
  20.            if W1>0
  21.                m0=0;
  22.                for i=1:k
  23.                    m0=m0+i*p(i);
  24.                end
  25.                m0=m0/W0;
  26.                m1=0;
  27.                for i=k+1:256
  28.                    m1=m1+i*p(i);
  29.                end
  30.                m1=m1/W1;
  31.                sb(k)=W0*W1*(m1-m0)*(m1-m0);
  32.            end
  33.        end
  34. end
  35.  
  36. [peak,Threshold]=min(sb);
  37. Threshold;
  38. for i=0:255
  39.     x(i+1)=i;
  40. end
  41. x1(1)=0;
  42. x1(2)=Threshold;
  43. y1(2)=peak;
  44. figure
  45. plot(x,sb,x1,y1)
  46. title('sb^2')
  47. text(Threshold-50,450,'Threshold position');
  48. Im=im2double(Im);
  49. bw=im2bw(Im,Threshold/255.0);
  50. figure
  51. imshow(bw)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top