Convert grayscale to colored images

Hi
I am stuck with my program.
BufferedImage gray = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics g = gray.getGraphics();
g.drawImage(bi, 0, 0, null);
g.dispose();using the above code, i have converted a colored image to a grayscale image.
now my problem is, i want to convert that grayscale image back to colored.
is there any way to do so?
please help
thanks

I am no expert in this, but I believe that when you lose the color information, it is lost forever never to be retrieved, that the basic premise of your program is incorrect. So, perhaps you can store information on what "filters" were applied (I'm not familiar with this "filter" concept) and in what order, and then after you have completed all the gray image processing, apply these filters to the stored colored image and then save it.

Similar Messages

  • DoEs AnYoNe KnOw HoW tO cOnVeRt GrAyScAlE ImAgEs To CoLoUr????

    Hi all,
    I 've got a simple image which has buildings,roads and grass areas. The image is currently in greyscale, and is basically a 400 by 700 text file full of interger values each representing a different land class - i.e. buildings have a value of 200, roads = 100 and grass areas = 60.
    does anyone know how to get the image from a grayscale image to a colour image?
    rob
    x

    argh... got confuse cos your subject.
    I 've got a simple image which has buildings,roads and grass areas. The image is currently in greyscale, and is basically a 400 by 700 text file full of interger values each representing a different land class - i.e. buildings have a value of 200, roads = 100 and grass areas = 60.this is not grayscale image rob. that file is data representation for your map, not color.
    sure you can convert it to color image, but you must define what color convertion do you like.
    DoEs ThIs SuBjEcT rElAtEd tO java?

  • How to use a grayscale color model in converting a colored image

    how to convert a colored image into grayscale using :
    ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
    int bits[] = new int[] {8};
    ColorModel cm = new ComponentColorModel(cs, bits, false, false,
    Transparency.OPAQUE,
    DataBuffer.TYPE_BYTE);
    please only this method , i don't need the "bandcombine" method cause i need to know that i have exact 256 grayscale colors, thanx in advance.

    I went into mail preferences in the first place. I found the fonts and colors and picked the color I want but it doesn;t seem to be sticking?

  • Convert color images to black&white bitmaps

    Hi,
    I have black&white scans of public domain books (image format). I use an OCR software to convert them to indexable PDFs (image+text format). However, the OCRed PDFs are insanely big: a 27 MB scanned PDF leads to an indexable PDF of 728 MB! And unfortunately, my OCR software doesn't have output settings, so I have to find a way to compress the files using Adobe Acrobat 9 Pro.
    Using Advanced Options > Optimization does reduce the file size, but not significantly. The problem seems to be that my OCR software converts the black&white scans to color images, and encodes them as such inside the PDF. So I need a way to set the image modes back to black&white. I tried using the Advanced Options > Preflight dialog, and selecting "Convert to black&white". However, the resulting PDFs stay about the same size! It seems that "Convert to black&white" converts the images to grayscale, instead of to bitmap.
    Any help would be appreciated!

    I mentioned "bitmaps", because when I open the original PDF and right-click a random page and select "Modify image..." and open the image in Photoshop, the mode is set to "Bitmap mode": meaning 1-bit mode, containing either black or white pixels. However, when I do "Modify image..." for the OCRed PDF, the mode is set to "RGB Color Mode". I think this explains, in part, the huge size of the OCRed PDF.
    Maybe this table will make it more clear:
    Original PDF (Bitmap Mode, 132 dpi)
    Size: 27 MB
    OCRed PDF (RGB Color Mode, 300 dpi)
    Size: 728 MB
    Now, from the table above, it's clear that I have to reduce the image resolution. So, using the Acrobat's PDF optimizer, I tried the following settings:
    Optimized OCRed PDF: Try 1 (Downsample to 132 dpi, JPEG compression)
    Size: 733 MB
    Optimized OCRed PDF: Try 2 (Downsample to 132 dpi, ZIP compression)
    Size: 449 MB
    But 449 MB is still huge for a single book. And I don't want to reduce the resolution under 132 dpi, because I will loose quality. Clearly, if the original document is just 27 MB, I should be able to squeeze the OCRed document too. But I don't know how.

  • How to combine 3 grayscale image into a color image??

    I have 3 8bit grayscale images, and want to convert them into a color image.
    How can I do this?
    Thank you in advance!

    BufferedImage.getRGB and BufferedImage.setRGB.

  • Converting from indexed color to grayscale no longer works in CS4

    I have a number of files to convert from indexed colors to grayscale. Did some but clicked "don't show me again" box on the Discard Colors warning. Now I can't make the conversion. Everything looks fine, but when I close file, then reopen, it's reverted to indexed colors - restarting Photoshop or the computer doesn't help.
    I'd appreciate any help....Thanks, Grant

    Grant,
    All your contact information is posted to the web. These forums are crawled by bots harvesting info.
    I don't think you want additional junk mail, unsolicited phone call scams, and possible attempts to crack your website, do you?
    People here recommend not to post contact info. Perhaps a forum moderator can remove your personal info, but you might be able to edit your post yourself.
    GIF only uses indexed color mode, So if you want your files to NOT be in the Indexed Color mode you need to save them as another file format like .png or .jpg

  • How to overlay color image over a grayscale image without IMAQ?

    I would like to display a color image over a grayscale image; I would like the color image look translucent. How would I do this without using IMAQ functions? I am currently displaying my grayscale image using Intensity Graph.

    > I would like to display a color image over a grayscale image; I would
    > like the color image look translucent. How would I do this without
    > using IMAQ functions? I am currently displaying my grayscale image
    > using Intensity Graph.
    Transparency and overlays are really just arithmetic on the images. It
    is either done by the windowing system or by you. At the moment you
    can't set transparency on LV controls. You can set it on LV floating
    windows on some OSes, but then you will need to have the windows lined up.
    A more direct approach is to lighten or darken the color image elements
    based upon whether they will display over white, black, or a shade of
    gray. If the images don't have the same size pixels, this will have a
    first step of resampling th
    e images so they do. Then combine the pixels
    using the transparency you were going to apply to the color and the
    shade of gray beneath it. I'm being vague here because there are lots
    of physical models for combining colors.
    If I look in my paint program I see about fifteen, so this is where you
    get to make a choice and decide if black behind a red pixel is black, or
    dark red. It all depends on whether these are two transparent
    images(acetate sheets) backlit, or is it a transparency over a
    nontransmitting media like paper. Anyway, if you can be more specific
    about what you want, none of this is hard, typically just scaling the
    int32s, adding, and some sort of normalization.
    Greg McKaskle

  • How to convert color image(24 bit) YUV 4:2:2 to gray scale 8 bit image

    I am using sony DFW-X700 color camera for one of vision applications.Does NI Compact Vision System(CVS) support YUV 4:2:2 format(8 bit each).I want to do gray scale processing, so i need to convert the YUV color into gray scale (8-bit) in the software(like Labview). Please suggest us how to do this conversion for better gray scale image clarity from color.

    In YUV color space, Y represents the gray scale; in RGB color space, R=G=B represents gray scale. You can simply set R=G=B=Y, to convert YUV to RGB. If the original color depth is 24 bit, then the result is 24 bit too.
    You can create gray scale color table like this:
    array size = 256;
    [0] = 0x000000;
    [1] = 0x010101;
    [2] = 0x020202;
    [255] = 0xFFFFFF;
    To convert 24 bit gray scale to 8 bit, check every pixel in 24 bit image to find the array index according to the color table, and replace the pixel with array index.
    George Zou
    http://gtoolbox.yeah.net
    George Zou
    http://webspace.webring.com/people/og/gtoolbox

  • Converting part of an image to Grayscale (black & white)

    Q. I want to make part of an image grayscale but keep some color elements.
    Answer: There is always more than one way to do something in Photoshop.
    #1 Select the area you want to be grayscale. Create a new Hue/Saturation Adjustment Layer (half-moon icon in the Layers palette). Dial down the Saturation.
    #2 Make a copy of your image and make it Grayscale.
    After creating a layer in the color image with just the part of your image you want to still be color paste the Grayscale image under this layer.
    Your image will still be a color image with elements that look grayscale.
    #3 In CS3 (version 10 ) use Image > Adjustments > Black & White

    It's all virtual right now. Various issues keep the points from being displayed, but it does contribute to the "level" setup which at some point will function (I'm guessing) much like the "old system" where you get certain bonuses (personal avatars, etc) depending on the "level" you are in the system.
    I'm already a level 4, so points only contribute to my "reputation", I guess. But TPTB have suggested that we inform users of the Forum on the proper way to use it to build a better community.
    Thanks for the "Solved"
    Patrick

  • How do I convert color image to color vector?

    Hi,
    Im fairly new/not very well versed in Illustrator, I was wondering if you guys could help me with instructions or tips how to convert old alphabet art to color and actualy converting color images like drawings to vector . Ive tried image trace but it turns the image black and white and with really rough strokes.
    Thank you!

    Is this art in the Public Domain? Or, do you have the copyright owner's permission to use it in your work? If the answer to both of these questions is no, then you should not be using it.
    That being said, I got good results with image trace (using the High Fidelity Photo preset) even on the low-res image you attached here. You just have to adjust the preferences after you do the trace.

  • How to convert a jpeg file into a 1-bit bmp file (2 colors image)

    Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
    I�m using FileSaver.saveAsBmp(String t) but what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
    Does anybody know how to do this? I�m really getting crazy with ths problem.
    Thanks in advance

    Hi opalo,
    this code may help you...
    import java.awt.*;
    import java.io.*;
    import java.awt.image.*;
    import javax.imageio.ImageIO;
    class Write1 extends Component {
    //--- Private constants
    private final static int BITMAPFILEHEADER_SIZE = 14;
    private final static int BITMAPINFOHEADER_SIZE = 40;
    //--- Private variable declaration
    //--- Bitmap file header
    private byte bitmapFileHeader [] = new byte [14];
    private byte bfType [] = {'B', 'M'};
    private int bfSize = 0;
    private int bfReserved1 = 0;
    private int bfReserved2 = 0;
    private int bfOffBits = BITMAPFILEHEADER_SIZE + BITMAPINFOHEADER_SIZE;
    //--- Bitmap info header
    private byte bitmapInfoHeader [] = new byte [40];
    private int biSize = BITMAPINFOHEADER_SIZE;
    private int biWidth = 50;
    private int biHeight = 70;
    private int biPlanes = 1;
    //private int biBitCount = 24;
    private int biBitCount = 1;
    private int biCompression = 0;
    private int biSizeImage = 0x030000;
    private int biXPelsPerMeter = 0x0;
    private int biYPelsPerMeter = 0x0;
    private int biClrUsed = 0;
    private int biClrImportant = 0;
    //--- Bitmap raw data
    private int bitmap [];
    //--- File section
    private FileOutputStream fo;
    //--- Default constructor
    public Write1() {
    public void saveBitmap (String parFilename, Image parImage, int
    parWidth, int parHeight) {
    try {
    fo = new FileOutputStream (parFilename);
    save (parImage, parWidth, parHeight);
    fo.close ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * The saveMethod is the main method of the process. This method
    * will call the convertImage method to convert the memory image to
    * a byte array; method writeBitmapFileHeader creates and writes
    * the bitmap file header; writeBitmapInfoHeader creates the
    * information header; and writeBitmap writes the image.
    private void save (Image parImage, int parWidth, int parHeight) {
    try {
    convertImage (parImage, parWidth, parHeight);
    writeBitmapFileHeader ();
    writeBitmapInfoHeader ();
    writeBitmap ();
    catch (Exception saveEx) {
    saveEx.printStackTrace ();
    * convertImage converts the memory image to the bitmap format (BRG).
    * It also computes some information for the bitmap info header.
    private boolean convertImage (Image parImage, int parWidth, int parHeight) {
    int pad;
    bitmap = new int [parWidth * parHeight];
    PixelGrabber pg = new PixelGrabber (parImage, 0, 0, parWidth, parHeight,
    bitmap, 0, parWidth);
    try {
    pg.grabPixels ();
    catch (InterruptedException e) {
    e.printStackTrace ();
    return (false);
    pad = (4 - ((parWidth * 3) % 4)) * parHeight;
    biSizeImage = ((parWidth * parHeight) * 3) + pad;
    bfSize = biSizeImage + BITMAPFILEHEADER_SIZE +
    BITMAPINFOHEADER_SIZE;
    biWidth = parWidth;
    biHeight = parHeight;
    return (true);
    * writeBitmap converts the image returned from the pixel grabber to
    * the format required. Remember: scan lines are inverted in
    * a bitmap file!
    * Each scan line must be padded to an even 4-byte boundary.
    private void writeBitmap () {
    int size;
    int value;
    int j;
    int i;
    int rowCount;
    int rowIndex;
    int lastRowIndex;
    int pad;
    int padCount;
    byte rgb [] = new byte [3];
    size = (biWidth * biHeight) - 1;
    pad = 4 - ((biWidth * 3) % 4);
    if (pad == 4) // <==== Bug correction
    pad = 0; // <==== Bug correction
    rowCount = 1;
    padCount = 0;
    rowIndex = size - biWidth;
    lastRowIndex = rowIndex;
    try {
    for (j = 0; j < size; j++) {
    value = bitmap [rowIndex];
    rgb [0] = (byte) (value & 0xFF);
    rgb [1] = (byte) ((value >> 8) & 0xFF);
    rgb [2] = (byte) ((value >> 16) & 0xFF);
    fo.write (rgb);
    if (rowCount == biWidth) {
    padCount += pad;
    for (i = 1; i <= pad; i++) {
    fo.write (0x00);
    int b = 1200;
    fo.write(b);
    rowCount = 1;
    rowIndex = lastRowIndex - biWidth;
    lastRowIndex = rowIndex;
    else
    rowCount++;
    rowIndex++;
    //--- Update the size of the file
    bfSize += padCount - pad;
    biSizeImage += padCount - pad;
    catch (Exception wb) {
    wb.printStackTrace ();
    * writeBitmapFileHeader writes the bitmap file header to the file.
    private void writeBitmapFileHeader () {
    try {
    fo.write (bfType);
    fo.write (intToDWord (bfSize));
    fo.write (intToWord (bfReserved1));
    fo.write (intToWord (bfReserved2));
    fo.write (intToDWord (bfOffBits));
    catch (Exception wbfh) {
    wbfh.printStackTrace ();
    * writeBitmapInfoHeader writes the bitmap information header
    * to the file.
    private void writeBitmapInfoHeader () {
    try {
    fo.write (intToDWord (biSize));
    fo.write (intToDWord (biWidth));
    fo.write (intToDWord (biHeight));
    fo.write (intToWord (biPlanes));
    fo.write (intToWord (biBitCount));
    fo.write (intToDWord (biCompression));
    fo.write (intToDWord (biSizeImage));
    fo.write (intToDWord (biXPelsPerMeter));
    fo.write (intToDWord (biYPelsPerMeter));
    fo.write (intToDWord (biClrUsed));
    fo.write (intToDWord (biClrImportant));
    // DataOutputStream temp = new DataOutputStream(fo);
    // int m = 32;
    // temp.writeInt(m);
    catch (Exception wbih) {
    wbih.printStackTrace ();
    * intToWord converts an int to a word, where the return
    * value is stored in a 2-byte array.
    private byte [] intToWord (int parValue) {
    byte retValue [] = new byte [2];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x00FF);
    return (retValue);
    * intToDWord converts an int to a double word, where the return
    * value is stored in a 4-byte array.
    private byte [] intToDWord (int parValue) {
    byte retValue [] = new byte [4];
    retValue [0] = (byte) (parValue & 0x00FF);
    retValue [1] = (byte) ((parValue >> 8) & 0x000000FF);
    retValue [2] = (byte) ((parValue >> 16) & 0x000000FF);
    retValue [3] = (byte) ((parValue >> 24) & 0x000000FF);
    return (retValue);
    class Writebmp
         public static void main(String args[])
              //Image img = Toolkit.getDefaultToolkit().getImage("jatin.bmp");
              try
              File filename = new File("jatin_test.bmp");
              BufferedImage image = ImageIO.read(filename);
              Graphics graphics = image.getGraphics();
              graphics.drawString("&#2313;&#2332;&#2327;&#2352;",10,30);
              Write1 w = new Write1();
              Image img = Toolkit.getDefaultToolkit().getImage("jatin_test.bmp");
              w.saveBitmap("jatin_test.bmp",img,200,200);
              catch (IOException e)
    System.err.println ("Unable to write to file");
    System.exit(-1);
    }

  • Convert a jpeg file into a 1-bit bmp file (2 colors image).

    Hi. I�m having serious problems to convert a jpeg file into a 1-bit bmp file (2 colors image).
    First, i,ve tried to get a 1-bit jpeg. But i think this is not possible, so what i have to do is to get a 1-bit bpm file.
    I�m using FileSaver.saveAsBmp(String destination) and what i get is a bmp image, but with 16M colors, but what i want is a 2 colors bmp file. A black and white image.
    Does anybody know how to do this? I�m really getting crazy with ths problem.
    Thanks in advance

    You better read this at
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=733738

  • Convert "Grayscale I16" to "RGB U64"

    Hello, 
    I need to convert an image from Grayscale I16 to RGB U64, but it doesn't work (I have joined a zip file).
    I think there is a bug in the NI Vision, or it's not implemented because I have no problem to do it from Grayscale U8 to RBG32. 
    Can you help me to find a solution to do that? 
    I need to use ReplaceColorPlane function or equivalent because I have to perform various treatments on each layer (RGB).
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    tests.zip ‏217 KB

    Hi Badgones73,
    The U64 image is composed of four U16 values (R, G, B and alpha). LabVIEW represents 16-bit images as an I16. When the IMAQ Extract Color Planes is called, the U16 value must be converted into I16 values. This is done by converting all values with a MSB of 1 to a value of 0. This means all the values from 32,768 to 65,535 are now 0. To avoid using losing these values, you must read the image into LabVIEW without using the vision functions.
    Once you have extracted the U16 values, they can be converted from U16 images to I16 images. Once this is done, you will be able to use all of the Vision functions.
    Also, i invite you to read the information on our website:
    How Do I Convert a Color Image to Grayscale?
    http://digital.ni.com/public.nsf/allkb/ED42C55C29B9B34C862570A60079952E?OpenDocument
    Regards,
    Rémi D.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> Les rencontres techniques de NI - Mesures et acquisition de données : de la théorie à la mise en ...

  • How can i compare two color images in vision builder for AI?

    What i want to do is to compare two images. I have a base color image that represents the desired colors and tones. I have another image to be compared to the base image. What i want to do is to compare this two images to know how close they are regarding contents of color and tones. In other words, i want to know how close is image 2 to image 1 (base sample)....
    I would like to know how to get the content of certain colors in an image and then compare this values with the same values from another image.
    For example..i have two sheets of paper that contain various mixed colors...i want to know the amount of green, red an blue in each image and then comapre this values.
    What i want to do is to compare difer
    ent samples of fabrics. this fabrics must be of a specified color...but due to the process they may vary in tone or even color...so i want to compare this fabrics to a amster sample to see how close they are in color and tone..
    Anything would help since i dont have experience in this type of comparisons...thanks

    VBAI allows you to work with grayscale images only. You can acquire an image, use the vision assistant to convert it grayscale by extracting the luminance plane (or any of the other color planes) and then analyze the resulting grayscale image. To do what you are talking about, though, it would really be better to get Vision for labview. You could then take color images, compare color plains, use statistical functions to determine average color values, and so on.

  • One spot color image

    How do I convert an image into a one-color (one PMS color) image?

    Image > mode > grayscale. Then Image > mode > duotone. Pull down the "type" drop down menu to monotone and use the picker to pick your color. If you want a PMS, you'll have to click the color libraries button in the picker dialogue box.
    I would make the grayscale conversion after creating a black & white adjustment layer to optimize the grayscale conversion.
    If you don't need a PMS, but just a 4-color simulation, you can use a gradient map adjustment layer instead.

Maybe you are looking for