Reading pixels of image

Hello
I need to know what I must to use as methods and packages in order to extracte the exact informations means the exact value of pixels from the image with gray scale and image with colors RGB.

Here's how to read one pixel from an image:
  public int getOnePixel(BufferedImage bi, int x, int y)
    // Get one pixel.
    if (bi != null)
      return bi.getRGB(x, y);
    else
      System.out.println("BufferedImage is null");
      return -1;
  }Here's how to create an image from a set of pixels:
  public BufferedImage createBufferedImage(int w, int h, int [] pixels)
    BufferedImage bi = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);
    WritableRaster wr = bi.getRaster();
    wr.setPixels(0,0,w,h,pixels);
    return bi;
  }Hope that helps. If you need more help, email me at [email protected]

Similar Messages

  • Read Pixel in image

    Hi, could anyone help me, i'm really upset in here..
    i try to read every pixel in my image, but what i got some number like this (-946523, -964323, and so on...) this is hexa right? and then i read some article, i got the answer like this :
    int pixel = -946523 & 0xff, what does it means?
    how can -946523 become 165?? i understand that 165 is the value of the pixel, right? but how can? how about the process? can anyone explain to me...
    Thanks a lot...

    Hi, could anyone help me, i'm really upset in here..
    i try to read every pixel in my image, but what i got
    some number like this (-946523, -964323, and so
    on...) this is hexa right? and then i read some
    article, i got the answer like this :
    int pixel = -946523 & 0xff, what does it
    means?
    how can -946523 become 165?? i understand that 165 is
    the value of the pixel, right? but how can? how about
    the process? can anyone explain to me...Pixels stored as integers have the following format:
    ARGB
    One byte of alpha information, a byte for red, a byte for green and a byte for blue.
    The byte represent a value from 0 to 255, where 0 means none of the component is present, and 255 means the full amount is present. For a fully opaque pixel (no tranparency), alpha is 255, which in hex is 0xFF. An integer in Java is a 32 bit signed value. The sign is carried in the high order bit. So, if you have a pixel packed as 4 bytes in an integer, and the pixel has an alpha value of 0xFF, the high order bit of the integer will alway be set, and the integer will be negative.
    A pixel value of -946523 in hex is 0xFFF18EA5. so, the pixel has an alpha value of 0xFF or 255, a red component of 0xF1 or 241; a blue component of 0x8E or 142; and a blue component of 0xA5 or 165.
    Your pixel in binary looks like this:
    1 1 1 1 1 1 1 1     1 1 1 1 0 0 0 1     1 0 0 0 1 1 1 0     1 0 1 0 0 1 0 1 
    ALPHA 24-31       RED  16-23          GREEN 8-15        BLUE 0-7So, say you want to get the alpha value, which is stored in the highest 8 bits, or bits 24 through 31. First, you need to shift those bits to the right until they are in the lowest 8 bits (0-7). This is done with the shift operator (>>).
    int pixel = -964323;
    int aShift = pixel >> 24;After this operation, the integer now looks like this:
    1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 1
    Note that when you shift right in Java, the empty bits to the left are filled with ones. This is called sign extension, and it is a problem for us, because we want all zeros in the left bits, leaving just the alpha component bits unchanged. To do this, you mask, which is done use the AND operator (&). This operator takes two numbers and compares each bit. If the bits are both 1, a 1 is placed in the result, otherwise a zero is placed in the result. So, if we take the shifted integer above and mask it with 0xFF, it looks like this:
    1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 (shifted integer)
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 (mask 0xFF)
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 (result)
    The result is 0xFF, which is 255, which is the correct value for alpha.
    In code, this looks like:
    int a = aShift & 0xFF;This can all be done in one line as follows:
    int a = (pixel >> 24) & 0xFF;For the red component, we first shift 16 bits to the right, which gives us
    1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 1     1 1 1 1 1 1 1 1     1 1 1 1 0 0 0 1  Once again, you mask with 0xFF and the result is:
    0 0 0 0 0 0 0 0     0 0 0 0 0 0 0 0      0 0 0 0 0 0 0 0      1 1 1 1 0 0 0 1which is 0xF1, or 241.
    In code:
    int r = (pixel >> 16) & 0xFF;Green is handled the same way, with a shift of 8 bits:
    int g = (pixel >> 8) & 0xFF;Blue is next, but what should be used for the shift value? Alpha was 24, red was 16, greeb was 8, which indicates that blue should be zero. In fact, if you use zero you will get the correct answer:
    int b = (pixel >> 0) & 0xFFbut not that the shift with 0 really doesn't do anything, so you can just use the mask, and get the right answer:
    1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 1 1 0 0 0 1 1 1 0 1 0 1 0 0 1 0 1 (pixel)
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 (mask)
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 (result)
    So, the blue pixel is 0xA5, or 165.
    In summary:
    int pixel = -964323;
    int a = (pixel >> 24) & 0xFF;
    int r = (pixel >> 16) & 0xFF;
    int g = (pixel >> 8) & 0xFF;
    int b = pixel & 0xFF;Jim S.

  • Questions on reading in JPEG2000 Images

    I am currently having an issue reading in jpeg2000 images. The issue is that I cannot find a way to extract metadata that is in the file and also extracting an area of interest in the image is painfully slow. i tried doing a ImageReader.getImageMetadata() but it doesn't return anything useful that i was looking for in the metadata portion. Below is a snippet of the a dummy code i put together. Its intention is to read a 10x10 block starting in the 0,0 location. This code is painfully slow. Am i doing something wrong? Error handling is left for now.
    J2KImageReader j2kImageReader = (J2KImageReader) ImageIO
    .getImageReadersByFormatName(
    "jpeg2000").next();
    j2kImageReader.setInput(new FileImageInputStream(new File(p_fileLocation)));
    ImageReadParam imageReadParam = j2kImageReader.getDefaultReadParam();
    imageReadParam.setSourceRegion(new Rectangle(0, 0, 10, 10));
    IIOImage image = j2kImageReader.readAll(0, imageReadParam);

    Also i forgot to mentioned that the above code looks like it is scanning and reading in all the pixels and returning the ones that i specified in the ImageReadParam class

  • How can a 200 pixels/cm image result in a 118 pixels/inch PDF?

    Hi all,
    Just encountered a problem that is a bit puzzling me.
    If you create a 1cm by 1cm image in Photoshop, with a resolution of 200 pixels/cm (= 508 pixels/inch), and you save this image to PDF, using for instance the PDF/X-1a presets or one of the Ghent PDF Workgroup PDF presets, the image will be downsampled to 118 pixels/inch (or 47 pixels/cm). This does not compute. When checking the PDF-settings, I would suspect the image would be downsampled to 118 pixels/cm (or appr. 300ppi), as you would believe from the PDF-settings, but not to 47pixels/cm or 118 pixels/inch.
    Is seems to me that Photoshop is taking the value (the '118') for the downsampling, but without translating my pixels/cm to pixels/inch first (it just downsamples 200 pixels/cm to 118 pixels/inch), which doesn’t seem very correct to me.
    This is a huge problem. If people would accidently use pixels/cm to set their image size, they will end up with a PDF that is not printable and will be rejected by most printing companies because of too low image resolution. I tried to do the same with Adobe Photoshop CS3, but the same problem.
    Anyone that can help me try to understand the logic behind this? Below the downsamping settings that would make me believe that I would end up with a 118 pixels/cm image instead of 118ppi and some other screenshots to clarify the issue.
    Original image resolution in Photoshop
    Image resolution (or preflight error) after saving to PDF

    Because it is only 118 ppi or 47pp/cm. Remember: the original image was 1cm wide and had a resolution of 200 pp/cm. The resulting PDF contains only 47 pixels for the entire width (the entire 1cm), so: 47pixels x 1cm or 2,54 inches = 47 pp/cm or 118 pixels/inch. It looks like there were really thrown away too many pixels during downsampling (calculation error in the PDF presets downsampling algorithm).
    Actual number of pixels in the PDF (dimension: 1cm x 1cm):

  • Avoiding pixelation with image resizing

    i just redesigned my site (with a ton of help from many people on this forum--thank you nancy riki osgood
    Sudarshan!!)
    i have my thumbnails resizing (using max width: 100%) in a gallery but on a large browser window like my 32" monitor they get pixelated when they scale up, particularly the text..
    is there  a way to start with a higher resolution image and display them at a smaller display size so when they scale up they stay crisp?
    http://toddheymandirector.com/
    go to REEL, MORE and NEWS
    thanks..

    Hello mate, Welcome back!
    Ideally, I wouldn't do a 100% width for your images on the site for enlarging them. No matter what plug-in you use, you'll definitely end up pixelating the image at least to some extent.
    However, if you're definitely looking at achieving this, try this: http://archive.plugins.jquery.com/project/aeImageResize
    And, start with a higher resolution of the image. The plug-in will scale it down proportionately depending on the screen dimension you're displaying it on, rather the DIV dimension that holds the image inside.
    Also, it is to be noted that usage of multiple jQuery will lead to a performance issue on your site. You should keep this in mind.
    One last thing: having said that you should start with a higher image resolution, your load time for the site will considerably increase as the plug-in only scales down the image visually, it doesn't load differently sized images!
    If I were you, I'll keep the thumbnail images to zoom in to one optimal size and then provide a link inside my fancybox/ lightbox to a much fuller, bigger size image - if someone is interested in seeing them/ downloading the big size image.

  • Is it possible to read pixels of gif in java

    Does anyone know about gif files and reading them?
    If you have a gif file and there are blue dots on the gif file. What do you do to check to see if a pixel is a certain color/attribute, ie blue... ? Please give code only - many other posts are general and obvious -. No acme.

    Load the Image with Toolkit and MediaTracker,
    create BufferedImage: BufferedImage image = new BufferedImage(loadedImage.getWidth(null),loadedImage.getHeight(null), BufferedImage.TYPE_...);
    Then get the image's Raster: Raster raster = image.getRaster();
    Now read pixels: raster.getPixel(x,y, intArray)
    where intArray is to receive the sample values of the pixel (with ARGB 4 values ...)
    Look at Core Java, Vol II

  • Read Binary(raw Image) data from a file

    Hi
    PLEASE HELP, I want to Read Binary(Raw Image)data (16 bit integer) from a file and display on the JPanel or JFrame.

    Hi, you'll need to use MemoryImageSource.
    You read each RGB triple and add it to a pixel[].
    Heres the roughg idea.
    Hope that helps.
    Harley.
    int width,height;
    int[] pixels = new int[width*height];
    while(!fileDone)
    for(int i=0; i<(width*height) i++){
    int rgb = inputStream.readInt();
    pixels[i] = rgb;
    DirectColorModel colorModel = new DirectColorModel(16,0xff00,0x00ff,0x00ff);
    MemoryImageSource memImage = new MemoryImageSource(width,height,pixels,0,width));

  • Blurry / Pixelated R3D images in Premiere CC 2014

    FYI, for anyone else (like me) who has experienced pixelation / blurry images when viewing certain R3D files on the timeline or in the source window in Premiere CC 2014: this issue can be solved by right clicking on the problem clip(s) in the timeline or in the project files panel, selecting "Source Settings," and clicking "Save to RMD." You'll see the image become fully sharp again immediately.
    This blurriness happens even when the still and playback resolution settings are set to "Full" in the program and source windows, and it isn't fixed by adjusting sequence settings. It was still visible even after exporting to Quicktime files, which created a huge headache for us as we tried to figure out what we were doing wrong in our sequence or export settings. Turns out both of them were fine, it was just this "Save to RMD" glitch.
    An Adobe staff member replied and said they will fix this in around a month: Red footage pixelated on Import into AE.

    Update: Unfortunately it's not all good news.
    Trying to render out to H.264 wiht Mercury CUDA still gives a crash rendering with the typically uninformative 'Unknown Error'. Software rendering does not, but it's very slow.
    Miraizon Codec and the Premiere native Cineform also crash with 'unknown error'. However I can render out using Cineform Mov at 12bit using my registered copy of Cineform. Not fast, about 1/8 real time.

  • Read character from Image area

    Hi every body,
    I need to read character from image area(jpg image).
    regards,
    sundar

    Step 1: Read the "RGB" values of each pixel using getRGB(x,y)
    Step 2: Write this info in an File as *1.txt
    Step 3: Get samples for each character and store it in a separate file.
    Step 4: ........ its a very long process
    so u refer optical character recognition... if interested let me know it.. i have achieved it..
    Regards
    rinaldo

  • 'Reading pixels failed' canon IP90

    I have a scanned colour image, saved as a pdf, and it just won't print properly - it prints the first section of the image and then the rest of the page is just blank. I have emailed it to a friend who also has a macbook, but a different printer (don't know which) and it prints for them fine. I have installed snow leopard, correct drivers from canon for the pixma ip90, tried printing it using the 'wire' instead of 'wireless' but nothing seems to stop this error appearing " error: reading pixels failed (-9707) "
    I would really appreciate some help ! I have searched the internet for this error but nothing comes up..

    The image may be too large (i.e. the resolution may be too high) for the printer driver to handle. Try scaling down the image before printing, or re-scan with a lower resolution.
    Have you tried deleting the printer in System Preference, downloading and installing the latest printer drivers from Canon and then adding the printer again?

  • Read Error of images in libre office

    read error in images of LibreOffice
    Hi, when loading this file, do not load images in the document, this only happens since version 3.5, instead of pictures, a box appears with the message "read error".
    The file I downloaded from the Internet, the images are correctly loaded into abiword.
    I would appreciate your help, thanks.
    The File

    Crystal Reports is limited in how it works with images - large images or a large number of images, etc. Much as CR is not a good database archiving tool, it's not a very good graphics presenter. I find stand-alone versions of CR are a bit better, but that may just be a perception. My recommendations:
    1) Try an eval of a stand-alone version of CR:
    http://www.sap.com/solutions/sapbusinessobjects/sme/freetrials/index.epx
    Go for CR 2008 as CR 2011 does not have any SDK
    2) Make sure the picture  blob  what ever, never spills beyond the designer pane of the report. This may change from site to site depending on printer drivers used (CR depends on these to render the report)
    3) Have a look at the article [Causes of "Background Processing" error|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/50a6f5e8-8164-2b10-7ca4-b5089df76b33]
    Ludek
    Follow us on Twitter http://twitter.com/SAPCRNetSup
    Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

  • Reading 8kb tiff image and then writing into backend. please help

    Hi All, Please Help ..
    My aim is to read a tiff image which of 8kb 1732x717 size, and then store it into backend.
    what I did is read the image into bufferedImage and then used tiffencodeparam with compression_none but the problem is size is too much after encoding.
    code sample
    BufferedImage image = ImageIO.read(tiff_filename); to read tiff image
    to write tiff image
    TiffEncodeParam p = new TiffEncodeParam();
    p.setCompression(TiffEncdeParam.COMPRESSION_NONE);
    FileOutputStream out = new FIleOutputStream(tiff_filename);
    ImageEncoder e = ImageCodec.createImageEncoder(""TIFF,out,p);
    e.encode(image);
    out.close();

    I got all my pictures AND everything else back, folders, ratings, keywords etc
    Fortunately I had a backup of the entire iPhoto library folder, it was about 3 months old (I know shame on me) so I didn't want to just use the entire backup folder and lose 3 months of photos.
    So I just copied the AlbumData.xml file and the Library6.iPhoto file. PRESTO all my pictures were back WITH all the folders,keywords etc, etc intact!! (up till the 3 month old backup point).
    Then I just re-imported the missing 3 months worth of pictures from the original folder in the iphoto library folder. So all I had to recreate was 3 months worth of customization. WHEW!!
    Reading through the discussions it seems there is a fair number of users where iPhoto would go empty, but they knew the images were still on the computer. I am not a programmer, but it seems silly to me the their are files that get re-written everytime iPhoto closes....computers crash. and then what happens to the files? Mine got corrupted, lesson learned BACKUP more frequently!!
    Thanks to Old Toad who steered me to the Library6.iPhoto as a possible troublemaker in another thread!

  • Reading Mac Disk Image on PC

    Are there any tools for reading a Disk Image created with Disk Utility on a Windows computer?

    Does this page contain anything useful?
    (20542)

  • Read the raw image file

    I want to read the raw image file , i have the basic labview 8.0 version

    That is a broad question... I'll make some asumptions.
    I think you have a file with some raw image format. This can be quite a few formats. Every camera firm has it's own proprietry format. Often, when talking about a raw image, it is simply a 2d array of colors. So you'll have a file with numbers that are U8's that represent R G B, alpha R G B, B G R, etc., or a U32 that represent the same, combined in one U32...
    The data can be stored binary or ASCII. Both formats are handled differently.
    The ASCII format can be one large array of data, or seperated with enters for each scan line.
    In both cases, you might need to remove information, like height and width, from the data before parsing the image data.
    You can use the "Spreadsheet String To Array" to convert the a ASCII string to a LabVIEW 1D or 2D array. Or use "Read From Spreadsheet File.vi" to read the file directly as an array. Use Reshape Array to convert a 1D array to a 2D array.
    The binary file is a bit different. Use "Read Binary File". It will get you a string. This string is a converted array of U8, the string doesn't need to be ASCII. convert this string to an array of U8's, with "String To Byte Array". Convert the 1D array just like before.
    Now you have a 2D array. You can convert it into a pixmap with "Flatten Pixmap.vi". You can then display it in a picture control with "Draw Flattened Pixmap.vi".
    Regards,
    Wiebe.

  • Pixelated jpg image files

    Muse 7.2, OSX 10.9.2
    I have inline images and a gallery slideshow on a site.  Some of these images are extremely pixelated on the rendered web page.  All the images were sized in Photoshop to the exact pixel dimensions and saved as  saved-for-web jpegs in Photoshop.
    Several of the inline images have been on my site for about a year and only recently appear pixelated.  I'm making some edits to my site but have not touched any of the images that are now pixelated.  Also, I have embedded the links to all images so Muse need not search through my computer for the image source files.
    I did replace one pixelated inline image with the same source file, but with a different file name.  For some reason this image now renders properly.  However this technique did not have any benefit on several images in a slideshow gallery that has both thumbnails and full size image.
    What's your opinion why these images appear pixelated, and what suggestions might overcome the trouble?
    Best regards,
    Tim

    Zak,
    A second thought on pixellated images.  Currently I have overcome the problem by replacing all the affected images with a replacement image (the same original) but using a different file name.  These same images are used elsewhere in the site, but at different sizes.  Likely the file name was the same as the images that became pixellated.
    The odd thing is that other images that have not pixellated have the same treatment.  In several places (pages) the images are the same with the same file name but at a different size.
    I have not made this site active yet but these odd problems have made for lots of extra work to sort out.  You can see this site at:  www.fractalfotos.com/debV3/index.html
    Thanks, Tim

Maybe you are looking for