Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:40:53+00:00 2026-06-01T14:40:53+00:00

I’m using the following code to load a grayscale JPG image, and query a

  • 0

I’m using the following code to load a grayscale JPG image, and query a single pixel’s value from it:

Raster data;
data = ImageIO.read (file).getData();
int [] buf = new int[1];
data.getPixel(0, 0, buf);

The image I’m using for test purposes is this one:

testgradient.jpg

When I open this image in Photoshop, and extract the colour information from the top left pixel, it tells me it is pure black (RGB 0,0,0). As far as I can see, there is no colour profile attached to the image, so it should be loaded identically by ImageIO. However, the result of the above code is that buf[0] contains 1. As my intended application is sensitive to this change (I am processing map elevation data with 0 indicating sea level or lower) I am wondering if either

  1. I can rely on it always happening, and can rely on RGB 1,1,1 not also being decoded as value 1 (testing this, I get ‘3’ out), or
  2. there is any way of preventing the change?

Preventing the change would clearly be preferable — if black is coming out as 1, and having tested white and seeing it come out as 250, this must mean that some values in the middle are going to be compressed so multiple source values come out with the same output value, so I am clearly losing information here. I’d ideally want to avoid information loss (and, yes, I’m aware that information was lost in the conversion of the map data to JPG, but this is how it was supplied to me by the original data provider, so it is impossible for me to recover that data… I’d like to avoid losing any more of it, though).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:40:54+00:00Added an answer on June 1, 2026 at 2:40 pm

    What’s probably happening is that the JPEG does not have an embedded colorspace, and Photoshop’s default colorspace is different from Java’s default, resulting in slightly different pixel values. For example, Java could be assuming sRGB while Photoshop might be using AdobeRGB. You should verify that you’re using the same colorspace in both Photoshop and Java.

    EDIT:

    I examined the image you included in your post with Photoshop, and found the following interesting info:

    1. The colorspace is “uncalibrated” <exif:ColorSpace>65535</exif:ColorSpace>
    2. The image is a CMYK TIFF file with 4 samples per pixel, not 3

    Whatever is giving you (0,0,0) for the top-left corner and (255,255,255) for the bottom-right is applying some conversion function to the raw data, which is most definitely not pure black and pure white in this file.

    Here’s the entire XMP raw data set:

    <?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
    <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 5.0-c060 61.134777, 2010/02/12-17:32:00        ">
       <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
          <rdf:Description rdf:about=""
                xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">
             <xmpMM:DocumentID>45A47BED0B7E76061DB20B529F19C17E</xmpMM:DocumentID>
             <xmpMM:InstanceID>45A47BED0B7E76061DB20B529F19C17E</xmpMM:InstanceID>
          </rdf:Description>
          <rdf:Description rdf:about=""
                xmlns:dc="http://purl.org/dc/elements/1.1/">
             <dc:format>image/jpeg</dc:format>
          </rdf:Description>
          <rdf:Description rdf:about=""
                xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/">
             <photoshop:ColorMode>1</photoshop:ColorMode>
          </rdf:Description>
          <rdf:Description rdf:about=""
                xmlns:tiff="http://ns.adobe.com/tiff/1.0/">
             <tiff:ImageWidth>16</tiff:ImageWidth>
             <tiff:ImageLength>16</tiff:ImageLength>
             <tiff:BitsPerSample>
                <rdf:Seq>
                   <rdf:li>8</rdf:li>
                   <rdf:li>8</rdf:li>
                   <rdf:li>8</rdf:li>
                   <rdf:li>8</rdf:li>
                </rdf:Seq>
             </tiff:BitsPerSample>
             <tiff:PhotometricInterpretation>1</tiff:PhotometricInterpretation>
             <tiff:SamplesPerPixel>4</tiff:SamplesPerPixel>
             <tiff:XResolution>72/1</tiff:XResolution>
             <tiff:YResolution>72/1</tiff:YResolution>
             <tiff:ResolutionUnit>2</tiff:ResolutionUnit>
          </rdf:Description>
          <rdf:Description rdf:about=""
                xmlns:exif="http://ns.adobe.com/exif/1.0/">
             <exif:ExifVersion>0221</exif:ExifVersion>
             <exif:ColorSpace>65535</exif:ColorSpace>
             <exif:PixelXDimension>16</exif:PixelXDimension>
             <exif:PixelYDimension>16</exif:PixelYDimension>
          </rdf:Description>
          <rdf:Description rdf:about=""
                xmlns:xmp="http://ns.adobe.com/xap/1.0/">
             <xmp:CreateDate>2012-04-11T12:26:47-07:00</xmp:CreateDate>
             <xmp:ModifyDate>2012-04-11T12:26:48-07:00</xmp:ModifyDate>
             <xmp:MetadataDate>2012-04-11T12:26:48-07:00</xmp:MetadataDate>
          </rdf:Description>
       </rdf:RDF>
    </x:xmpmeta>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.