Setting gamma value when converting DPX to JPEG

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Setting gamma value when converting DPX to JPEG

Post by stevepugh »

Hi all,

According to the Motion Picture Digital Images docs (http://www.imagemagick.org/www/motion-picture.html), I ought to be able to change the incoming gamma settings using "-set setting value" when converting a DPX file into JPEG format (for example, when creating a contact sheet of film frames).

However, the following four lines yield identical JPEG images when I would expect significant gamma differences. Can anyone tell me what I'm doing wrong?

convert C:\TestFile.dpx -set gamma 0.5 -set reference-black 95 -set reference-white 685 image1.jpg
convert C:\TestFile.dpx -set gamma 1.0 -set reference-black 95 -set reference-white 685 image2.jpg
convert C:\TestFile.dpx -set gamma 1.8 -set reference-black 95 -set reference-white 685 image3.jpg
convert C:\TestFile.dpx -set gamma 2.2 -set reference-black 95 -set reference-white 685 image4.jpg

Many thanks, my eyes are starting to cross and my head hurts from banging it against the wall.

-Steve
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

Use gamma, black-point, and white-point to attenuate the conversion from the Log colorspace to RGB. If you want to set the gamma, for example, in the output DPX image, use -define dpx:television.gamma=1.7.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

magick wrote:Use gamma, black-point, and white-point to attenuate the conversion from the Log colorspace to RGB. If you want to set the gamma, for example, in the output DPX image, use -define dpx:television.gamma=1.7.
Thank you for the quick reply, but my understanding is that the "define xxx:xxx.xxxxx" is solely for writing OUT a DPX file - what if my goal is to read in a DPX and write out a JPEG with the gamma converted?

Best,
Steve
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

Is your DPX image in the Log colorspace? Type
  • identify -verbose myimage.dpx
and check the Colorspace tag. We ran your script with ImageMagick 6.3.8-1 and when we compared the first and second images we get:
  • compare -metric mae image1.jpg image2.jpg compare.png
    2761.14 (0.0421324)
Which shows a slight difference in the pixels as expected.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

magick wrote:Is your DPX image in the Log colorspace? Type
  • identify -verbose myimage.dpx
and check the Colorspace tag. We ran your script with ImageMagick 6.3.8-1 and when we compared the first and second images we get:
  • compare -metric mae image1.jpg image2.jpg compare.png
    2761.14 (0.0421324)
Which shows a slight difference in the pixels as expected.
*Ahem*
Move along folks, nothing to see here...

I am embarassed to admit it, but somewhere along the line my test source image got converted from Log to linear RGB colorspace. Recopying that file from its safe and secure original location yielded a Log test file and the correct differences in gamma being applied to my target JPEG image.

I thank you kindly for pointing me in the right direction!!

Best,
Steve
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Logarithmic DPX file reporting as RGB - how to handle?

Post by stevepugh »

Hi there, it's me again - Realizing that my earlier attempt to set gamma while converting a DPX file to JPEG was unsuccessful because the source image was identifying itself as Colorspace RGB (not Colorspace Log), I set to investigating.

When I run identify -verbose on a Logarithmic DPX file written out of Digital Fusion 5.2, I get the following (edited for brevity):

Code: Select all

Format: DPX (SMPTE 268M-2003 (DPX 2.0))
  Class: DirectClass
  Geometry: 2048x1156+0+0
  Type: TrueColor
  Endianess: MSB
  Colorspace: Log
  Depth: 10-bit
  
When I run identify -verbose on a Logarithmic DPX file written out of AfterEffects CS3, I get the following:

Code: Select all

  Format: DPX (SMPTE 268M-2003 (DPX 2.0))
  Class: DirectClass
  Geometry: 2048x1156+0+0
  Type: TrueColor
  Endianess: MSB
  Colorspace: RGB
  Depth: 10-bit
  
I believe that both are actually logarithmic because when I apply our standard Lookup table, both look identical after conversion. However, Imagemagick does not want to apply gamma to that second image in the same way that it handles that first image, apparently because of the flag.

I can't say that I blame it, this appears to be a case of mis-handling during the file write. However, I am wondering if there is a way to "force" Imagemagick to act on this file as a logarithmic file. Will I need to (*gasp*) modify source? I'm only a little bit scared of that. OK, maybe a lot ;-)

Many thanks for any insight/enlightenment provided!!
Steve
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

The colorspace of the DPX image is defined by the image element descriptor and transfer-characteristic. If the transfer characteristic is PrintingDensityColorimetric we set the colorspace to LogColorspace. Only if the colorspace is Log do we apply the gamma and black/white points to convert to the RGB colorspace. Its possible the program you are using is not conforming to the SMPTE standard or ImageMagick is not interpreting the standard correctly. Post a URL to your two DPX images and we will download and try to determine if ImageMagick has a bug or if the program you are using is buggy.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

Howdy, I sent you a PM with a link to the two files (updated link, with Two-Count 'em-TWO files), I hope that's OK.

Best,
Steve
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

Got it. Stand by, we may need a day or two to get to this problem.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

Copy that, thank you!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

The following will work with ImageMagick 6.3.8-3 Beta (available sometime tomorrow):
  • convert -colorspace log AfterEffectsFile.dpx -set gamma 0.5 -set reference-black 95 -set reference-white 685 image.jpg
Alternatively, take a look at the SMTPE documentation and let us know how a Log colorspace is indicated in the DPX file format and we will patch the DPX coder to properly report a Log colorspace (or as mentioned, perhaps there is a bug in your program).
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

Fantastic, thank you! And I will investigate the SMTPE docs and let you know what I find.

Thanks again,
Steve
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by magick »

ImageMagick 6.3.8-3 is scheduled for release within a week.
stevepugh
Posts: 43
Joined: 2008-01-21T12:34:36-07:00

Re: Setting gamma value when converting DPX to JPEG

Post by stevepugh »

Good morning! I have downloaded and installed 6.3.8-4 and can "convert -list colorspace", it shows me all of the colorspace options.

However, attempting to convert one of those 'RGB' DPX files written out of AfterEffects and specifying "-colorspace log -set gamma 2.2 -set reference-black 95 -set reference-white 685 output.jpg" gives me the same effect as that command line w/o the colorspace argument in the earlier build of IM.

The end result is still a JPG which appears to have been generated from a log file without any of the gamma or black/white reference points having been altered. As a test, I ran the same command only changing colorspace to "rgb" and the result was identical.

Can you tell me what I'm doing wrong?

Many thanks,
Steve
Post Reply