Results 1 to 2 of 2
Thread: Plz Some one check my code
- 02-07-2009, 06:16 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 8
- Rep Power
- 0
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); }}
- 02-07-2009, 11:24 PM #2
'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
-
Check for null int
By SnarfSnarf in forum New To JavaReplies: 5Last Post: 01-30-2009, 11:12 PM -
Check for printer job
By pjmorce in forum Advanced JavaReplies: 0Last Post: 11-07-2008, 08:26 AM -
Check box tag
By elizaabru in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 08-26-2008, 02:37 PM -
Can someone check my code
By joz_12345 in forum Java 2DReplies: 7Last Post: 02-18-2008, 02:58 AM -
spell check
By kazitula in forum Java AppletsReplies: 2Last Post: 12-20-2007, 11:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks