private static Image enhance(Image image, int[]histogram) {

		ImageData imageData = image.getImageData();

		// Calculate cumulative histogram
		int[] cumulativeHistogram = new int[256];
		for (int i = 0; i < cumulativeHistogram.length; i++) {// height
			if (i == 0)
				cumulativeHistogram[i] = histogram[0];
			else
				cumulativeHistogram[i] = histogram[i] + cumulativeHistogram[i - 1];

			// System.out.println(i+":\t"+histogram1[i]+"\t\t"+cumulativeHistogram[i]);
		}

		// Enhance existing image
		int height = imageData.height;
		int width = imageData.width;
		int r = 0;
		// Line by Line
		for (int i = 0; i < height; i++) {// height
			for (int j = 0; j < width; j++) {// width

				// byte gray = imageData.data[c++];
				// gray &= 0xFF;// Calculate Gray
				// System.out.print(gray + "=");
				int pixel = imageData.getPixel(j, i);
				switch (imageData.depth) {
				case 32:
					int A = pixel >> 32;
					int R = pixel >> 16 & 0xFF;
					int G = pixel >> 8 & 0xFF;
					int B = pixel & 0xFF;
					pixel = (int) (0.299 * R + 0.587 * G + 0.114 * B);
					break;
				case 24:
					R = pixel >> 16;
					G = pixel >> 8 & 0xFF;
					B = pixel & 0xFF;
					pixel = (int) (0.299 * R + 0.587 * G + 0.114 * B);// rgb -> gray
					break;
				}
				if (DEBUG)
					System.out.print(pixel + "\t");

				int cdf = cumulativeHistogram[pixel];
				int hv = Math.round((cdf - cumulativeHistogram[0]) * 255 / (height * width - cumulativeHistogram[0]));

				imageData.setPixel(j, i, hv);
				// newData[c++]=(byte)hv;
				// System.out.print(gray+","+hv+"\t|\t");///j+", "+i+": "+gray+" -> "+
			}
			if (DEBUG)
				System.out.println();
		}

		// Create new image

		Image image2 = new Image(image.getDevice(), imageData);
		/*boolean useTempFile = false;
		if (useTempFile) {
			ImageLoader loader = new ImageLoader();
			loader.data = new ImageData[] { imageData };
			String newImageName = "aaa";
			loader.save(IMAGE_PATH + newImageName, SWT.IMAGE_JPEG);
			InputStream is = null;
			try {
				is = new FileInputStream(IMAGE_PATH + newImageName);
			} catch (FileNotFoundException e) {
				throw new RuntimeException(e);
			}
			// is = HelloWorld.class.getResourceAsStream("Fig1.jpg");
			// ImageData[] data = loader.load(is);
			image2 = new Image(image.getDevice(), is);
		}*/
		return image2;
	}