Pages: [1]   Go Down

Author Topic: Is there a way to "un-profile" an image (remove changes applied by a profile)  (Read 1066 times)

SergeyT

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 55

Hello everyone,

Looking for some help here.

I have images that are produced by a scanner and saved in CIE LAB (D50).
I also have the scanner RGB input profile

Looking for a way to get back to a profile uncorrected linear RGB with what I have. 

At the scan time it is impossible to preserve scans in the original input RGB color space as the scanner SW requires either CIE LAB or device independent RGB (aRGB, sRGB, ProPhoto) as the output.
After the scan is made it is impossible to convert it from CIE LAB back to the input RGB , that input RGB is naturally not showing as a valid option in CMS.

Maybe there is way to create a fake "reverse-profile" from the scanners input profile using let's say Argyll?
And then:
1. Convert LAB->ReverseRGB
2. Remove gamma correction(Apply gamma 1.0)

Or maybe a fake (transparent) scanner input profile can be created that does no modifications to the input from the scanner ? This is for conversion of color negatives into positives. The film is scanned as seen (orange) and of course there is no correct ICC profile for that kind of film can be obtained anyway.
 
Thanks,
SergeyT

Logged

MauriceRR

  • Newbie
  • *
  • Offline Offline
  • Posts: 46

If the input rgb is not functionnal in your CMS (photoshop ?), you need to reverse the profiling, which won't be easy if you don't have à color target probably like an it8. It's à lot of work for something maybe not so important.

For the color cast of à négative, try this in photoshop :
Create à colored layer on top with the color of your négative, then apply division mode.
And just add a color inversion layer then.

After that you can make à subtile retouch with cameraraw for exemple, which will invert the gamma for you when applying filters curves and effets.
Logged

GWGill

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 608
  • Author of ArgyllCMS & ArgyllPRO ColorMeter
    • ArgyllCMS

I have images that are produced by a scanner and saved in CIE LAB (D50).
I also have the scanner RGB input profile
Depends on the profile. Is it a matrix profile ? If so, you can easily reverse the transform, assuming you know the intent used.
Is it cLUT ? If so, what tables does it have ?
Quote
2. Remove gamma correction(Apply gamma 1.0)
You mean make it linear RGB ?

If so, that's a harder, and I doubt there are any tools that will just do it. You have to somehow create a set of RGB transformation curves based on the profile.
Logged

SergeyT

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 55

Thanks for the responses!

Have to check what kind of profile it is and post the results here, almost certain it is a matrix profile. I have both the target and the ref file.
The goal is to restore a linear RGB from the CIELAB scan.

In the last few years I have tried every PS method that can be found on Web as well as developed my own sets of actions. None of them are satisfactory for a variety of reasons with inconstancy of outcome being the major one.

Thanks again,
SergeyT
Logged

GWGill

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 608
  • Author of ArgyllCMS & ArgyllPRO ColorMeter
    • ArgyllCMS

The goal is to restore a linear RGB from the CIELAB scan.
Linear RGB can only be "restored", if the scanner natively outputs linear RGB. Many won't, as linear light encoding is inefficient.
« Last Edit: October 29, 2019, 07:46:23 am by GWGill »
Logged

SergeyT

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 55

To the best of my knowledge the data is coming from the scanner in linear RGB (16 bit per channel).
I am not certain to what degree the scanning software changes it before the input profile applied. But if it does I would expect it to apply the same curve to all 3 channels.
Other than lamp intensity (I have no control over that), input profile and output color space(LAB, could be set as RGB as well) no other settings are applied in the scanning SW. If and whatever Tone curve (gamma) is applied by the scanner software outside of input profile is not that important for as long as the same curve is applied to all 3 channels. I can reverse that curve by utilizing a photograph of a color checker on a particular film stock.  For now I need help to find a way to reverse the changes applied by the input profile.
I have many-many scans made over the years and would really like to reverse the changes applied by the input profile to get as close to linear RGB as possible without rescanning. 

Here is the one that I believe was used for most if not all scans
Quote
icc:
Header:
  size         = 113600 bytes
  CMM          = 'APPL'
  Version      = 2.4.0
  Device Class = Input
  Color Space  = RGB
  Conn. Space  = Lab
  Flags        = Not Embedded Profile, Use anywhere
  Dev. Mnfctr. = 0x0
  Dev. Model   = 0x0
  Dev. Attrbts = Transparency, Glossy, Positive, Color
  Rndrng Intnt = Perceptual
  Illuminant   = 0.964203, 1.000000, 0.824905    [Lab 100.000000, 0.000498, -0.000436]
  Creator      = 'LOGO'


tag 4:
  sig      'chad'
  type     'sf32'
  offset   38704
  size     44
S15Fixed16Array:
  No. elements = 9

tag 5:
  sig      'rXYZ'
  type     'XYZ '

tag 6:
  sig      'gXYZ'
  type     'XYZ '

tag 7:
  sig      'bXYZ'
  type     'XYZ '

tag 8:
  sig      'wtpt'
  type     'XYZ '

tag 9:
  sig      'bkpt'
  type     'XYZ '

tag 10:
  sig      'rTRC'
  type     'curv'
  offset   38848
  size     1034
Curve:
  No. elements = 511

tag 11:
  sig      'gTRC'
  type     'curv'
  offset   39884
  size     1034
Curve:
  No. elements = 511

tag 12:
  sig      'bTRC'
  type     'curv'
  offset   40920
  size     1034
Curve:
  No. elements = 511

tag 13:
  sig      'A2B0'
  type     'mft2'
  offset   41956
  size     35662
Lut16:
  Input Channels = 3
  Output Channels = 3
  CLUT resolution = 17
  Input Table entries = 511
  Output Table entries = 511
  XYZ matrix =  1.000000, 0.000000, 0.000000
                0.000000, 1.000000, 0.000000
                0.000000, 0.000000, 1.000000

tag 14:
  sig      'A2B2'
  type     'mft2'
  offset   41956
  size     35662
Lut16:
  Input Channels = 3
  Output Channels = 3
  CLUT resolution = 17
  Input Table entries = 511
  Output Table entries = 511
  XYZ matrix =  1.000000, 0.000000, 0.000000
                0.000000, 1.000000, 0.000000
                0.000000, 0.000000, 1.000000

tag 15:
  sig      'A2B1'
  type     'mft2'
  offset   77620
  size     35662
Lut16:
  Input Channels = 3
  Output Channels = 3
  CLUT resolution = 17
  Input Table entries = 511
  Output Table entries = 511
  XYZ matrix =  1.000000, 0.000000, 0.000000
                0.000000, 1.000000, 0.000000
                0.000000, 0.000000, 1.000000

tag 16:
  sig      'gmps'
  type     'data'


Thanks for your help!
SergeyT

Logged

Doug Gray

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 2197

This is an input device profile. It converts device RGB (from the scanner) to Lab using 3D lookup tables.
It has tables for 3 intents, Perceptual, Relative, and Saturation. It does not have reversing tables which would labeled B2A0-3. As a result you can't use something like Photoshop to do a reverse conversion. Printer profiles have both sets of tables and is required for soft proofing.

All three tables share the same values so there is no difference between conversion Intents.

The RGB device channels also have 1D LUTs and they don't share the same tables. Table sharing can be seen by looking at the "offset" and these differ for each RGB. That doesn't mean they aren't the same. Some software will just duplicate the tables which is space wasteful unless they actually differ in which case they must have different offsets. To determine that you would have to dump the tables.

Since it doesn't have reverse tables there is no simple way to find the input scanner RGB values however, Argyll's software includes an option to search the A2B tables in reverse and so can find the RGB values given the Lab values. See Argyll's utility documentation or perhaps Graeme Gill will stop by.

The Lab values from the profile are generally only the first step in conversion. From there the Lab is typically converted to a RGB working space like Adobe RGB or sRGB. Unless the image is tagged you should assume sRGB.


Logged

SergeyT

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 55

Thanks for the tips and some more input.

After reading the ICC Profile Specs doc I think that I need to refine my terminology a bit.

The scanner supplies image data in Device RGB. Scanner software takes that data and converts into CIELAB by applying the scanner's input profile. The resulting image that is now in CIELAB is saved as a TIFF.

What I am looking for is to find a way to convert my scans that are currently stored in CIELAB TIFFs back into Device RGB TIFFs, knowing the scanner input profile (or the measurement data that profile was built upon).

The profile contains both TRC curves as well as cLUT A2B tables.

It is clear to me that for converting from Device RGB into CIELAB the scanner SW was applying cLUT based conversion.

According to the ICC Profile Specs, TRCs is mandatory element of an input profile and if present can be used for converting into CIEXYZ as a PCS, while cLUT A2B should be used converting into CIELAB as a PCS.


6.3.1.2 RGB Input Profiles
Quote
The three tone reproduction curves linearize the raw values with respect to the luminance (Y) dimension of the CIEXYZ encoding of the profile connection space. The 3x3 matrix converts these linearized values into XYZ values for the CIEXYZ encoding of the profile connection space
...
Only the CIEXYZ encoding of the profile connection space can be used with matrix/TRC models. A multidimensional table tag must be included if the CIELAB encoding of the profile connection space is to be used.

Does this mean that data contained in the profile sufficient for a CMS to use either Matrix or cLUT to convert from Device RGB into other color spaces(just in theory)?

In my case cLUT was used for conversion, but did  TRCs elements participate in the conversion as well, or were they ignored by the CMS engine during the conversion from Device RGb into CIELAB?

Some more info about the TRCs in my profile:
Although all 3 TRCs are comprised of 511 element arrays each,  upon further examination the actual values in all 3 curves are identical and resemble a simple gamma 2.2 curve


Part of Argyll package is revfix utility that allows for "Regenerate a CLUT device profiles B2A table data by inverting the A2B table". Can it be used to built a B2A cLUT based upon the data contained in my scanner profile ?
I have tried it but it rejected to work with my profile. Do I need to add some tag elements into my profile to make it work? If needed I think I should be able to do it without breaking the integrity of scanners profile.

Apologies for so many questions and thanks again for your help,
SergeyT
Logged

Doug Gray

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 2197

Thanks for the tips and some more input.

After reading the ICC Profile Specs doc I think that I need to refine my terminology a bit.

The scanner supplies image data in Device RGB. Scanner software takes that data and converts into CIELAB by applying the scanner's input profile. The resulting image that is now in CIELAB is saved as a TIFF.
Yes, this is consistent with your scanner profile.
Quote

What I am looking for is to find a way to convert my scans that are currently stored in CIELAB TIFFs back into Device RGB TIFFs, knowing the scanner input profile (or the measurement data that profile was built upon).

The profile contains both TRC curves as well as cLUT A2B tables.

It is clear to me that for converting from Device RGB into CIELAB the scanner SW was applying cLUT based conversion.

According to the ICC Profile Specs, TRCs is mandatory element of an input profile and if present can be used for converting into CIEXYZ as a PCS, while cLUT A2B should be used converting into CIELAB as a PCS.

TRCs, in input profiles, are normally used for camera sensor transforms. Scanners are linear enough that TRCs can provide good approximations. XYZPCS  and LABPCS are inter-convertible so it's rather odd to see both in the same input profile. Scanner profiles that I've generated with Argyll don't have TRCs, just 3DLUTs. I don't know what further to suggest at this point but you might run revfix with the -v option and post what it displays.
Quote


6.3.1.2 RGB Input Profiles
Does this mean that data contained in the profile sufficient for a CMS to use either Matrix or cLUT to convert from Device RGB into other color spaces(just in theory)?

In my case cLUT was used for conversion, but did  TRCs elements participate in the conversion as well, or were they ignored by the CMS engine during the conversion from Device RGb into CIELAB?

Some more info about the TRCs in my profile:
Although all 3 TRCs are comprised of 511 element arrays each,  upon further examination the actual values in all 3 curves are identical and resemble a simple gamma 2.2 curve


Part of Argyll package is revfix utility that allows for "Regenerate a CLUT device profiles B2A table data by inverting the A2B table". Can it be used to built a B2A cLUT based upon the data contained in my scanner profile ?
I have tried it but it rejected to work with my profile. Do I need to add some tag elements into my profile to make it work? If needed I think I should be able to do it without breaking the integrity of scanners profile.

Apologies for so many questions and thanks again for your help,
SergeyT
Logged

GWGill

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 608
  • Author of ArgyllCMS & ArgyllPRO ColorMeter
    • ArgyllCMS

To the best of my knowledge the data is coming from the scanner in linear RGB (16 bit per channel).
OK.

Since you haven't made the profile available, it's hard to be sure what will work. You can easily reverse the matrix transform of the profile, so I don't know why you haven't tried this already (i.e. see cctiff).

revfix wasn't designed for input profiles. It could be hacked to do something like that, if you know your way around the code.

If you want to invert the cLUT transform, then in principle xicclu could be used:

    xicclu -fif profile.icm

but this inverts one color at a time, and isn't setup to convert images.

Another possibility is to re-create the profile with a B2A table. If the profile contains the CGATS data (i.e. what is in the 'gmps" tag ??), then
you could extract that using extractttag, and then run colprof.

If there is no CGATS data, then a final method is to reproduce the profile. This is a slight hack:

    targen -d3 newprofile                              # You could set a larger number of patches, neutral axis patches etc. See doco.
    fakeread oldprofile.icm newprofile

then edit newprofile.ti3 and change "OUTPUT" to "INPUT", and "RGB_XYZ" to "XYZ_RGB", then:

   colprof -v newprofile

then you can use cctiff and the B2A table to convert from Lab to RGB

   cctiff -v newprofile.icm input_lab.tif output_rgb.tif


« Last Edit: November 04, 2019, 10:11:25 pm by GWGill »
Logged

SergeyT

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 55

Thank you for the valuable suggestions gentlemen!

It will take quite some time some time to try each.

Some inital results...

You can easily reverse the matrix transform of the profile...
The method works but the results are not suitable for proper Negative to Positive conversion unfortunately.

Quote
revfix wasn't designed for input profiles. It could be hacked to do something like that, if you know your way around the code.
Yet to get there...

Quote
If you want to invert the cLUT transform, then in principle xicclu could be used:
    xicclu -fif profile.icm
but this inverts one color at a time, and isn't setup to convert images.
Tried on a couple of patches but have to re-do with more precision to make conclusion.

Quote
Another possibility is to re-create the profile with a B2A table. If the profile contains the CGATS data (i.e. what is in the 'gmps" tag ??), then
you could extract that using extractttag, and then run colprof.
That worked, but again, the resulting data left me wishing for more. I think that might be due to differences in profiling algorithms used by profiler, the original profile was created with, and Argyll.
 
Quote
This is a slight hack:

    targen -d3 newprofile                              # You could set a larger number of patches, neutral axis patches etc. See doco.
    fakeread oldprofile.icn newprofile
   
   then edit newprofile.ti3 and change "OUTPUT" to "INPUT", and "RGB_XYZ" to "XYZ_RGB", then:

   colprof -v newprofile

then you can use cctiff and the B2A table to convert from Lab to RGB

   cctiff -v newprofile.icm input_lab.tif output_rgb.tif
So far this method produced the best results!

Thanks again for all your help!
SergeyT
Logged
Pages: [1]   Go Up