Converting a true color bufferedImage to a 256color?

Hi,
Does anyone know how to convert a true color bufferedImage to a 256 color?
Any help would be appreciated. Thank you

The simplest way is to choose an arbitrary lookup table then map each rgb pixel to its nearst value in the table. If the table is good for your type of image then the results can be reasonable.
A differnt way is just to drop the insignificant bits from each of r, g and b then
combine the reduced r,g and b into a single byte.
A better way is to compute a lookup table that is optimal for you image (for various definitions of "optimal"). Below are references for three different approachs to do this (taken from the JAI documentation of ColorQuantizeDescriptor). Once you have the optimised lookup table you
can find the nearest colour in it for each pixel (as in the first approach).
Median-Cut      Color Image Quantization for Frame Buffer Display, Paul Heckbert, SIGGRAPH proceedings, 1982, pp. 297-307
NeuQuant      Kohonen Neural Networks for Optimal Colour Quantization, Anthony Dekker, In Network: Computation in Neural Systems, Volume 5, Institute of Physics Publishing, 1994, pp 351-367.
Oct-Tree      Interactive Computer Graphics: Functional, Procedural, and Device-Level Methods by Peter Burger and Duncan Gillis, Addison-Wesley, 1989, pp 345.
Cheers
matfud

Similar Messages

  • JAI - Saved image has black background (unless screen config is True Color)

    Hi!
    I'm trying to save images using JAI's codecs. Everything is okay if screen config is True Color, but if in 256 colors (or even in 65536 colors) the background of my images looks very dark...
    Can you please have a look at the code bellow (and try it with some different screen configs). I'm really stuck with that issue; any suggestion may help...
    NOTE:
    - I've noticed this problem when using JAI's jpeg codec.
    - The problem occurs with both JDK 1.3 and 1.4.
    - The problem does not occur (only) if screen config is True Color.
    - You must rerun the code after changing screen config.
    Thanks for help...
    cbmn2
    +++++++++++++++++++
    import java.awt.*;
    import com.sun.media.jai.codec.*;
    import javax.media.jai.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.io.*;
    import java.awt.image.renderable.*;
    public class Test2 extends JFrame
    String codecFormat = "jpeg";
    String outFilePath = "./test.jpg";
    JPanel jp;
    JButton jb;
    MyActionListener mal = new MyActionListener();
    public Test2()
    setSize(800,600);
    Container cp = getContentPane();
    cp.setLayout(null);
    jp = new JPanel(){
    public void paintComponent(Graphics g)
    super.paintComponent(g);
    Dimension dim = getSize();
    // initialization...
    //==================
    g.setColor(Color.white);
    g.fillRect(0, 0, dim.width, dim.height);
    // some drawing...
    //=================
    int inset = 10;
    g.setColor(Color.red);
    g.fillRect(inset, inset, dim.width-2*inset, dim.height-2*inset);
    jp.setBounds(10,10,400,300);
    jp.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
    cp.add(jp);
    jb = new JButton("Save image to '"+outFilePath+"'");
    jb.setBounds(10,320,400,50);
    jb.addActionListener(mal);
    cp.add(jb);
    class MyActionListener implements ActionListener
    public void actionPerformed(ActionEvent ae)
    Object source = ae.getSource();
    if (source == jb)
    jb_actionPerformed(ae);
    public void jb_actionPerformed(ActionEvent ae)
    try {
    Image image = jp.createImage(jp.getWidth(), jp.getHeight());
    jp.paint(image.getGraphics());
    saveImage(image, outFilePath, codecFormat);
    JOptionPane.showMessageDialog(this, "File '"+outFilePath+"' is now saved...");
    catch(Exception e) {
    JOptionPane.showMessageDialog(this, "Oops! An exception occured...");
    public void saveImage(Image image, String filePath, String format) throws Exception
    // conversion Image => RenderedImage
    //==================================
    RenderedImage renderedImage = JAI.create("AWTImage", image);
    ParameterBlock pb = new ParameterBlock();
    pb.addSource(renderedImage);
    pb.add(DataBuffer.TYPE_BYTE);
    renderedImage = JAI.create("format", pb);
    // saving file
    //=============
    JAI.create("filestore", renderedImage, filePath, format);
    public static void main(String[] args)
    (new Test2()).setVisible(true);
    }

    try this:
    BufferedImage bi = new BufferedImage(1728,500,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D big = bi.createGraphics();
    Graphics2D g2 = bi.createGraphics();
    big.setFont(new Font("Dialog", Font.PLAIN, 20));
    big.setColor(Color.WHITE);
    big.fillRect(0,0,1728,500);
    big.setColor(Color.BLACK);
    big.drawString("Data/Time Created:" + new java.util.Date(), 80, 210);
    big.drawString("POLICY NUMBER: 1711215 NAME OF CALLER: BENEFICIARY", 80, 230);
    big.drawString("Requested: Loan Request XXXXXXXXXXXXXXXXXXXXXXXXXXXXX Current Loan Value: $0.00", 80, 270);
    g2.drawImage(bi, 0, 0, null);

  • In competitive exams photo in "true color" format.... How to do it in adobe photoshop please replay it.....

    In competitive exams photo in "true color" format.... How to do it in adobe photoshop>>> please replay it.....

    Mayuk, you are not making any sense here.
    True color (24-bit)
    "True Color" redirects here. For images with natural color rendition, see true-color.
    http://en.wikipedia.org/wiki/File:Truecolor.png 24 bits (16,777,216 colors, "truecolor")
    True color supports 24-bit for three RGB colors. It provides a method of representing and storing graphical-image information (especially in computer processing) in an RGB color space such that a very large number of colors, shades, and hues can be displayed in an image, such as in high-quality photographic images or complex graphics. Usually, true color is defined to mean 256 shades of red, green, and blue, for a total of 224 or 16,777,216 color variations. The human eye can discriminate up to ten million colors.[13]
     Color images composed from 3 grayscale images A, B & C assigned to R,G & B in different orders.
    "True color" can also refer to an RGB display-mode that does not need a color look-up table (CLUT).
    For each pixel, generally one byte is used for each channel while the fourth byte (if present) is being used either as an alpha channel, data, or simply ignored. Byte order is usually either RGB or BGR. Some systems exist with more than 8 bits per channel, and these are often also referred to as true color (for example a 48-bit true-color scanner).
    Even with true color, monochromatic images, which are restricted to 256 levels, owing to their single channel, can sometimes still reveal visible banding artifacts.
    True color, like other RGB color models, cannot express colors outside of the gamut of its RGB color space (generally sRGB).
    Macintosh systems refer to 24-bit color as "millions of colors".
    RGBA color space, or 32-bit color, is a variant of true color in which the additional 8-bit is allocated to transparency and indicates how transparent is the element to which the color is assigned, when overlaid on other elements.

  • How can I convert an Image ( or BufferedImage ) to Base64 format ?

    Hi folks...
    How can I convert an Image, or BufferedImage, to the Base64 format ?
    The image that I want to convert, I get from the webCam connected to the computer...
    Anyone can help me ?
    Rodrigo Kerkhoff

    I suggest you read this thread concerning this:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=477461
    Failing that, Google is your friend.
    Good luck!

  • How can I convert a pages color document to a PDF Black and White doc.

    How can I convert a pages color document to a PDF Black and White doc.  Or, covert the color to B&W in a new doc?

    > How can I convert a pages color document to a PDF Black and White doc.  Or, covert the color to B&W in a new doc?
    The general idea is that you colour correct photographs once, archive, and convert with or without colour changes. The archived photograph is unchanged - or we would be colour correcting the same photographs again and again and again.
    If you have a photograph with a corrected exposure, you can open the photograph in the Apple ColorSync Utility, apply a colour space conversion to a grayscale appearance using the preinstalled ICC profile, save the photograph under another name, and place that in your pagination.
    If you have a paginated document with corrected exposures, and any such non-scalable bitmap or scalable spline graphics as you have chosen to add, you can render the pagination as a whole to PDF through the same ICC profile, carrying out the same colour space conversion on any and all objects.
    Caveat: If you intend the pagination for certain processes, in particular offset lithography, then you are probably  expected not to render the type to grayscale, but rather to render it to single ink solid black. No software can determine what printing process you intend, you have to understand a bit about printing, and how to set up general colour space conversions in software. Ask your prepress provider, and if the answer is not prompt and proficient, pick another provider.
    /hh

  • 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

  • Virtual PC / XP Mode Error outs with Required configuration: - Windows must be configured in mode 800x600 minimum - Windows must be configured in mode 'true colors'.

    Hello,
    I am running Application using XP mode and Virtual PC on Windows 7. I have 8 GB RAM and more than 300 GB free disk space. When I launch application in XP, I receive following error 
    Required configuration: 
    - Windows must be configured in mode 800x600 minimum
    - Windows must be configured in mode 'true colors'.
    My screen resolution is  1024
    × 768
    and I do not see any other options to resolve this problem.
    Any guidance is greatly appreciated.
    Ganesh

    This is a thread that discusses your problem.
    https://social.technet.microsoft.com/Forums/windows/en-US/12a17fa5-ddab-4480-8973-1a13bfb2e8fd/need-more-than-16bit-color-depth-on-windows-xp-mode?forum=w7itprovirt
    Your app is probably calling for 32-bit color, and XP Mode with
    integration features doesn't support that.  There's 3 ways around it. 
    one, is to enable remote desktop in XP Mode and connect to the VM with
    remote desktop.
    2nd is to turn off the integration features and then you can set the XP
    Mode desktop to 1024x7687 and 32-bit color
    and 3rd, if you app supports 24-bit color, there's a registry hack to do
    it.  It's in the thread I posted above.
    Bob Comer

  • Convert from spot color to custom CMYK value in Applescript

    I thought this would be very simple and it's not apparently. I am trying to convert a spot color into a custom CMYK value. Basically:
    tell application "Adobe Illustrator"
              set theList to every path item of current document
              repeat with k from 1 to count of theList
                        if fill color of item k of theList = {name:"Dark Green"} then
                                  set fill color of item k of theList to {cyan:0.0, magenta:100.0, yellow:0.0, black:0.0}
                        end if
              end repeat
    end tell
    But this script obviously doesn't work. From what I can tell, the fill color simply returns the tint of the item, not the name of it. I can't find anything that returns the name of a spot color so I can set the correct corresponding color. In the above example, I made the color obviously changed so I could visually see the result.
    Any advice would be greatly appreciated! I'm a first time poster here.
    Thanks!

    tell application "Adobe Illustrator"
              tell current document
                        set theList to every path item
                        set sw to every swatch
                        repeat with i from 1 to count of sw
                                  set swname to name of item i of sw
                                  if swname = "Dark Green" then
                                            set swco to color of item i of sw
                                            repeat with k from (count of theList) to 1 by -1
                                                      set co to fill color of item k of theList
                                                      if swco = co then
                                                                set fill color of item k of theList to {cyan:0.0, magenta:100.0, yellow:0.0, black:0.0}
                                                      end if
                                            end repeat
                                  end if
                        end repeat
              end tell
    end tell

  • Can I sample a layer's "true" color despite its opacity and blend mode?

    I'm doing some painting with a lot of layers set to different blend modes.  I find that every time I want to paint on one of these layers, I have to go to that layer, set the opacity back to 100, change the blend mode back to "normal" sample the color, then change everything back and continue painting.  I realize I can save a swatch for the color, but it can get confusing when you're using subtle color differences on multiple layers.  It seems like there should be a modifier key to the tool that samples the layers "true" color discarding opacity and blend mode.  Does this exist?  Thanks!

    Perfect!  This is exactly what I'm looking for chris....I don't suppose there's any way to toggle the tool's "current layer/all layers" functionality on the fly so i don't have to go to the tool and select which mode I"m in each time is there?  I usually access this tool by just hitting "option" while using a brush.  Would be cool if i could set "Option + shift" to use the eyedropper in "current layer" mode.  Thanks for the speedy reply!

  • Photosmart 8250 not printing in true colors

    I replaced the Magenta ink cartridge on March 26, 2011.  Ever since I have been getting shades of magenta for my printing.  When I print an email with graphics on it the header information will print in black but the graphics will not print in the true colors.  I uninstalled the software and went to the HP web site to install the most update software.  But to no avail.  I also did a reset but that did not help.  Any suggestions on a solution will be appreciated.

    Hi
    Please perform the below step on the printer touch screen
    Please perform the below step on the printer touch screen, while you performing the steps both keys are invisible or not lit up
    (http://ecx.images-amazon.com/images/I/81KY%2BvZACkL._AA1500_.jpg)
    Touch Reverse or Undo arrow key (Bottom Left)
    Touch Little home icon (Top Left)
    Then touch Reverse or Undo arrow key (Bottom Left)
    Again touch the Reverse or undo (Bottom Left) Buttons, in sequence.
    You will see support menu listed on the printer touch screen
    Touch Support Menu.
    Press Right arrow for Reset Menu and Touch OK.
    Press Right arrow for Parital  Reset and Touch OK.
    Wait for unit to Power Down/Turn Off.
    Press Power button to turn the Printer On.
    Select Engligh language and USA Country -- select Yes to print alingment page -- select yes to setup if the printer is connected wireless, select Printer -- and go thru the process.
    Regards
    Justin
    Say thanks by clicking the Kudos Star in the post.
    If my post resolved your problem, please mark it as as Accepted Solution : )

  • How can i open the "Convert to Indexed Color" dialog with custom presets?

    Hi,
    I need to automatically open the "Convert to Indexed Colors" dialog in Photoshop. Before and after that i have some scripts running so its not possible to open the dialog manually. Also i want to set some custom presets (like number of colors etc.).
    Found something similar to what i want for the Color Range selection (opens the dialog with the presets you put in):
    function colorrange(enabled, withDialog, fuzziness) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        desc1.putInteger(app.charIDToTypeID('Fzns'),fuzziness);
        var desc2 = new ActionDescriptor();
        desc2.putDouble(app.charIDToTypeID('Lmnc'), 31.22);
        desc2.putDouble(app.stringIDToTypeID("a"), 0.86);
        desc2.putDouble(app.stringIDToTypeID("b"), 0.31);
        desc1.putObject(app.charIDToTypeID('Mnm '), app.charIDToTypeID('LbCl'), desc2);
        var desc3 = new ActionDescriptor();
        desc3.putDouble(app.charIDToTypeID('Lmnc'), 95.34);
        desc3.putDouble(app.stringIDToTypeID("a"), 54.59);
        desc3.putDouble(app.stringIDToTypeID("b"), 49.85);
        desc1.putObject(app.charIDToTypeID('Mxm '), app.charIDToTypeID('LbCl'), desc3);
        desc1.putInteger(app.stringIDToTypeID("colorModel"), 0);
        var desc4 = new ActionDescriptor();
        var desc4 = executeAction(app.stringIDToTypeID('colorRange'), desc1, dialogMode);
    How can i achieve the same for the indexed color conversion dialog? Apart from doing a lot of guessing regarding the stringIDs.
    Is there some kind of "lookup table" for char and string IDs?
    Thank you guys in advance! This forum has been a great help many times.

    Ok never mind i got it, stupid me.
    Recorded it with Script Listener and changed the "DialogMode" parameter of the executeAction function from "DialogModes.No" to "DialogModes.All".
    var idCnvM = charIDToTypeID( "CnvM" );
                var desc249 = new ActionDescriptor();
                var idT = charIDToTypeID( "T  " );
                    var desc250 = new ActionDescriptor();
                    var idPlt = charIDToTypeID( "Plt " );
                    var idClrP = charIDToTypeID( "ClrP" );
                    var idSele = charIDToTypeID( "Sele" );
                    desc250.putEnumerated( idPlt, idClrP, idSele );
                    var idClrs = charIDToTypeID( "Clrs" );
                    desc250.putInteger( idClrs, 4 );
                    var idFrcC = charIDToTypeID( "FrcC" );
                    var idFrcC = charIDToTypeID( "FrcC" );
                    var idNone = charIDToTypeID( "None" );
                    desc250.putEnumerated( idFrcC, idFrcC, idNone );
                    var idTrns = charIDToTypeID( "Trns" );
                    desc250.putBoolean( idTrns, false );
                    var idDthr = charIDToTypeID( "Dthr" );
                    var idDthr = charIDToTypeID( "Dthr" );
                    var idDfsn = charIDToTypeID( "Dfsn" );
                    desc250.putEnumerated( idDthr, idDthr, idDfsn );
                    var idDthA = charIDToTypeID( "DthA" );
                    desc250.putInteger( idDthA, 75 );
                var idIndC = charIDToTypeID( "IndC" );
                desc249.putObject( idT, idIndC, desc250 );
            executeAction( idCnvM, desc249, DialogModes.ALL ); //Change from NO to ALL

  • True colors are not showing on some photos.

    True colors are not showing on some photos. Today a black sweatshirt displayed as blue. Is there an adjustment?

    Reload the webpage while bypassing the cache using '''one''' of the following steps:
    *Hold down the ''Shift'' key and click the ''Reload'' button with a left click.
    OR
    *Press ''Ctrl'' + ''F5'' or ''Ctrl'' + ''Shift'' + ''R'' (Windows and Linux)
    *Press ''Command'' + ''Shift'' + ''R'' (Mac)
    Let us know if this solves the issues you are having.

  • Converting to CMYK color profile (for print) in raw format

    I am looking to self publish a cookbook in lightningsource. They need the photos in cmyk format. When is it best to convert to this color profile from rgb?
    I have bridge CS5
    What I'm doing currently:
    I click on my .arw image file and select "open in camera raw" which brings me to an editing screen. At the very bottom is says rgb, and 240 ppi
    I need 300 ppi at least and cmyk color.
    Now I know how to change these things in Photoshop, but I was taught that editing it in camera raw in bridge is better to preserve quality for print.
    Should I just edit it in raw and then convert to 300 dpi and cmyk color in photoshop? Or is there a way to do this in bridge? Whats the difference? Any advice will help, trying to make my pictures look amazing in print

    Correct me if I misunderstood anything!
    You are on the right track except for the ppi story. The ppi settings just are a figure expressing the amount of pixels stored in 1 inch, without the width and height figures of the image itself you can't do much with it and just changing this figure is not changing the total amount of available pixels.
    For instance create a new document at 300 ppi and use the international paper size A4 (21 x 29,7 cm). The amount of pixels is 2480 x 3508 (roughly the result of an 8 MP dSLR.
    Use the image size option in PS and be sure to not resample (meaning creating new pixels or deleting pixels to alter the original file size that is 24,9 MB). Now change the amount of pixels to whatever you like. If you increase the number the width and height decrease, and vice versa. Yet the amount of pixels and file size stay at 2480 x 3508 and 24,9 MB.
    But with the specs of wanted width and height for the end result of 300 ppi starts making sense.
    For instance you have a image at the size of a post stamp and an image at international paper size (A4) and both are 300 ppi. The small post stamp size would be in cm about 2 x 3,5 while the A4 size has about 21 x 30 cm width and height.
    So you can imagine having both needed to be printed at the A4 size in 300 dpi (printers work with dots, hence they use dpi - dots per inch- and while not the same they both often use the 300 figure and stand for pretty high quality result) the A4 sized original will meet the wanted standards without problems   while the post stamp would have to be resampled to the new A4 size and when having still 300 ppi needed there would be a lot of interpolation (creating new pixels to match the new size) and this would often result in pixelated or worse quality print result, because PS has to use guess (albeit quit educated guessing) work to add more pixels that are needed to reach the new dimensions.
    ACR has the advantage to set the ppi by default at 300 but as said, as long as you don't alter width and height of the original it is just a figure without any significant importance until you know the complete specs for the output source.

  • Converting string to color

    I have a String str = "red" . how do i convert this to Color.red .

    Hmm... I see two possibilities..
    1. You make a Hashtable with entries like this:
          hash.put ("red", Color.red);
          hash.put ("blue", Color.blue);
          //etc. etc.2. You take a look what reflect can do.. ;-)
    (java.lang.reflect)
    I'd suggest the thing with the hashtable; it's easier and faster. :)
    CUL8er,
    Nick.

  • When I print to Canon 100 Pro using Photoshop elements 12 for Mac, do not get true color as when I print straight from photo

    When I print using Macbook and Adobe Elements 12 on Canon 100Pro, do not get true color.  When I download a photo and print from the download, I get true color.  Where do I start to fix issue?  It appears to be a Photoshow issue rather than Macbook or Canon 100 Pro.

    Please post Photoshop Elements related queries over at
    http://forums.adobe.com/community/photoshop_elements

Maybe you are looking for

  • Problem with Jabber and file transfers WAN - LAN-Users - a solution!

    Hi, I read a lot of messages about problems with file transfers between iChat-Users, if one (or both) are behind a NAT. I had this problem to and found an easy solution: My situation iChat-Server behind a Netgear ProSafe FireWall. I opened the needed

  • Itunes does not sync to my ipod

    Until recently (the addition of an external Blu Ray player to my desktop computer) I could sync my older ipod touch simply by plugging into my USB.  Now, when I plug in Windows makes the "noise" that something is being plugged in but iTunes will not

  • Problems storing sql statement in database

    Hi, I'm writing an application which needs to select a sql statement from an oracle database. The statement should look something like this: "select id,name,... .from table 1 where id = " + ID + " and name = " + NAME however when I select this from t

  • Mail on iPad 2 only loads subject line

    HI,  Just switched over to the cloud and suddenly all I get on my iPad 2 is the subject line  of any incoming email message and the  name of the sender.  The body of the email does not appear.  Emails are fine on my laptop and my office computer. Any

  • Where can I found a JSP forum to add to my site?

    I want to host a forum in my website, but I don't want to write the code myself, I want to use an already existing one... Can I download one anywhere?