@@ -405,6 +405,58 @@ public Color getColor(int x, int y){
405405 }
406406
407407
408+ //**************************************************************************
409+ //** getHistogram
410+ //**************************************************************************
411+ /** Returns an array with 4 histograms: red, green, blue, and average
412+ <pre>
413+ ArrayList<int[]> histogram = image.getHistogram();
414+ int[] red = histogram.get(0);
415+ int[] green = histogram.get(1);
416+ int[] blue = histogram.get(2);
417+ int[] average = histogram.get(3);
418+ </pre>
419+ */
420+ public java .util .ArrayList <int []> getHistogram (){
421+
422+ //Create empty histograms
423+ int [] red = new int [256 ];
424+ int [] green = new int [256 ];
425+ int [] blue = new int [256 ];
426+ int [] average = new int [256 ];
427+
428+ for (int i =0 ; i <red .length ; i ++) red [i ] = 0 ;
429+ for (int i =0 ; i <green .length ; i ++) green [i ] = 0 ;
430+ for (int i =0 ; i <blue .length ; i ++) blue [i ] = 0 ;
431+ for (int i =0 ; i <average .length ; i ++) average [i ] = 0 ;
432+
433+
434+ //Populate the histograms
435+ for (int i =0 ; i <this .getWidth (); i ++){
436+ for (int j =0 ; j <this .getHeight (); j ++){
437+ Color color = this .getColor (i , j );
438+ int r = color .getRed ();
439+ int g = color .getGreen ();
440+ int b = color .getBlue ();
441+
442+ red [r ] = red [r ]+1 ;
443+ green [g ] = green [g ]+1 ;
444+ blue [b ] = blue [r ]+1 ;
445+
446+ int avg = Math .round ((r +g +b )/3 );
447+ average [avg ] = average [avg ]+1 ;
448+ }
449+ }
450+
451+ java .util .ArrayList <int []> hist = new java .util .ArrayList <int []>();
452+ hist .add (red );
453+ hist .add (green );
454+ hist .add (blue );
455+ hist .add (average );
456+ return hist ;
457+ }
458+
459+
408460 //**************************************************************************
409461 //** addImage
410462 //**************************************************************************
0 commit comments