Advertisement
Guest User

Untitled

a guest
Dec 15th, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. A=imread(txt);
  2. org=A;
  3. [h,w,f]=size(A);
  4.  
  5.  
  6. A = imadjust(A,[0.3 0.7],[]);
  7. A = rgb2gray(A);
  8. A = medfilt2(A, [3 3]);
  9. level = graythresh(A);
  10.  
  11.  
  12. A = im2bw(A,level*1.3);
  13. A = bwareaopen(A,30);
  14.  
  15. A=edge(A,'roberts');
  16.  
  17.  
  18.  
  19.  
  20.  
  21. horHist=zeros(w);
  22.  
  23. for i=1:w
  24. tot=0;
  25. for j=1:h
  26. if (A(j,i)==1)
  27. tot=tot+1;
  28. end
  29. end
  30. horHist(i)=tot;
  31. end
  32.  
  33.  
  34.  
  35.  
  36.  
  37. gem=max(horHist)/2.3;
  38.  
  39. hstart=0;
  40. heinde=0;
  41. width=0;
  42. hcounter=0;
  43. arc=0;
  44. hcoor=zeros(1,2);
  45.  
  46.  
  47. for i=1:w
  48. if horHist(i)>gem(1)
  49. if(hstart==0)
  50. hstart=i;
  51. end
  52. hcounter=0;
  53. else
  54. if hstart>0
  55. if hcounter>(w*0.07)
  56. heinde=i-hcounter;
  57. width=heinde-hstart;
  58. if(width>(w*0.1))
  59. arc=arc+1;
  60. hcoor(arc,1)=hstart;
  61. hcoor(arc,2)=width;
  62. end
  63. hstart=0;
  64. hcounter=0;
  65. heinde=0;
  66. width=0;
  67. end
  68. hcounter=hcounter+1;
  69. end
  70. end
  71. end
  72.  
  73. [ww,f]=size(hcoor);
  74. hstart=0;
  75. hwidth=0;
  76.  
  77. for i=1:ww
  78. if(hcoor(i,2)>hwidth)
  79. hwidth=hcoor(i,2);
  80. hstart=hcoor(i,1);
  81. end
  82. end
  83.  
  84. A=A(:,hstart:(hstart+hwidth),:);
  85.  
  86.  
  87. verHist=zeros(h);
  88.  
  89. for j=1:h
  90. tot=0;
  91. for i=2:hwidth
  92. if (A(j,i-1)==1 && A(j,i)==0) || (A(j,i-1)==0 && A(j,i)==1)
  93. tot=tot+1;
  94. end
  95. end
  96. verHist(j)=tot;
  97. end
  98.  
  99.  
  100. verh=zeros(1);
  101. coun=1;
  102.  
  103.  
  104. for i=1:h
  105. if(verHist(i)>0)
  106. verh(coun)=verHist(i);
  107. coun=coun+1;
  108. end
  109. end
  110. gem=mean(verh)
  111.  
  112. vstart=0;
  113. veinde=0;
  114. height=0;
  115. vcounter=0;
  116. arc=0;
  117. vcoor=zeros(1,2);
  118. h*0.07
  119.  
  120. for(i=1:h)
  121. if verHist(i)>gem(1)
  122. if(vstart==0)
  123. vstart=i;
  124. end
  125. vcounter=0;
  126. else
  127. if vstart>0
  128. if vcounter>(h*0.03)
  129. veinde=i-vcounter;
  130. height=veinde-vstart;
  131. if(height>(h*0.05))
  132. arc=arc+1;
  133. vcoor(arc,1)=vstart;
  134. vcoor(arc,2)=height;
  135. end
  136. vstart=0;
  137. vcounter=0;
  138. veinde=0;
  139. height=0;
  140. end
  141. vcounter=vcounter+1;
  142. end
  143. end
  144. end
  145. [l,f]=size(vcoor);
  146. axes(handles.axes5);
  147.  
  148.  
  149.  
  150. A=org(vcoor(l,1):vcoor(l,1)+vcoor(l,2),hstart:(hstart+hwidth),:);
  151. imshow(A);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement