Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-08-2008, 06:29 PM
Member
 
Join Date: Nov 2007
Posts: 5
archanajathan is on a distinguished road
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);

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to display image ? Birkoff AWT / Swing 7 06-09-2008 08:58 AM
set coordinate to an image nuur AWT / Swing 2 04-01-2008 09:08 AM
image removing Triss New To Java 3 01-20-2008 09:27 PM
Help with image mapping coco AWT / Swing 1 08-07-2007 05:06 AM
Image Verification peiceonly Java Servlet 1 04-27-2007 05:50 PM


All times are GMT +3. The time now is 02:47 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org