Brightness/Contrast of an indexed image

Hi all,
Is it possible to change the Brightness/Contrast of an indexed image?
I've tried that with the following code:
// Brighten the image by 30%
float scaleFactor = 1.3f;
RescaleOp op = new RescaleOp(scaleFactor, 0, null);
bufferedIm = op.filter(bufferedIm, null);but it outputs:
java.lang.IllegalArgumentException: Rescaling cannot be performed on an indexed imageThanks in advance

Just roll your own: get the color components of the IndexColorModel, rescale them, build a new
IndexColorModel from that and put that together with the original WriteableRaster to form the
rescaled BufferedImage:
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.net.*;
import javax.imageio.*;
import javax.swing.*;
public class RescalingICMExample {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://weblogs.java.net/jag/bio/JagHeadshot-small.jpg");
        BufferedImage original = ImageIO.read(url);
        BufferedImage index = convertType(original, BufferedImage.TYPE_BYTE_INDEXED);
        JPanel p = new JPanel(new GridLayout(2,4));
        addToPanel(p, original, "original image");
        addToPanel(p, index, "indexed version");
        float[] scales = {1f, 1.1f, 1.2f, 1.3f, 1.3f, 1.3f};
        float[] offsets = {48, 32, 16, 0, 16, 32};
        for(int i=0; i<scales.length; ++i) {
            float s = scales;
float o = offsets[i];
addToPanel(p, rescale(index, s, o), "scale=" + s + ", offset="+o);
JFrame f = new JFrame("");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
public static BufferedImage convertType(BufferedImage image, int type) {
if (image.getType() == type)
return image;
BufferedImage result = new BufferedImage(image.getWidth(), image.getHeight(), type);
Graphics2D g = result.createGraphics();
g.drawRenderedImage(image, null);
g.dispose();
return result;
static void addToPanel(JPanel p, BufferedImage image, String title) {
JLabel label = new JLabel(new ImageIcon(image));
label.setBorder(BorderFactory.createTitledBorder(title));
p.add(label);
public static IndexColorModel rescale(IndexColorModel icm, float scaleFactor, float offset) {
int size = icm.getMapSize();
byte[] reds=new byte[size], greens=new byte[size], blues=new byte[size], alphas=new byte[size];
icm.getReds(reds);
icm.getGreens(greens);
icm.getBlues(blues);
icm.getAlphas(alphas);
rescale(reds, scaleFactor, offset);
rescale(greens, scaleFactor, offset);
rescale(blues, scaleFactor, offset);
return new IndexColorModel(8, size, reds, greens, blues, alphas);
public static void rescale(byte[] comps, float scaleFactor, float offset) {
for(int i=0; i<comps.length; ++i) {
int comp = 0xff & comps[i];
int newComp = Math.round(comp*scaleFactor+offset);
if (newComp < 0)
newComp = 0;
else if (newComp > 255)
newComp = 255;
comps[i] = (byte) newComp;
public static BufferedImage rescale(BufferedImage indexed, float scaleFactor, float offset) {
IndexColorModel icm = (IndexColorModel) indexed.getColorModel();
return new BufferedImage(rescale(icm, scaleFactor, offset), indexed.getRaster(), false, null);

Similar Messages

  • Brightness/Contrast issue

    when I add the brightness/contrast filter to my footage and adjust it-the picture looks normal,until I render, in which case I get flickering multi-colored frames. I'm editing prores422HQ footage at 23.98fps. The timeline is set to the correct setting, and I've tried different render settings with no luck. Any help would be appreciated...

    In support of Jim, (and I don't know what camera you are using when I say this). But pro gear, tends to record in a bigger colour space (higher colour resolution 4.2.2) therefore when adjusting (using FCP filters for example) there's greater latitude to tolerate the adjustments. In my early days of single chip, just a few minor tweaks in brightness contrast can have the image fall off really dramatically, so you do need to get the image right when you record it i.e. even a single chip will record a great image when lit well, but under-lit, it's very difficult to make adjustments using FCP filters.

  • Photoshop Levels/Brightness & Contrast Problem (PS CS2)

    When I try to apply Levels & or Brightness & Contrast settings to an image, it always seems to revert back to the way it was. The filters won't do anything it seems. I have Adobe Photoshop CS2. At home it did the same thing and I re-installed Photoshop only to find out it still did not work. Is there something I am forgetting to do? Your help will be much appreciated!!!
    Eric

    View your image at 100% (Actual Pixels) when making adjustments.
    (And I'm going to take a wild guess that you are working on a line drawing or scanned half-tone image.)

  • How to Change Brightness, Contrast and Saturation of an image in LabWindows/CVI (Urgent) ?

    Hi All
    I want to change brightness, contrast and saturation of an image, plz help me how it will possibe in labwindows/cvi
    Thanks

    CVI does not include native functions to operate such changements on an image.
    It may be possible that these functions are included in IMAQ library, but I never used ot so I'm not sure. In any case, this is an additional tool to install and it is not free.
    Alternatively, you may need to search for a third party library that offers such functions.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Change Brightness, Contrast and Saturation of an image

    Hi,
    I have an 256 grey level image and I'd like to change the brightness,
    contrast and saturation.
    Does it exist a VI to do this?
    If someone has an example, please send to me.
    Thanks in advance,
    Miguel.

    Robert,
    ¿Where is the example? In ftp://ftp.ni.com or in http://www.ni.com?
    Thanks,
    Miguel.
    Robert Currie escribió en el mensaje de noticias
    #35p1dFA$GA.285@cpmsnbbsa03...
    > Try the example VI by NI.
    >
    > It should be located in the following folder:
    > Labview/Examples/Vision/Imaq_ex2.llb
    >
    > Then choose the Brightness/Contrast example.
    >
    > If you don't/can't find it let me know and I'll send the library.
    >
    > Robert
    >
    >
    >
    > Miguel wrote in message <[email protected]>...
    > >Hi,
    > >
    > >I have an 256 grey level image and I'd like to change the brightness,
    > >contrast and saturation.
    > >
    > >Does it exist a VI to do this?
    > >
    > >If someone has an example, please send to me.
    > >
    > >Thanks in advance,
    > >
    > >Miguel.
    > >
    >
    >

  • When i place my photo, the adjustments tab does not pop up, and even when i click image at the top, I cannot select any adjustments-brightness/contrast,hue-saturation, color blance, etc..Anyone know what I am doing wrong?

    When i place my photo, the adjustments tab does not pop up, and even when i click image at the top, I cannot select any adjustments-brightness/contrast,hue-saturation, color blance, etc..Anyone know what I am doing wrong?

    Good day!
    What is "place" supposed to mean – open, place as Smart Object, …?
    What are the image’s Color Mode and bit depth?
    Could you please post a screenshot with the pertinent Panels visible?
    Does Window > Adjustments not raise the Adjustments Panel?
    Regards,
    Pfaffenbichler

  • Unsigned 16-Bit Image Brightness Contrast

    Hello, Everyone
    I have Unsigned 16-Bit Image , I want to change the brightness & Contrast of this Image.
    I dont found any VI in LabVIEW to do that with this format (there is BCG but only for 8-Bit).
    I found this link for that issue:Adjusting Brightness and Contrast for 16-Bit Image
    So, I used the Operators function to do that. but i dont know if  the order of that functions is sensitive or NOT. see Picture
    and did i realy need to use Subtract operators and Divide operators .
    Best wishes
    Alzhrani

    Hi Al-Zahrani,
    I don't believe that it matters whether you do brightness or contrast first. You can verify this by looking at a picture using both methods you showed below. However, when I did this, I did not see much of a difference and believe that you can place either brightness or contrast first. Also, you will need to include the math functions in order to perform the image processing you are trying to do. Hope this helps!
    Mychal F
    Applications Engineer
    National Instruments

  • Image / Adjustments: Brightness/Contrast. Why is it crap now?

    Ever since we got CS3, I have to hit the "Legacy" button in the Brightness/Contrast to get decent results. I just tried again WITHOUT using the Legacy button to enhance a scan a little. I brightened it up a few notches and then dragged the contrast bar and NOTHING happened. Whats that about? I hit the Legacy button and do my adjustments and it works as it should. Am I missing something?

    TwitchOSX wrote:
    Curves and Levels arent that hard to screw with. I just prefer not to
    use them. Besides, I don't really do anything that requires the use of
    tools like that, so it's a non-issue for me.
    TwitchOSX wrote:
    Well, I guess I'm an amateur.
    The emphasized sentences go well together; TwitchOSX wrote them, not I.
    TwitchOSX wrote:
    Damn my 14 years of photoshop experience!
    Fourteen years of deliberately ignoring the most basic Photoshop tools!?    Maybe TwitchOSX doesn't even need Photoshop. 

  • How can I apply Brightness​, Contrast, Saturation​, etc on an color Image or Picture?

    I am using IMAQ to open an existing color jpeg file, and perform operations on it. I would like to be able to change the brightness, contrast, saturation, etc. similarly to what can be done to an IMAQ Session via a property node. I've seen examples for grayscale, but not for color? Anyone have ideas / examples?
    Thanks,
    Tim

    I found it -- IMAQ ColorBCGLookup.vi if others are interested.

  • Adjusting contrast on grayscale pdf image

    On Photoshop 6.0 I was able to adjust the contrast of a grayscale pdf image by going to image-adjustments-brightness/contrast,increasing the contrast, hitting ok. I could then save the image file. I just obtained Photoshop CS3 and things do not work that way. I do not see any change when I increase the contrast. However, I see an increase in contrast when I lower the brightness, but when I click ok, the contrast goes back to where it was.
    How do I increase the contrast and save the image?

    I'm sure I've asked this before, but why don't you use code tags?

  • Brightness Contrast filter won't stop flickering

    My Brightness & Contrast filter is acting crazy. Most of the time, it works fine, but sometimes changes suddenly. Right in the middle of the clip, it will change brightness. Sometimes, it happens in brief flashes, sometimes constant, and other times, it rapidly flickers. This is only happening to certain clips, at complete random. Why is it doing this?
    If anybody knows how I can stop this, please help.
    Powermac G4   Mac OS X (10.3.9)   using FCP 4.5

    Tried trashing renders. still can't figure it out.
    It seems to happen on both the external monitor and the clip itself. Tried exporting into new quicktime movies, also as still image sequences and the flicker still happens to these certain clips when the contrast filter is applied. Seems to be embedded in the footage itself, but doesn't happen when there's no filter.

  • BCG Brightness Contrast Gamma - Looking for BCG function returning color table / lookup table coded in pure G and applicable to Intensity Graph or Picture Control

    Looking for BCG function returning color table / lookup table coded in
    pure G and applicable to 8-bit Intensity Graph or Picture Control. Do
    not want to use IMAQ Vision is this particular application.  Any
    help is appreciated.
    Sincerely,
    Don

    Take a look at this color model software I put together.  (Don't concern yourself much with the basic programming at this point.). The color component generator subVI is borrowed from a LabVIEW example.
    First look at test_color2.vi.  If you adjust the sliders of the various controls, you will see how it works.  You can see that for pure B&W images, brightness, contrast, and gamma (which I think I have coded correctly) are all fairly straightforward to modify.
    Now look at test_color3.vi.  Here we try to adjust BCG for color images using the color model shown here where current color component clusters are carried into the BCG event cases via shift registers.  You can see that once color is introduced into the image, it becomes difficult to mix the colorizing with the BCG model.  And this is pretty much where I am right now.
    Would be interested in comments / suggestions.
    Sincerely,
    Don
    Attachments:
    test_color2.llb ‏2251 KB

  • Exposure vs. Levels vs. Brightness/Contrast Adjustment Layers?

    I have some photos that are a bit underexposed and I'm trying to brighten them up a bit and I made a Levels adjustment layer and also experimented with the Exposure adjustment layer. Are these essentially doing the same thing OR are there reasons to have a Levels adjustment layer along with an exposure one and a Brightness/Contrast one?
    Thanks in advance.

    The Exposure adjustment in Photoshop is primarily meant to correct tonal values of High Dynamic Range images, which are 32 bits. This command makes tonal adjustments using a linear color space or gamma instead of your image’s color space.  You can use it on 8 bit or 16 bit images too, but the adjustments may seem rather drastic.
    When rescuing poorly exposed 8 bit or 16 bit images, I prefer Levels or Curves because you have greater control.  Brightness/Contrast, isn't something I use much.
    Nancy O.

  • Strange Artifacts with Brightness/Contrast Filter

    I've applied the brightness/contrast filter to several stills and then on the last 6 frames, I pump the brightness to 100 to create a flash transition. However, on several of these, I'm getting very strange black artifacts after rendering. They appear on the edges of the frame.
    They're not there before rendering, so it's not because that's what the image is supposed to look like at 100 brightness.
    Has anyone ever experienced this or have any ideas how to fix it?
    Thanks!
    Cameron

    Interesting development. I got a different transition from Eureka! plugins that's basically the same as the Buena one except it doesn't crash my system. Rendered it, and lo and behold! Same problem. The same kind of artifacts show up on the edges. The problem with cropping it is that then I just have to re-render and the artifacts come up again.
    Any ideas?
    Thanks!
    Cameron

  • Looking for the brighter red pixel of an image

    Hi, I need to find the brighter red pixel of an image. I tried this code, but the value of each pixel seemed to be the same (zero).
    public static void findBrighterRedPoint(Image i, ImageObserver o){
         int redMax = 0; //0 to 255
         int xMax = 0;
         int yMax = 0;
         PixelGrabber pg = new PixelGrabber(i,0,0,i.getWidth(o),i.getHeight(o),true);
         ColorModel cm = pg.getColorModel();
         for(int a=0;a<pg.getHeight();a++){
              for(int c=0;c<pg.getWidth();c++){
                   if(cm.getRed(((a-1)*pg.getWidth()+c)) > redMax){
                        redMax = cm.getRed(((a-1)*pg.getWidth()+c));
                        xMax=c;
                        yMax=a;
                   if(f==(pg.getHeight()-1) && c==(pg.getWidth()-1)){
                   System.out.println("Red bound max value: "+cm.getRed(((a-1)*pg.getWidth()+c))+" Arrow: "+a+" Collumn: "+c);
    }//method endThanks for some help...
    Edited by: juanma268 on Jul 25, 2008 5:45 PM

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import javax.swing.*;
    public class LookingForRed extends MouseMotionAdapter {
        JLabel red, green, blue;
        BufferedImage image;
        public void mouseMoved(MouseEvent e) {
            Point p = e.getPoint();
            int rgb = image.getRGB(p.x, p.y);
            red.setText(String.valueOf(  (rgb >> 16)&0xff));
            green.setText(String.valueOf((rgb >>  8)&0xff));
            blue.setText(String.valueOf( (rgb >>  0)&0xff));
        public static void findBrighterRedPoint(Image i, ImageObserver o){
            int redMax = 0; //0 to 255
            int xMax = 0;
            int yMax = 0;
            int w = i.getWidth(o);
            int h = i.getHeight(o);
            int[] pixels = new int[w*h];
            PixelGrabber pg = new PixelGrabber(i,0,0,w,h,pixels,0,w);
            try {
                pg.grabPixels();
            } catch(InterruptedException e) {
                System.out.println("interrupt");
            ColorModel cm = pg.getColorModel();
            for(int a=0;a<pg.getHeight();a++){
                for(int c=0;c<pg.getWidth();c++){
                    int index = a*pg.getWidth()+c;
                    int pixel = pixels[index];
                    if(cm.getRed(pixel) > redMax){
                        redMax = cm.getRed(pixel);
                        xMax=c;
                        yMax=a;
                    if(a==(pg.getHeight()-1) && c==(pg.getWidth()-1)){
                        System.out.println("Red bound max value: "+redMax+
                                   " Arrow: "+yMax+" Collumn: "+xMax);
        private void showGUI(BufferedImage image) {
            this.image = image;
            ImageIcon icon = new ImageIcon(image);
            JLabel label = new JLabel(icon, JLabel.CENTER);
            label.addMouseMotionListener(this);
            JPanel panel = new JPanel(new GridBagLayout());
            panel.add(label, new GridBagConstraints());
            JFrame f = new JFrame();
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.add(panel);
            f.add(getLabelPanel(), "Last");
            f.setSize(300,300);
            f.setLocation(200,200);
            f.setVisible(true);
            findBrighterRedPoint(image, label);
        private JPanel getLabelPanel() {
            red = new JLabel();
            green = new JLabel();
            blue = new JLabel();
            Dimension d = new Dimension(45, 25);
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            addComponents("r =", red,   panel, gbc, d);
            addComponents("g =", green, panel, gbc, d);
            addComponents("b =", blue,  panel, gbc, d);
            return panel;
        private void addComponents(String s, JLabel jl, Container c,
                                   GridBagConstraints gbc, Dimension d) {
            gbc.anchor = GridBagConstraints.EAST;
            c.add(new JLabel(s), gbc);
            jl.setPreferredSize(d);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(jl, gbc);
        public static void main(String[] args) {
            LookingForRed test = new LookingForRed();
            BufferedImage image = test.makeImage();
            test.showGUI(image);
        private BufferedImage makeImage() {
            int w = 200, h = 200;
            int type = BufferedImage.TYPE_INT_RGB;
            BufferedImage image = new BufferedImage(w, h, type);
            int[] data = new int[w*h];
            int x = 3*w/4;
            int y = 3*h/4;
            System.out.println("Max red value should appear at " +
                               "x = " + x + "  y = " + y);
            int a = 255;
            for(int j = 0; j < h; j++) {
                int b = j*255/(h-1);
                for(int k = 0; k < w; k++) {
                    int r = (j == y && k == x) ? 255 : 127;
                    int g = k*255/(w-1);
                    data[j*w + k] = ((a & 0xff) << 24) |
                                    ((r & 0xff) << 16) |
                                    ((g & 0xff) <<  8) |
                                    ((b & 0xff) <<  0);
            image.setRGB(0,0,w,h,data,0,w);
            return image;
    }

Maybe you are looking for