I try to create a program which computes image histogram. I ve got the above code but i cant figure out why it doesnt work.
public void hist(List<Integer> r, List g, List b){
int count[] = new int [256];
int rSize = r.size();
int gSize = g.size();
int bSize = b.size();
for (int j = 0; j<=255; j++){
for(int i = 0; i < rSize; i++){
if( r.get(i) == j ){}
//System.out.println(r.get(i) == j);
count[j]++;
}
}
for (int i = 0; i < count.length; i++) {
System.out.print(count[i]);
}
}
If i call it in main, every element of count is rSize which is impossible as r list has the values of Red channel of an image.
Your
ifis empty:if( r.get(i) == j ){}.It should be:
Might want to use the debugger next time and simply step through your code, would’ve caught this easily.