Skip to content

Instantly share code, notes, and snippets.

@remysucre
Last active November 8, 2017 21:49
Show Gist options
  • Save remysucre/6ebdca1af7863ee040c1681098bae8fd to your computer and use it in GitHub Desktop.
Save remysucre/6ebdca1af7863ee040c1681098bae8fd to your computer and use it in GitHub Desktop.
package mold;
import java.util.List;
import java.util.Arrays;
class Histogram {
public static class Pixel {
public int r, g, b;
public Pixel (int r, int g, int b) {
this.r = r;
this.g = g;
this.b = b;
}
}
public static void main (String [] args) {
List < Pixel > pixels = Arrays.asList (new Pixel (10, 10, 10), new Pixel (120, 120, 120), new Pixel (210, 210, 210), new Pixel (10, 120, 210));
int [] hR = new int [256];
int [] hG = new int [256];
int [] hB = new int [256];
histogram (pixels, hR, hG, hB);
}
@SuppressWarnings("unchecked")
public static int [] [] histogram (List < Pixel > image, int [] hR, int [] hG, int [] hB) {
int i = 0;
{
labeled_1 : while (i < image.size ()) {
int r = image.get (i).r;
int g = image.get (i).g;
int b = image.get (i).b;
hR [r] ++;
hG [g] ++;
hB [b] ++;
i += 1;
{
labeled_2 : while (i < image.size ()) {
int r = image.get (i).r;
int g = image.get (i).g;
int b = image.get (i).b;
hR [r] ++;
hG [g] ++;
hB [b] ++;
i += 1;
}
}}
} int [] [] result = new int [3] [];
result [0] = hR;
result [1] = hG;
result [2] = hB;
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment