I don't can convert exactely my rgb image to an gray image..
My final image it's to dark, and affects my work.
I use this code:
public static BufferedImage rgb2gray(BufferedImage bi)//converter
{
int heightLimit = bi.getHeight();
int widthLimit = bi.getTileWidth();
BufferedImage converted = new BufferedImage(widthLimit, heightLimit, BufferedImage.TYPE_BYTE_GRAY);
for (int height = 0; height < heightLimit; height++) {
for (int width = 0; width < widthLimit; width++) {
Color c = new Color(bi.getRGB(width, height) & 0x00fffff);
int newRed = (int) ((0.2989f * c.getRed()) * 1.45);//0.2989f
int newGreen = (int) ((0.5870f * c.getGreen()) * 1.45);//0.5870f
int newBlue = (int) ((0.1140f * c.getBlue()) * 1.45);
int roOffset = newRed + newGreen + newBlue;
converted.setRGB(width, height, roOffset);
}
}
return converted;
}
What is wrong?
In matlab the result it's perfect, but with this code in java is poor.