Results 1 to 1 of 1
- 01-08-2008, 05:29 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 5
- Rep Power
- 0
Converting multiple banded image into single banded image... Image enhancement
I am trying to do image enhancement by histogram equalization using the below code. As of now i am not able to view the output be it correct or wrong.
The error thrown is regarding the input image being a 3 banded image. And ROI needs a single banded image. So i guess i need to convert my 3 banded image into 1 banded image. So how should i do that?
If you have a better code for image enhancement please provide me.
Here goes the code and the input image is "ww.jpg"
import java.awt.image.*;
import javax.media.jai.*;
import javax.media.jai.iterator.*;
class SubstitutePixelValues
{
public static void main (String[] args)
{
PlanarImage img = JAI.create("fileload", "ww.jpg");
// Get the image dimensions.
int width = img.getWidth();
int height = img.getHeight();
// Get the number of bands on the image.
SampleModel sm = img.getSampleModel();
int numBands = sm.getNumBands();
int binCount=1;
System.out.println(numBands);
// Allocate histogram memory.
int[] numBins = new int[numBands];
double[] lowValue = new double[numBands];
double[] highValue = new double[numBands];
for(int i = 0; i < numBands; i++)
{
numBins[i] = binCount;
lowValue[i] = 0.0;
highValue[i] = 255.0;
}
// Create the Histogram object.
Histogram hist = new Histogram(numBins, lowValue, highValue);
// Set the ROI to the entire image.
ROI roi = new ROI(img);
// Create the histogram op.
RenderedOp histImage = JAI.create("histogram", img, hist, roi, new Integer(1), new Integer(1));
// Retrieve the histogram.
hist = (Histogram)histImage.getProperty("histogram");
// Create an equalization CDF.
float[][] CDFeq = new float[numBands][];
for(int b = 0; b < numBands; b++) {
CDFeq[b] = new float[binCount];
for(int i = 0; i < binCount; i++) {
CDFeq[b][i] = (float)(i+1)/(float)binCount;
}
}
// Create a normalization CDF.
double[] mean = new double[] {128.0, 128.0, 128.0};
double[] stDev = new double[] {64.0, 64.0, 64.0};
float[][] CDFnorm = new float[numBands][];
for(int b = 0; b < numBands; b++) {
CDFnorm[b] = new float[binCount];
double mu = mean[b];
double twoSigmaSquared = 2.0*stDev[b]*stDev[b];
CDFnorm[b][0] =
(float)Math.exp(-mu*mu/twoSigmaSquared);
for(int i = 1; i < binCount; i++) {
double deviation = i - mu;
CDFnorm[b][i] = CDFnorm[b][i-1] +
(float)Math.exp(-deviation*deviation/twoSigmaSquared);
}
}
for(int b = 0; b < numBands; b++) {
double CDFnormLast = CDFnorm[b][binCount-1];
for(int i = 0; i < binCount; i++) {
CDFnorm[b][i] /= CDFnormLast;
}
}
// Create a histogram-equalized image.
RenderedOp eq = JAI.create("matchcdf", ".jpg", CDFeq);
// Create a histogram-normalized image.
RenderedOp nm = JAI.create("matchcdf", ".jpg", CDFnorm);
}
}
Similar Threads
-
Image Verification
By peiceonly in forum Java ServletReplies: 2Last Post: 04-04-2009, 07:38 AM -
How to display image ?
By Birkoff in forum AWT / SwingReplies: 7Last Post: 06-09-2008, 07:58 AM -
set coordinate to an image
By nuur in forum AWT / SwingReplies: 2Last Post: 04-01-2008, 08:08 AM -
image removing
By Triss in forum New To JavaReplies: 3Last Post: 01-20-2008, 08:27 PM -
Help with image mapping
By coco in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks