Reputation: 13
Below is some of my code. I am going through a folder, pulling every image, and finding the RGB value of every pixel, and determining which ones are blue. I am trying to only increment per file, but for some reason, it is continuing and adding every file's increment.
try {
int width = image.getWidth();
int height = image.getHeight();
for(int k = 0; k < height; k++){
for(int j = 0; j < width; j++){
Color c = new Color(image.getRGB(j, k));
int redVal = c.getRed();
int greenVal = c.getGreen();
int blueVal = c.getBlue();
//24 42 72
if ((redVal >= 0) && (redVal <= 80)) {
if ((greenVal >= 40) && (greenVal <= 105)) {
if ((blueVal >= 80) && (blueVal <= 135)) {
count++;
}
}
}
}
}
System.out.print(count +" pixels are \"blue\", ");
Output:
23700 pixels are "blue"
27199 pixels are "blue"
38136 pixels are "blue"
40834 pixels are "blue"
41443 pixels are "blue"
50349 pixels are "blue"
How can I fix this? Thank you.
Upvotes: 0
Views: 44
Reputation: 8348
If you want count
to only represent the blue in a single file, then reset it's value to 0 before iterating over the pixels:
int width = image.getWidth();
int height = image.getHeight();
count = 0;
...
Upvotes: 2