could you help me, you can tell me what I'm wrong with, my code has 2 for's that run through a whole 157x127 pixel image, from which I get black and white through RGB; in turn I have 2 counters of those two colors.
As I understand it, if the 157x127 measurement gives 19,939 pixels, of which there is black and white; but adding the counters gives me less (14218 for white and 5643 for black). Where am I wrong or is my logic wrong?
Add the image:
The application does not close itself
Code below:
BitmapDrawable drawable = (BitmapDrawable) imgviewREXMorphologEX.getDrawable();
Bitmap bitmap = drawable.getBitmap();
int Width = bitmap.getWidth();
int Height = bitmap.getHeight();
int contadorB = 0;
int contadorN = 0;
for (int x = 0; x <= Width - 1; x++) {
int xi = x;
for (int y = 0; y <= Height - 1; y++) {
int yi = y;
int coordenada = bitmap.getPixel(xi, yi);// pixel
double r = Color.red(coordenada);
double g = Color.green(coordenada);
double b = Color.blue(coordenada);
if (r == 255 && g == 255 && b == 255) {
contadorB++;
} else if (r == 0 && g == 0 && b == 0) {
contadorN++;
}
txtviewcolor3.setText(contadorB + " - " + contadorN + " - " + (contadorB + contadorN) + " - " + (Width * Height));
}
}