Results 1 to 2 of 2
  1. #1
    TamTam is offline Member
    Join Date
    Feb 2009
    Posts
    8
    Rep Power
    0

    Default Plz Some one check my code

    HI...I wanted a code for Histogram Equalization to study greyscale image (the pixels' variation) and i found this but with no main so I added a main..The result upon running gives me : run:BUILD SUCCESSFUL (total time: 12 seconds) but am not seeing the result how could it be displayed..this is the code with the main statuc..:confused::confused::confused::
    Java Code:
    public class Histogram extends Thread{
      
      //no of grey-scale values 
      private final int grey_scales = 256;
      private final int hist_height = 256;
    
      // histogram colors
      private final int fgcolor = 0xff000000;
      private final int bgcolor = 0xffffffff;
      
      //width and height of the image
      private int i_w=0;
      private int i_h=0;
     
      //pixel arrays for input image and histogram
      private int [] hist_1d;
      private int [] src_1d;
      
      //width of histogram.  
      public int hist_w = 256; 
      
      //array for histogram bins
      private double [] hist_values;
    
    
      /**
       *Creates a 256*256 image array for the histogram of the specified image array
       *@param src Image array to be turned into a histogram
       *@param width The width of the input image
       *@param height The height of the input image
       *@return An image array representing the histogram of the input image
       */
    
      public int[]  histogram(int [] src, int width, int height){
        
        i_w = width;
        i_h = height;
        src_1d = new int[i_w * i_h];
        src_1d = src;
        
        hist_1d = new int[hist_w*i_h];
        int gs = grey_scales; 
        hist_values = new double[gs];
        
        //histogram "normalisation"
        double increment = 1.0/256.0; 
        
        //the grayscale value appearing more often.
        double max_value = 0.0;
        
        //to spread over 256 vertical values of histogram
        int scale_factor = 0; 
        int blue;
        int l = hist_1d.length;
        int n = 1; 
        
        for(int i=0; i<src_1d.length; i++){
          blue = src_1d[i] & 0x000000ff;
          hist_values[blue] += increment;
          max_value = (hist_values[blue]>max_value)?hist_values[blue]:max_value;
        }
        
        scale_factor = (int) Math.floor(i_h / max_value);
        
        for(int i=0;i<hist_values.length;i++){
          hist_values[i] *= scale_factor;
        }
        
        //this is the bit which represents the hist bins as black
        //lines.
        
        for(int i = 0; i < hist_values.length; i++){
          while (hist_values[i] > 0){
    	  hist_1d[(l - gs*n) + i] = fgcolor;
    	hist_values[i] -= 1;
    	n++;
          }
          n=1;
        }
        
        return hist_1d ;  
      }
    
      /**
       *Calculates the peak value of the histogram
       *@param the image
       *@param the width of the image
       *@param the height of the image
       *@return the peak value in the histogram 
       */
    
      public int  peak (int [] src, int width, int height){
      
        int result = 0;    
        i_w = width;
        i_h = height;
        src_1d = new int[i_w * i_h];
        src_1d = src;
        
        hist_1d = new int[hist_w*i_h];
        int gs = grey_scales; 
        hist_values = new double[gs];
        
        //histogram "normalisation"
        double increment = 1.0/256.0; 
        
        //the grayscale value appearing more often.
        double max_value = 0.0;
        
        //to spread over 256 vertical values of histogram
        int scale_factor = 0; 
        int blue;
        int l = hist_1d.length;
        int n = 1; 
        
        for(int i=0; i<src_1d.length; i++){
          blue = src_1d[i] & 0x000000ff;
          hist_values[blue] += increment;
          max_value = (hist_values[blue]>max_value)?hist_values[blue]:max_value;
          
        }
        
    
        for (int i = 0; i<hist_values.length;i++){
          if (hist_values[i] == max_value) {
    	result = i;
          }
        }
         
      return result;
    }
      /**
       *Calculates the maximum value in the histogram
       *@param the image
       *@param the width of the image
       *@param the height of the image
       *@return the maximum value in the histogram
       */
    
      public double  maximum (int [] src, int width, int height){
      
        int result = 0;    
        i_w = width;
        i_h = height;
        src_1d = new int[i_w * i_h];
        src_1d = src;
        
        hist_1d = new int[hist_w*i_h];
        int gs = grey_scales; 
        hist_values = new double[gs];
        
        //histogram "normalisation"
        double increment = 1.0/256.0; 
        
        //the grayscale value appearing more often.
        double max_value = 0.0;
        
        //to spread over 256 vertical values of histogram
        int scale_factor = 0; 
        int blue;
        int l = hist_1d.length;
        int n = 1; 
        
        for(int i=0; i<src_1d.length; i++){
          blue = src_1d[i] & 0x000000ff;
          hist_values[blue] += increment;
          max_value = (hist_values[blue]>max_value)?hist_values[blue]:max_value;
          
        }
        
    
       return max_value * 256;
      }
    
      /**
       *Calculates the histogram and scales it.
       *@param the image
       *@param the width of the image
       *@param the height of the image
       *@param the value to set the histogram maximum
       *@return the int array containing the histogram scaled
       */
      public int[]  histogramScale(int [] src, int width, int height, double max){
        
        i_w = width;
        src_1d = src;
        
        hist_1d = new int[grey_scales*hist_height];
        hist_values = new double[grey_scales];
        
        //histogram "normalisation"
        //to spread over hist_height vertical values of histogram
        double increment = ((double)hist_height)/max; 
        int blue;
        
        for(int i=0; i<src_1d.length; i++){
          blue = src_1d[i] & 0x000000ff;
          hist_values[blue] += increment;
        }
        
        //draw the hist bins as lines
        int n; 
        for(int i = 0; i < hist_1d.length; i++){ hist_1d[i] = bgcolor; }
        for(int i = 0; i < hist_values.length; i++){
          if (hist_values[i] > hist_height) { hist_values[i] = hist_height; }
          n=1;
          while (hist_values[i] > 0){
    	hist_1d[(hist_1d.length - grey_scales*n) + i] = fgcolor;
    	hist_values[i] -= 1;
    	n++;
          }
        }
        return hist_1d ;  
      }
    
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
        new Histogram();
        PlanarImage image = JAI.create("fileload", args[0]);
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(image);
    }}

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    'Finding' code and attempting to use it without a shadow of understanding can be frustrating. Allow me to point you in the direction of a learning resource.
    The Java™ Tutorials

    db

Similar Threads

  1. Check for null int
    By SnarfSnarf in forum New To Java
    Replies: 5
    Last Post: 01-30-2009, 11:12 PM
  2. Check for printer job
    By pjmorce in forum Advanced Java
    Replies: 0
    Last Post: 11-07-2008, 08:26 AM
  3. Check box tag
    By elizaabru in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-26-2008, 02:37 PM
  4. Can someone check my code
    By joz_12345 in forum Java 2D
    Replies: 7
    Last Post: 02-18-2008, 02:58 AM
  5. spell check
    By kazitula in forum Java Applets
    Replies: 2
    Last Post: 12-20-2007, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •