Skip to main content
April 7, 2011
Answered

Scanning and logging all LAB values from an image?

  • April 7, 2011
  • 1 reply
  • 3388 views

Hi all,

there was previously some means to extract the LAB values from an image to a .csv file by means of javascript via the Color Sampler tool.

i am wondering, if anyone is able to extract the LAB values of the WHOLE IMAGE to a .csv file?

Meaning, every pixel's LAB values, arranged in a .csv file...

will that ever be possible?

Thank you so much in advance!

regards.

This topic has been closed for replies.
Correct answer Michael_L_Hale

I also agree with your assessment Michael.  Those Lab numbers at those extremes probably never come in to play with normal images.

Where this comes into play, is when you are trying to read the Photoshop Raw file and convert  to Lab values "a" and "b". You would not want to scale the full 16 bit range of 0 to 65535 to the -128 to 127 Lab range.  To get the scaling right, you would want to scale it to the -128 to 128 range and then truncate to 127.  Otherwise, all the "a" and "b" values would be slightly off over the entire range.  The error would have been 0 out of 256 at "a" or "b" at -128 and an error of 1 out of 256 at the high end.   Not large yet enough to be noticed that it is off.

Thanks for spurring this topic through.  I would not have known this subtlety without your help.

John Wheeler


thebestcpu wrote:

You would not want to scale the full 16 bit range of 0 to 65535 to the -128 to 127 Lab range.

I would think someone using a script to get the Lab values of each pixel in a 16bit document would want the values in 16bit. But I get what you mean by clipping the range at 65279. However, like I said I am not going to worry about it. It seems that becasue Photoshop will save a and b values in a Ps raw file beyond 65279 that those values are valid even if the info panel clips.

Here is the function I am using now. It works with both 8 and 16bit numbers. Of course the script that read the PS raw file would still need to know wheither to read 8 or 16bit.

function convertNumberToLab(channel,num){
     if((num !=0 &&( num >>>8) != 0) ){// is 16bit num
          if(channel == 0){
               return Math.round(num*(32768/65535));
          }else{
               return Math.round((num-32768)/2);
          }
     }else{
          if(channel == 0){
               return Math.round((num/256)*100);
          }else{
               return num-128;
          }
     }
};

I did a Google search and Excel has raised the column and row limit. So unless it is reading very large files a script could create a csv file with a header and each pixel Lab values per row.

1 reply

April 7, 2011

I think I can partially get you there without the huge overhead of scanning the image array throught the script.  In fact, your question is a pretty common question about how to access the image bits productively.

Turns out there is a pretty quick and slick way to output the entire image array to a real basic file.  You just save the document as a Photoshop Raw file.

It comes up with a dialog box and I usually just accept the defaults and in your case I would chose interleaved.  For an 8 bit Lab image, for interleaved storage each three bytes will represent the "L", "a", and "b" bytes of one pixel of the image.  I don't remember from memory yet I think it is that order and then it sequentially goes through the array in the X direction first followed by the Y direction.  There is absolutely no other information stored with the data and that also means it does not store the X and Y dimensions of the image.  If that information is needed, your script can do that for you.  Whether you use the PS script to do the rest of some other programming language is your choice at that point.

Note, if you are using 16 bit mode, then each pixel is represented by 6 bytes (2 bytes for each of the  "L", "a", and "b" values).  Also note that non-interleaved mode outputs one color channel at a time.  You just pick the approach that works best for you.

Added edit:  Forgot to mention that the "L" byte values of 0 ot 100 are stored in the scale byte as 0 to 255;  the "a" and "b" value ranges of -128 to 127 are store in two's complement coding.  That was one added twist compared to the standard RGB values that are a direct mapping of 0 to 255.

Hope that helps. Hopefully I am not leading you astray.  Been a while since I have used it yet it (and did it with RGB yet it is supposed to work in all color modes and bit depth) is orders of magnitude faster than any scanning technique from within a script.

John Wheeler

Message was edited by: thebestcpu Added the info on how Lab is stored in the bytes

April 7, 2011

Hi thebestcpu,

First of all, i wish to thank you for the informative answer about how LAB are stored in RAW file.

Fortunately, i am working with RAW file(.rw2), 8-bits.

However, due to my limited knowledge about how RAW file works, i am unable to figure how to get to the LAB values.

As i start with a .rw2 file, i need not save the document as mentioned. How do i extract the L, A and B values into an excel file?

Can i trouble you to guide me step by step?

Thanks!

regards. 

April 7, 2011

Hi andosg_Ryan

Sorry, I am not familiar with the details of that raw format.  I am also doubtful that the camera raw data actaully stores Lab data directly in the file.  If you are trying to extract directly from a raw file, I am not sure that Photoshop would be the tool you want to use.

It might be easier to have forum members help you if you described the project/goal/objective you are trying to achieve.  There are usually many ways to get the job done whether with Photoshop or another tool.

Here is my understanding of PS handling of Raw files.  Raw files are processed through Adobe ACR from which you have a choice of which RGB space to bring it into PS. So if I needed Lab values from the Raw file (which is really after post processing through ACR):

- Bring in the raw file through ACR (or Adobe Lightroom)

- Open from ACR into PS with the widest color space available (e.g. ProPhotoRGB)

- Convert color mode to Lab

- Then output the data per my previous post


Other than that, another forum member would need to help you.

Good luck with your project

John Wheeler