JAVA: get the average brightness of an image
use this code together with code from choose file. You will need to uncomment the following line:

//ExamineImage.lum(sourceFolder);


import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.*;
import javax.imageio.*;
import javax.swing.*;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 import javax.swing.ImageIcon;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class ExamineImage{

public static void lum(String ffile) {
    BufferedImage img=null;
   
    File myFile = new File(ffile);
      //  File[] listOfFiles = myFolder.listFiles();
   
try{

              if (myFile.isFile()) {
              
            
               
                img = ImageIO.read(myFile);
                int width=0;
                int height=0;

                int count=0;
                double avg=0;
                            if(img!=null){
                               width  = img.getWidth();
                               height  = img.getHeight();
                            }
                             System.out.println("Width " + width + " " +  height);
                             /*
                      int[][] aa = new int[width][height];
                       int[][] rr = new int[width][height];
                        int[][] gg = new int[width][height];
                         int[][] bb = new int[width][height];
                         */
                
                for(int x=0; x < width; x++){
                    for (int y=0;y < height;y++){
                                   
                                 
                                     int pixelCol = img.getRGB(x, y);
                                        int a = (pixelCol >>> 24) & 0xff;
                                        int r = (pixelCol >>> 16) & 0xff;
                                        int g = (pixelCol >>> 8) & 0xff;
                                        int b = pixelCol & 0xff;
                                     /*
                                        aa[x][y] = a;
                                        rr[x][y] = r;
                                        gg[x][y] = g;
                                        bb[x][y] = b;
                                        */
                                       
                                     double lum=   (0.2126*r) + (0.7152*g) + (0.0722*b);
                                   avg += lum;
                                   count++;
                                     
                           }}  
                           
                           avg = avg/count;
                            System.out.println("The average luminance " +avg);
                 
                // image(rr,gg,bb);
            }

}catch(Exception e){

System.out.println("THERE WAS A PROBLEM " + e);
}

}//end of lumanance method








 public static void image(int[][] red, int[][] green, int[][] blue)
    {
       //make some changes to the pixels
     
    
        
     
       //make changes above
       
       
       
       //create new image


      BufferedImage img = new BufferedImage(255, 255, BufferedImage.TYPE_INT_RGB);
      
  
      
              
                    int r = 255;
                    int g = 255;
                    int b = 0;
                    int col = (r << 16) | (g << 8) | b;
                   // img.setRGB(x, y, col);
          
            
      
         
        File f = new File("aMyFile.jpg");
            
            
            try{
                ImageIO.write(img, "JPEG", f);
            } catch(Exception e){
                
            }
            
           
    }






}//end of class