I also wonder about that, and I never made any changes at all. -_-
Yep, I printed them and they have the same pixels.
That's how weird my situation is. --"
I also wonder about that, and I never made any changes at all. -_-
Yep, I printed them and they have the same pixels.
That's how weird my situation is. --"
That's how weird my situation is
Can you explain what the problem is and show the code that is not working, display the program's output and explain what is wrong with that output and explain what you want the code to do.
I post all possible codes involved.
//gets all the pixels from the image
public static int[] getAllPixels(BufferedImage bi){
int[] rgbs;
width = bi.getWidth(null);
height = bi.getHeight(null);
rgbs = new int[width*height];
rgbs = bi.getRGB(0, 0, width, height, rgbs, 0, width);
}
//#1 suspect in the problem
//computes for the new pixels based on Histogram equalization
public static void histogramProcessing(BufferedImage bi){
int w = bi.getWidth(null), h=bi.getHeight(null);
int[] rgb = getAllPixels(bi);
int l=256;
for(int i=0; i<rgb.length; i++){
rgbsToPixel.addElement(rgb[i] & 0x000000ff);
rgbsToPixelClone.addElement(rgb[i] & 0x000000ff);
}
Collections.sort(rgbsToPixelClone, null);
Iterator it1 = rgbsToPixelClone.iterator();
int numToFind=0, count=0, ctr=0;
numToFind = ((Integer)it1.next()).intValue();
while(it1.hasNext()){
Object i = it1.next();
int value = ((Integer)i).intValue();
if(numToFind==value){
count++;
}else{
count++;
pixelValues.add(numToFind);
pixelCount.add(count);
ctr++;
count=0;
numToFind = value;
}
}
count++;
pixelValues.add(numToFind);
pixelCount.add(count);
Iterator it2 = pixelCount.iterator();
double cdfValue = (((Integer)it2.next()).intValue());
cdfValue = (cdfValue/(w*h));
cdfCount.add(cdfValue);
hValues.add(cdfValue);
while(it2.hasNext()){
Object i = it2.next();
double nextValue = (((Integer)i).intValue());
nextValue = nextValue/(w*h);
hValues.add(nextValue);
cdfValue = cdfValue + nextValue;
cdfCount.add(cdfValue);
}
Iterator it3 = cdfCount.iterator();
while(it3.hasNext()){
Object minCDF = cdfCount.firstElement();
double cCDF = (Double)it3.next();
double mCDF = (Double)minCDF;
double numerator = cCDF - mCDF;
double denominator = 1-mCDF;
double nCDF = Math.round((numerator/denominator)*(l-1));
int fnCDF = (int)nCDF;
fPixel.add(fnCDF);
}
Iterator fPixelVIterator = fPixel.iterator();
Iterator fhValIterator = hValues.iterator();
int num1 = (((Integer)fPixelVIterator.next()).intValue());
double fhVal1 = (Double)fhValIterator.next();
double fHVal;
int fHValidx, cnt=0;
while(fPixelVIterator.hasNext()){
int num2 = (((Integer)fPixelVIterator.next()).intValue());
double fhVal2 = (Double)fhValIterator.next() ;
if(num1==num2){
fhVal1 = fhVal1 + fhVal2;
fHValidx = fPixel.indexOf(num1, cnt);
finalHIndex.add(fHValidx);
finalH.add(0.0);
num1 = num2;
cnt++;
}else{
finalh.add(fhVal1);
fHValidx = fPixel.lastIndexOf(num1);
finalHIndex.add(fHValidx);
fHVal = cdfCount.get(fHValidx);
finalH.add(fHVal);
fhVal1 = fhVal2;
num1=num2;
cnt++;
}
}
finalh.add(fhVal1);
fHValidx = fPixel.lastIndexOf(num1);
finalHIndex.add(fHValidx);
fHVal = cdfCount.get(fHValidx);
finalH.add(fHVal);
}
//changes the value of the pixels
//#2 suspect in the problem
public static int[] pixelRemapping(){
Iterator rgbsIterator = rgbsToPixel.iterator();
while(rgbsIterator.hasNext()){
int rgbsVal = (((Integer)rgbsIterator.next()).intValue());
int rgbsIdx = pixelValues.indexOf(rgbsVal);
int newPixel = fPixel.get(rgbsIdx);
pixelTorgbs.add(newPixel);
}
int[] nPixel = new int[rgbsToPixel.size()];
for(int i=0; i<rgbsToPixel.size();i++){
nPixel[i]=pixelTorgbs.get(i);
}
return nPixel;
}
//creates the new image using the new pixels
public static BufferedImage creatingImage(int[] pixels){
BufferedImage newImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
newImage.setRGB(0, 0, width, height, pixels, 0, width);
return newImage;
}
//putting the image to a JLabel
Image picA = ImageFcn.creatingImage(ImageFcn.getAllPixels(bi));
picAftArea.setIcon(new ImageIcon(picA));
The problem: The new image does not appear correctly in the program.
The output:
(The left side is the before image.)
http://imageshack.us/photo/my-images/651/typebytegraynew.png/
http://imageshack.us/photo/my-images/408/typebytegrayoriginal.png/
http://imageshack.us/photo/my-images/844/typeintargbnew.png/
http://imageshack.us/photo/my-images/842/typeintargboriginal.png/
Supposedly output: Produce the new image (gray pixels range from 0-255)
Or for the given example, its output should be like this (at least)
http://en.wikipedia.org/wiki/File:JPEG_example_subimage_-_equalized.svg
Can you make ONE program that compiles and executes and shows your problem?
You have posted many pieces of code that I have no idea how to use to show the problem.
I'd expect the program to work on a small image with a fixed/known set of pixels that the program prints out to show what they are to start with.
Then process the image with the code in your program and print out the pixels that are the result of the changes by your program.
Then comment the output list of pixels saying what is wrong with each one and what its value should be.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.