private void equalize(){
        	int fileNum = 0;
            int height = image.getHeight();
            int width = image.getWidth();

            float[] hsb = new float[]{0,0,0,0};
            int[] pixels = image.getRGB(0, 0, width, height, null, 0, width);
            int[] histogram = new int[256];
            int cdfMin = 0;

            int i;
            Color c;

            // generate histogram of brightness values
            for(i = 0; i < pixels.length; i++){
                c = new Color(pixels[i]);
                hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsb);
                histogram[(int)(hsb[2]*255)]++;
            }

            // find first non-zero element of histogram
            for(i = 0; histogram[i] == 0; i++);

            cdfMin = histogram[i]; // because a cdf monotonically increases

            // convert histogram to cdf
            if(i == 0){
                i++;
            }

            for(; i < 256; i++){
                histogram[i] += histogram[i-1];
            }

            for(i = 1; i < 256; i++){
                histogram[i] = Math.round((((float) histogram[i])-cdfMin)/(height*width-cdfMin)*255);
            }

            for(i = 0; i < pixels.length; i++){
                c = new Color(pixels[i]);
                hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsb);
                hsb[2] = ((float) (histogram[(int)(hsb[2]*255)]))/255;
                pixels[i] = Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]);
            }

            BufferedImageFile equalizedImage = new BufferedImageFile(image);
            equalizedImage.setRGB(0, 0, width, height, pixels, 0, width);

            File outputfile1 = new File("unequalized " + image.getFilename() + ".jpg");
            File outputfile2 = new File("equalized " + image.getFilename() + ".jpg");
            
            try{
            	ImageIO.write(image, "jpg", outputfile1);
                ImageIO.write(equalizedImage, "jpg", outputfile2);
            }
            catch(Exception e){
                e.printStackTrace();
            }
        }