Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. public void otsu(){
  2. int threshparam=0;
  3. getValuesOfRGB();
  4.  
  5. Image src = imageView.getImage();
  6.  
  7. int width = (int) src.getWidth();
  8. int height = (int) src.getHeight();
  9.  
  10. int total = width*height;
  11.  
  12. float sum = 0;
  13. for (int t=0 ; t<256 ; t++) sum += t * rgbH[t];
  14.  
  15. float sumB = 0;
  16. int wB = 0;
  17. int wF = 0;
  18.  
  19. float varMax = 0;
  20. threshparam = 0;
  21.  
  22. for (int t=0 ; t<256 ; t++) {
  23. wB += rgbH[t]; // Weight Background
  24. if (wB == 0) continue;
  25.  
  26. wF = total - wB; // Weight Foreground
  27. if (wF == 0) break;
  28.  
  29. sumB += (float) (t * rgbH[t]);
  30.  
  31. float mB = sumB / wB; // Mean Background
  32. float mF = (sum - sumB) / wF; // Mean Foreground
  33.  
  34. // Calculate Between Class Variance
  35. float varBetween = (float)wB * (float)wF * (mB - mF) * (mB - mF);
  36.  
  37. // Check if new maximum found
  38. if (varBetween > varMax) {
  39. varMax = varBetween;
  40. threshparam = t;
  41. }
  42. }
  43.  
  44. binarize(threshparam);
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement