Contrast Strech on Planar Image

Hi all,
How to apply a simple contrast stretch algorithm on 8bit RGB PlanarImage.
Please note that, stretch is interactive. The user will specify min and max value of histogram , by moving the slider.
Edited by: java_explorer on Jul 15, 2008 9:09 PM

Hi,
For Histogramm equalization look at the
HistogramDescriptor class of JAI.
Olek

Similar Messages

  • 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?

  • Planar image conversion

    how to convert .bmp image to planar image using JAI?
    i've tried to search but i cannot find any since i have to use planar image as input to make template matching..
    tq

    See this topic: {thread:id=1518066}.
    It is mentioned (and largely ignored by the OP) that you have to specify which kind of precision loss you're ready to bear. There is a code example that scales color levels to reduce the number of bits (sounds like exactly what you're looking for).

  • 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);

  • Photosmart C309g-m, contrast & brightness on printed images

    How does one adjust brightness and contrast on printed images?
    (Std. settings produce very dark images.)
    (I have, in other situations, been disatisfied with gamma adjustment compared to "canned" brightness and contrast control.)
    Thanks,
    Jim

    Hi there jimjohnston,
    Could you provide the community with a little more information to help narrow troubleshooting? What operating system are we using and what application are we printing from?
    You can say thanks by clicking the Kudos Star in my post. If my post resolves your problem, please mark it as Accepted Solution so others can benefit too.

  • How to add "Contrast" to many layers (images) at once?

    I have a document whо contains many layer (about 2000) and I must to add "Contrast" for all of layers at once. Contrast parameter will be same for all layers. I need this method because after that i will "export layers to files" with same names.
    Thank You!

    A script seems like the best solution.
    But you could try the following:
    First, save your document, and save it again on another name (to prevent saving back the changes on the original file)
    Try the best settings for Contrast on the topmost layer.
    Once you've find the adjustment that produces the best result, Start the recording of an Action (click the new action button in the Action Panel, select a keyboard shortcut).
    Record the selection of the next layer down by hitting ALT+[.
    Replay the contrast change by holding ALT+clicking on the adjustment you made.
    Stop the recording of the action.
    Now select the two steps, and go to the Actions Panel's flyout menu, and select duplicate. Repeat this many times. Ten, twenty, maybe.
    You can now run the action, let it process a few layers, then run it again. You will divide the number of times you must do this by the number of duplications you've made.
    There might be a better method, but it's all I could think of on a Friday afternoon ;-)
    Found this: http://www.creativetuts.com/photoshop/photoshop-scripts/243-repeat-last-filter-to-all-laye rs-photoshop-script.html

  • How to convert a 2D array of pixels in to a grayscale planar image

    Im having following problems, I hope someone may help me.
    1.     I want to convert a 2D array of pixels (Grayscale values) into a Grayscale PlannerImage. I tried the following code I found on net.
    The steps to do this are:
    -Construct a DataBuffer from your data array.
    -Construct a SampleModel describing the data layout.
    -Construct a Raster from the DataBuffer and SampleModel. You can use methods from the RasterFactory class to do this.
    -Construct a ColorModel which describes your data. The factory method PlanarImage.createColorModel(sampleModel) will take care of this for some common cases.
    -Construct a TiledImage with the SampleModel and ColorModel.
    -Populate the TiledImage with your data by using the TiledImage.setData() method to copy your raster into the TiledImage.
    Only the last step involves any actual processing. The rest is just object creation.
    public static RenderedImage createRenderedImage(float[][] theData, int width, int height, int numBands) {
    int len = width * height * numBands;
    Point origin = new Point(0,0);
    // create a float sample model
    SampleModel sampleModel =
    RasterFactory.createBandedSampleModel(DataBuffer.TYPE_FLOAT,width,height,numBands);
    // create a compatible ColorModel
    ColorModel colourModel = PlanarImage.createColorModel(sampleModel);
    // create a TiledImage using the float SampleModel
    TiledImage tiledImage = new TiledImage(origin,sampleModel,width,height);
    // create a DataBuffer from the float[][] array
    DataBufferFloat dataBuffer = new DataBufferFloat(theData, len);
    // create a Raster
    Raster raster = RasterFactory.createWritableRaster(sampleModel,dataBuffer,origin);
    // set the TiledImage data to that of the Raster
    tiledImage.setData(raster);
    RenderedImageAdapter img = new RenderedImageAdapter((RenderedImage)tiledImage);
    return img;
    I passed it 2D array of pixels with 3 bands, and it gave an exception >>Array index out of bounds at this line >>tiledImage.setData(raster). Then I tried it with a 1D array of length height*width with a single band. So Now it gives me a monochromatic RenderedImage. How can I make it a grayscale PlanarImage.

    jyang, thank you very much for your response. I believe I found a different solution all together, by converting each 16-bit intensity value into an 8-bit intensity value via an intensity ratio (ie: divide each intensity by the maximum and multiply by 256). The attachment shows the new program.
    Attachments:
    mod_image.vi ‏2004 KB

  • Fast image rotation and contrast adaptation

    First: I'm new in vision processing.
    I'm using LabView 8.0 with the IMAQ Vision development module. The aim is to control the angle and the contrast of a precalculated image (a greyscale wedge) in a fast loop with a framerate of 60 or 100Hz. Currently I use the time-consuming IMAQ rotate and IMAQ BCG functions. All these function works very fine but a litle bit to slow for my application. I have measure: IMAQ rotate with 40ms and IMAQ BCG with 15ms for an image with 1024 x 768 pixels (8-bit greyscale) on a new PC. I know that an arbitrary rotation is a processor intensive task.
    Please correct me, but i assume that with IMAQ rotate the image rotation will be carried out in the PC RAM. Afterwards the recalculated image will be written in the grafic memory. In a final step the image will be displayed on the monitor by mean of the grafic processor.
    I can imagine there exist a solution or some ideas in the LabView community to use the high end 3D very fast grafic card processor for the rotation and contrast tasks. I hope the approach will accelerate the time of calculation.
    Thanks for your help.
    Best regards
    Ivo Buske

    And of course, the rambling about IMAQ image pointers isn't relevant. (Skip all IMAQ.)
    You might as well send the image once (each time it changes), and rotate it with opengl.
    "Wiebe@CARYA" <[email protected]> wrote in message news:[email protected]...
    Hi,
    If I understand correctly, you just want a gradient screen to rotate, and to be able to adjust it's contrast.
    This can be done a lot easier without an image. If you use OpenGL, you can just draw two triangles with there color set correctly. (You'd be able to make nice rainbow pictures as a bonus.)
    An C/C++ application, or dll, could be made in a few hours by someone experienced with opengl and c++. You could even create an opengl window, and control it with LabVIEW. In other opengl applications there are some practical problems, but some might not matter to your application. Biggest problem is getting feedback (mouse clicks, close, move, resize window etc.) from the OpenGL window to LabVIEW.
    Opening a opengl window, rotating a few polygons, adjusting color, closing window certainly doable.
    Regards,
    Wiebe.
    "ibstein74" <[email protected]> wrote in message news:[email protected]...
    Hi Wiebe, I have a fixed image, created before with array functions, that contain a pure linear greyscale gradient (left side: white / right side: black). I used this image to control a "spatial light modulator". This device is connected to the second DVI graphic card output. The main task of the "spatial light modulator" is to shift the local phase of the reflective light. It works as an spatial resolved "adaptive mirror".&nbsp; The local phase shift correspondes directly to the applied grey level of the image. To change the direction in both dimensions of the reflective light I need to rotate this image (= rotate the phase wedge) Thereby the contrast can adjust the absolute angle of reflection.After I had calculated my greyscale gradient image and applied it to the second DVI output, I want only control the contrast and rotation. I think the graphic card function are very fast. But I have to control the graphic card directly per DLL or C-function node. It must be possible because I can tune the contrast and adjust the rotation manually with the nvidea driver in the windows system manager. I'm&nbsp; waiting for a couple of weeks of an answer from nvidea but it seems that contrast and rotation of an 2D-image is not a real problem for these 3-D guys. :-(I hope of an answer or new ideas.Ivo Buske

  • 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 processing from .txt file onto an intensity graph

    I am doing a mini project in my class and I was wondering if anyone could help me. It about image processing but I am bit stuck.
    Heres the idea:
    "An image is really nothing more than a 2D array of data. The value of every element in the array corresponds to the brightness of the image at that point.
    In this project you will create a VI which loads a 2D array of data and then displays it on the screen using the Intensity Graph. Three example files (boats.txt, gordon.txt and parrot.txt) are available on the module webpage that you can use. However, you can also use any other black and white image you like, but will need to convert it to a “text image” first. To do this you can use some software called “ImageJ” which is available on the computers and is free to download.
    You can vary the brightness of an image by adding the same value to every element in the array.
    The contrast of an image is adjusted by multiplying every element in the array by the same value. Using numerical controls and simple array mathematics, you should adjust the brightness and contrast of your displayed image.
    Some other ideas that you could try with image manipulation are:
    o Invert an image (change black to white and white to black)"
    First I am having problems putting my picture onto the graph. It is in the write file but the colours are not correct and the image has rotated 90 degrees. I will upload my VI so far when I get back onto my computer.
    Would really appricate the help! Thank you for reading

    Hi charlthedancer,
    Here is an example to get you started.
    Kind regards,
    GajanS
    Attachments:
    Test.vi ‏14 KB

  • Image Processing Performance Issue | JAI

    I am processing TIFF images to generate several JPG files out of it after applying image processing on it.
    Following are the transformations applied:
    1. Read TIFF image from disk. The tiff is available in form of a PlanarImage object
    2. Scaling
         /* Following is the code snippet */
         PlanarImage origImg;
         ParameterBlock pb = new ParameterBlock();
         pb.addSource(origImg);
         pb.add(scaleX);
         pb.add(scaleY);
         pb.add(0.0f);
         pb.add(0.0f);
         pb.add(Interpolation.getInstance(Interpolation.INTERP_BILINEAR));
         PlanarImage scaledImage = JAI.create("scale", pb);3. Convertion of planar image to buffered image. This operation is done because we need a buffered image.
         /* Following is the code snippet used */
         bufferedImage = planarImage.getAsBufferedImage();4. Cropping
         /* Following is the code snippet used */
         bufferedImage = bufferedImage.getSubimage(artcleX, artcleY, 302, 70);The performance bottle neck in the above algorithm is step 3 where we convert the planar image to buffered image before carrying out cropping.
    The operation typically takes about 1120ms to complete and considering the data set I am dealing with this is a very expensive operation. Is there an
    alternate to the above mentioned approach?
    I presume if I can carry out the operation mentioned under step 4 above on a planr image object instead of buffered image, I will be able to save
    considerable processing time as in this case step 3 won't be required. (and that seems like the bottle neck). I have also noticed that the processing
    time of the operation mentioned in step 3 above is proportional to the size of the planar image object.
    Any pointers around this would be appreciated.
    Thanks,
    Anurag
    Edited by: anurag.kapur on Oct 4, 2007 10:17 PM
    Edited by: anurag.kapur on Oct 4, 2007 10:17 PM

    It depends on whether you want to display the data or not.
    PlanarImage (the subclass of all renderedOps) has a method that returns a Graphics object you can use to draw on the image. This allows you to do this like write on an image.
    PlanarImage also has a getAsBufferedImage that will return a copy of the data in a format that can be used to write to Graphics objects. This is used for simply drawing processed images to a display.
    There is also a widget called ImageCanvas (and ScrollingImagePanel) shipped with JAI (although it is not a committed part of the API). These derive from awt.Canvas/Panel and know how to render RenderedImage instances. This may use less copying/memory then getting the data as a BufferedImage and drawing it via a Graphics Object. I can't say for sure though as I have never used them.
    Another way may be to extend JComponent (or another class) and customize it to use calls to PlanarImage/RenderedOp instances directly. This can hep with large tiled images when you only want to display a small portion.
    matfud

  • How can I merge two TIFF images in one...?

    I need some help please, I am looking for a way to "resize" black & white single TIFF images.
    The process I need to do is like cutting a small image and paste it over a new blank letter-size image (at 300 dpi), like a template.
    Or better yet, is there a way to do something like this...?
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();Some APIs and topics in the internet do or talk about resizing, but the final images get stretched or shrinked and I need them not to do so at all.
    Also, I do not need to display the images, only to get the TIFF images processed and saved back to a file.
    How can I do this with Java and JAI? Unfortunately I am almost new to this and I don't know how difficult it might be to deal with images.

    If 2550 x 3300 isn't the original aspect ratio of the image, then the image is going to looked streched or shrinked in at least one dimension. There is no way around that. It would be like resizing a 2 pixel by 2 pixel image into a 3 pixel by 6 pixel image. The image would look like it's height shrunk or it's width stretched. Had I resized it to 3 pixels by 3 pixels or 6 pixels by 6 pixels, though, then it wouldn't look shrunken or streched.
    Open image...
    image.*width* = 2550;
    image.*height* = 3300;
    image.save();*1)* To open a TIFF image you can use the javax.swing.ImageIO class. It has these static methods
    read(File input)
    read(ImageInputStream stream)
    read(InputStream input)
    read(URL input) You can use which ever method you want. But first you need to install [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html]. The default ImageReaders that plug themselves into the ImageIO package are BMP, PNG, GIF, and JPEG. JAI-ImageIO will add TIFF, and a few other formats.
    The downside is that if clients want to you use your program on their machine then they to will need to install JAI-ImageIO to read the tiffs. To get around this, you can go to your Java/jdk1.x.x_xx/jre/lib/ext/ folder and copy the jai_imageio.jar file (after you've installed JAI-ImageIO). You can also obtain this jar from any one of the zip files of the [daily builds|https://jai-imageio.dev.java.net/binary-builds.html#Daily_builds]. If you add this jar to your program's classpath and package it together with your program, then clients won't need to install JAI-ImageIO and you'll still be able to read TIFF's. The downside of simply adding the jar to the classpath is that you won't be able to take advantage of a natively accelerated JPEG reader that comes with installing JAI-ImageIO (instead, ImageIO will use the default one).
    *2)* Once you've installed [JAI-ImageIO|https://jai-imageio.dev.java.net/binary-builds.html] and used ImageIO.read(...), you'll have a BufferedImage. To resize it you can do the following
    BufferedImage newImage = new BufferedImage(2550,3300,BufferedImage.TYPE_BYTE_BINARY);
    Graphics2D g = newImage.createGraphics();
    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
    g.drawImage(oldImage,0,0,2550,3300,null);
    g.dispose();Here, I simply drew the old image (the one returned by ImageIO.read(...)) onto a new BufferedImage object of the appropriate size. Because you said they were black and white TIFF's, I used BufferedImage.TYPE_BYTE_BINARY, which is a black and white image. If you decide to use one the BufferedImage types that support color, then a 2550x3330 image would require at least 25 megabytes to hold into memory. On the other hand, a binary image of that size will only take up about one meg.
    I specified on the graphics object that I wanted Bilinear Interpolation when scaling. The default is Nearest Neighbor interpolation, which while fast, dosen't look very good. Bilinear offers pretty good results scaling both up or down at fast speeds. Bicubic interpolation is the next step up. If you find the resized image to be subpar, then come back and post. There are a couple of other ways to resize an image.
    Note, however, if 2550 x 3300 is not the same aspect ratio as the the TIFF image you loaded, then the resized image will look shrunk or stretched along one dimension. There is absolutely no way around this no matter what resizing technique you use. You'll need an image whose original dimensions are in a 2550/3300 = .772 ratio if you want the resized image to not look like it's streched (you can crop the opened image if you want).
    *3)* Now we save the "newImage" with the same class we read images with: ImageIO . It has these static methods
    write(RenderedImage im, String formatName, File output)
    write(RenderedImage im, String formatName, ImageOutputStream output)
    write(RenderedImage im, String formatName, OutputStream output)You'll suply the resized BufferedImage as the first parameter, "tiff" as the second parameter and an appropriate output for the third parameter. It's pretty much a one line statement to read or write an image. All in all, the whole thing is about 7 lines of code. Not bad of all.
    Now as for the 300 dpi thing, there is a way to set the dpi in the Image's metadata. I'm pretty good at reading an image's metadata, but I've never really tried writing out my own metadata. I know you can set the dpi, and I have a somewhat vague idea how it might be done, but it's not something I've tried before. I think I'll look more into it.

  • Quick, easy ways to make images look better?

    What are the best ways to make images look a bit better? I shot my footage using a pretty bad camera, so quality already isn't the greatest, but what is the best way to make images look a bit more "movie-like"? The 3way color correstion is nothing for me, it's too hard to make images look good, they'll quickly turn too yellow or red, etc... Something to improve contrast maybe? Using Image Control: Brightness and contrast (bezier) doesn't seem to help much.

    Okay, I took a couple of screenshots:
    http://www.majhost.com/gallery/TheDarkBrickX/Random/film/afbeelding_1.png
    http://www.majhost.com/gallery/TheDarkBrickX/Random/film/afbeelding_2.png
    http://www.majhost.com/gallery/TheDarkBrickX/Random/film/afbeelding_3.png
    http://www.majhost.com/gallery/TheDarkBrickX/Random/film/afbeelding_4.png
    Now I don't know alot about image quality or color, but I think there is not enough contrast? It all looks very cold. Luckily, image quality isn't the most important thing in this project, but it would be nice to be able to touch it up a little bit.

  • 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.

  • Image quality degrades in published swf

    I've built a Flash site for a freind who is a photographer.
    There are over 100 images on the site that are imported jpegs. Most
    of them look fine but two of them look very washed out when I
    publish my swf even though in the Flash project file they have very
    sharp contrast. These particular images are monochromatic. Is there
    anyway to preserve the variation of tones in the published swf?
    I've tried using them at maximum image quality, but had the
    same result.
    Any suggestions would be greatly apreciated.

    I tried saving as a png, but I got the same result. It's like
    my black becomes a dark grey and my midtones go light/
    white.

Maybe you are looking for