Compositing 32-bit images and getting strange output (colorspace issue?)

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
nate101
Posts: 9
Joined: 2017-05-24T04:29:54-07:00
Authentication code: 1151

Compositing 32-bit images and getting strange output (colorspace issue?)

Post by nate101 »

Hi all, new to Imagemagick and loving it so far. Thanks in advance for any help!

ImageMagick version: 7.0.5-Q16-HDRI for Windows

I have an image of a sphere that was created in a 3d studio max (Lime_Correct). Nowadays these renderers have a cool feature where you can break a rendered image into its raw components, in this case the base color of the sphere (Lime_SourceColor) and the shadows that fall on it (Lime_Shadows) and then recombine in post-production.

I'm able to achieve this in Photoshop by layering the two images and using a 'Multiply' blending mode. But when I try to recreate in ImageMagick I can't duplicate the effect (the composited image does not match the original, colors are off). Here is the command I was using:

Code: Select all

magick Lime_SourceColor.tif Lime_Shadows.tif -compose Multiply -composite -depth 32 Lime_IM.tif
  • To match the original render, I know the underlying component images must be 32-bit, in this case I'm using 32-bit TIFs
  • I thought perhaps it was a colorspace issue but I've tried every combination of RGB and sRGB in the above code and nothing gets output exactly correct
  • Not sure if this is some limitation of ImageMagick's ability to work with 32-bit images, but assume it was probably my noobish understanding of colorspaces
  • All the files I'm using are below if anyone wants to take a look
Lime_SourceColor.tif
Lime_Shadows.tif
Lime_Correct.tif (this is the correct output I'm trying to match)
Lime_Sphere.psd (this shows how compositing works properly in photoshop, you can see if you toggle on/off LimeCorrect layer)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by magick »

We're using ImageMagick 7.0.5-7 Q16 HDRI and libtiff 4.0.8. When we convert the image and compare, we only get a very slight difference in color:

Code: Select all

-> magick Lime_SourceColor.tif Lime_Shadows.tif -compose Multiply -composite -depth 32 Lime_IM.tif
-> compare -metric rmse Lime_IM.tif Lime_Correct.tif x:
54.2187 (0.000827324)
The difference is isolated to the edge of the sphere and the internal part of the sphere is the exact color of your reference image, Lime_Correct.tif.

The Windows version of ImageMagick is running libtiff 4.0.4. Perhaps that accounts for the differences you are seeing. We are upgrading the TIFF library to 4.0.8 in the next point release of ImageMagick this weekend. You could 7.0.5-8 when it is released and see if it fixes the problem.
nate101
Posts: 9
Joined: 2017-05-24T04:29:54-07:00
Authentication code: 1151

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by nate101 »

Thanks for the quick reply! I was just opening the two files in photoshop and comparing them visually, maybe I was looking at two different colorspaces in photoshop and that's why they looked different on my screen. Will run a couple more tests when I get home tonight and see what I come up with.
nate101
Posts: 9
Joined: 2017-05-24T04:29:54-07:00
Authentication code: 1151

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by nate101 »

Now that I have the first part working, I'm trying to recreate the Lime_SourceColor.tif using its two color components (black, green) and an alpha mask (see illustration below):

Image

Having trouble though figuring out how to match the colors in 32-bit and can't get an exact duplicate of the original. Here is the code I was using:

Code: Select all

magick ( -size 512x512 canvas:rgb(0,0,0) ) ( -size 512x512 canvas:rgb(68,189,42) ) Lime_Alpha.tif -depth 32 -composite Lime_IM.tif
compare -metric rmse Lime_IM.tif Lime_SourceColor.tif x:
What is the best way to go about identifying the rgb values of the two colors in the TIF so that I can then manually input them? Files I'm using are attached below:

Lime_Alpha.tif
Lime_SourceColor.tif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by fmw42 »

I am not sure I understand or follow all this. But I just want to make a point. Perfect green in ImageMagick is not green, but either green1 or lime or rgb(0,255,0). So you may be getting different colors building in ImageMagick from Photoshop, if you specify green in ImageMagick. If this is not the case for your problem, then please ignore my comments.

I presume you have checked the colorspaces. ImageMagick defaults to sRGB, while Photoshop defaults to AdobeRGB. I would recommend for best viewing across different viewers that you assign a common profile to your images.
nate101
Posts: 9
Joined: 2017-05-24T04:29:54-07:00
Authentication code: 1151

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by nate101 »

Fred,

Thanks for the reply and sorry my original post wasn't clear. I believe this is a colorspace issue like you said, I am just a complete novice at dealing with them in ImageMagick. What I'm trying to do is:
  • Recreate an existing 32-bit tif file -- Lime_SourceColor.tif which I have a link to above
  • The image consists of a solid black background and a solid green sphere
  • I have an alpha mask (Lime_Alpha.tif) to delineate the background from the sphere
  • I want to create two solid canvases, one that matches the color of the black background and one that matches the color of the green sphere
  • I can then use the Lime_Alpha.tif as a mask on the green canvas and composite to recreate the original Lime_SourceColor.tif
  • I'm not sure how to extract the color information from the green sphere so I can properly reproduce it on a solid canvas (aside from opening Photoshop and using the eyedropper which, like you said, doesn't seem to give consistent RGB values between PS and Imagemagick)
To try to make things simpler I cropped the green area from Lime_SourceColor down to a 1x1 pixel 32-bit tif (link below). When I run "identify -verbose" on it I get a ton of color information (see bottom) but I'm not sure how to take that information and apply it to the creation of a new canvas that will match the color/colorspace of the original.

For example, if I just wanted to recreate this 1x1 pixel green tif, what is the proper ImageMagick command to do so?

Sphere_Green_1px

Code: Select all

Image: Sphere\SquareTest\Sphere_Green_1px.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 1x1+0+0
  Resolution: 300x300
  Print size: 0.00333333x0.00333333
  Units: PixelsPerInch
  Type: Palette
  Base type: TrueColor
  Endianess: LSB
  Colorspace: sRGB
  Depth: 32/16-bit
  Channel depth:
    Red: 16-bit
    Green: 16-bit
    Blue: 16-bit
  Channel statistics:
    Pixels: 1
    Red:
      min: 15339.6 (0.234067)
      max: 15339.6 (0.234067)
      mean: 15339.6 (0.234067)
      standard deviation: 0 (0)
      kurtosis: -3
      skewness: 9.76562e+041
      entropy: -1.#IND
    Green:
      min: 24961.2 (0.380884)
      max: 24961.2 (0.380884)
      mean: 24961.2 (0.380884)
      standard deviation: 0 (0)
      kurtosis: -2.56e+062
      skewness: 0
      entropy: -1.#IND
    Blue:
      min: 5333.12 (0.0813782)
      max: 5333.12 (0.0813782)
      mean: 5333.12 (0.0813782)
      standard deviation: 0 (0)
      kurtosis: -5e+059
      skewness: 0
      entropy: -1.#IND
  Image statistics:
    Overall:
      min: 5333.12 (0.0813782)
      max: 24961.2 (0.380884)
      mean: 15211.3 (0.23211)
      standard deviation: 9814.67 (0.149762)
      kurtosis: -2.33333
      skewness: -0.0130688
      entropy: -1.#IND
  Colors: 1
  Histogram:
         1: (1005310956,1635882369, 349516757) #3BEBD3EC6181958114D533D5 srgb(23
.4067%,38.0884%,8.13782%)
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Matte color: grey74
  Background color: white
  Border color: srgb(223,223,223)
  Transparent color: none
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 1x1+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: None
  Orientation: TopLeft
  Properties:
    date:create: 2017-06-18T14:58:47-04:00
    date:modify: 2017-06-18T14:58:49-04:00
    dc:format: image/tiff
    exif:PixelXDimension: 1
    exif:PixelYDimension: 1
    icc:copyright: Copyright 2017 Adobe Systems Incorporated
    icc:description: XYZ Profile
    icc:manufacturer: XYZ Profile
    icc:model: XYZ Profile
    photoshop:ColorMode: 3
    photoshop:ICCProfile: XYZ Profile
    quantum:format: floating-point
    signature: 282097a888a967efa353d0e1f1869f7593d77b934e2855a361630e9258193960
    tiff:alpha: unspecified
    tiff:endian: lsb
    tiff:photometric: RGB
    tiff:rows-per-strip: 1
    tiff:software: Adobe Photoshop CC 2015 (Windows)
    tiff:timestamp: 2017:06:18 14:58:47
    xmp:CreateDate: 2017-06-09T09:01:16-04:00
    xmp:CreatorTool: Adobe Photoshop CC 2015 (Windows)
    xmp:MetadataDate: 2017-06-18T14:58:47-04:00
    xmp:ModifyDate: 2017-06-18T14:58:47-04:00
    xmpMM:DocumentID: adobe:docid:photoshop:007bbb73-5458-11e7-ac49-bde23bd34339

    xmpMM:InstanceID: xmp.iid:f87e8b73-e0dd-da47-b7b3-87a413324caa
    xmpMM:OriginalDocumentID: xmp.did:cacccd5c-6fdc-fe45-bbc5-4e63b8c31326
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by fmw42 »

If you just want to get the color of a pixel from an image ( or scale the image to get the average color ),then use the pixels: string format.

Code: Select all

convert rose: -format "%[pixel:u.p{10,20}]\n" info:
srgb(99,71,62)

will give you the resulting color at pixel 10,20.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Compositing 32-bit images and getting strange output (colorspace issue?)

Post by fmw42 »

For your lime source color image that is green surrounded by black, you can turn black to alpha and then scale the image to 1x1 and get the resulting pixel: value. It will compute the average of all non-transparent pixels. So

Code: Select all

convert Lime_SourceColor.tif -fuzz 10% -transparent black -scale 1x1! -alpha off -depth 8 -format "%[pixel:u.p{0,0}]\n" info:
srgb(45,86,15)
Post Reply