Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void otsu(){
- int threshparam=0;
- getValuesOfRGB();
- Image src = imageView.getImage();
- int width = (int) src.getWidth();
- int height = (int) src.getHeight();
- int total = width*height;
- float sum = 0;
- for (int t=0 ; t<256 ; t++) sum += t * rgbH[t];
- float sumB = 0;
- int wB = 0;
- int wF = 0;
- float varMax = 0;
- threshparam = 0;
- for (int t=0 ; t<256 ; t++) {
- wB += rgbH[t]; // Weight Background
- if (wB == 0) continue;
- wF = total - wB; // Weight Foreground
- if (wF == 0) break;
- sumB += (float) (t * rgbH[t]);
- float mB = sumB / wB; // Mean Background
- float mF = (sum - sumB) / wF; // Mean Foreground
- // Calculate Between Class Variance
- float varBetween = (float)wB * (float)wF * (mB - mF) * (mB - mF);
- // Check if new maximum found
- if (varBetween > varMax) {
- varMax = varBetween;
- threshparam = t;
- }
- }
- binarize(threshparam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement