bug when converting PSD to TIFF with transparency

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

bug when converting PSD to TIFF with transparency

Post by fmw42 »

Version: ImageMagick 6.9.1-10 Q16 x86_64 2015-07-25 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib

With the following PSD, I have converted it to TIFF in Photoshop and similarly in IM, both with compress none. There is background transparency with a shadow under it at the bottom and the top. When I convert in PS to TIFF, the shadow matches. But when I convert in IM, the shadow is much lighter.

RGB PSD with sRGB profile:
psd_to_tiff_alpha_bug/RGB-SRC.psd

PSD to TIFF in Photoshop (compress none):
RGB-SRC_fred_ps_nolayers_none_transp_rle.tif


PSD to TIFF in IM (compress none):

Code: Select all

convert RGB-SRC.psd[0] -compress none RGB-SRC_fred_im_none_trans.tif
RGB-SRC_fred_im_none_trans.tif

Code: Select all

compare -metric rmse RGB-SRC_fred_im_none_trans.tif RGB-SRC_fred_ps_layers_none_transp_rle.tif -format "\n" null:
1244.16 (0.0189846)


EDIT: My client did not want the images shown publicly, so I have removed the links
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: bug when converting PSD to TIFF with transparency

Post by dlemstra »

I think this is happening because Photoshop is using the layer image and IM is using the merged image. When you convert your PSD file to .JPG with IM you will see that the layer has a grey/black background in the shadow at the bottom. I suspect that Photoshop is somehow using that when the TIF is created. But for IM this information is gone because it is using the first (merged) image and if you check the JPEG file you will notice that the background of the shadow is white. You can also see the difference in shadow if you save your .PSD file .PNG with IM. The layer is darker then the merged image. What happens when you save the image again as another .PSD file in Photoshop? Does that correct the issue with the shadow when you convert it in IM?
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I am saving the flattened layer from PSD to TIFF not to JPG. I tried saving the TIFF in PS with and without saving the layer information, but got the same result both ways. The TIFF compare correctly with the PSD file. IM is producing a lighter shadow.

I saved a new PSD file both with and without layers and converted it to TIFF in IM, but got the same bad comparison as above

P.S. Saving to JPG compares as good as it can considering that IM and PS may have different dct compression tables, and it is not saving the alpha channel. I get a compare rmse of 218.795 (0.00333859).

When I save the to TIFF without the alpha channel, I get a perfect match. So the issue is with the alpha channel processing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

More information. It looks like the conversion to TIF in IM is changing the RGB mean values, though the min and max appear the same.

I saved a new PSD file with layers unchecked. Then saved that to TIFF. And also converted that PSD file in IM to TIFF

Code: Select all

convert RGB-SRC_fred_nolayers.psd[0] -compress none RGB-SRC_fred_im_none_trans_psd_nolayers.tif

compare -metric rmse RGB-SRC_fred_im_none_trans_psd_nolayers.tif RGB-SRC_fred_ps_nolayers_none_transp_rle.tif -format "\n" null:
1244.16 (0.0189846)


Looking at the verbose info, I see that the channel means are different, though the min and max are the same. The alpha is the same. So something is happening to the RGB channels to change that and it might be the shadow rendering.


PSD to TIF in Photoshop

Code: Select all

Image: RGB-SRC_fred_ps_nolayers_none_transp_rle.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 3888x4800+0+0
  Resolution: 300x300
  Print size: 12.96x16
  Units: PixelsPerInch
  Type: TrueColorAlpha
  Base type: TrueColor
  Endianess: MSB
  Colorspace: sRGB
  Depth: 8/16-bit
  Channel depth:
    red: 16-bit
    green: 16-bit
    blue: 16-bit
    alpha: 8-bit
  Channel statistics:
    Pixels: 18662400
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 67.1413 (0.263299)
      standard deviation: 78.9552 (0.309628)
      kurtosis: -0.165784
      skewness: 1.02158
      entropy: 0.465623
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 72.3846 (0.283861)
      standard deviation: 71.7421 (0.281342)
      kurtosis: -0.467159
      skewness: 0.766278
      entropy: 0.502229
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 83.5585 (0.32768)
      standard deviation: 79.4682 (0.31164)
      kurtosis: -1.08445
      skewness: 0.503172
      entropy: 0.501862
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 193.895 (0.760374)
      standard deviation: 107.957 (0.423362)
      kurtosis: -0.494017
      skewness: 1.21938
      entropy: 0.082297

PSD to TIF in IM

Code: Select all

Image: RGB-SRC_fred_im_none_trans_psd_nolayers.tif
  Format: TIFF (Tagged Image File Format)
  Mime type: image/tiff
  Class: DirectClass
  Geometry: 3888x4800+0+0
  Resolution: 300x300
  Print size: 12.96x16
  Units: PixelsPerInch
  Type: TrueColorAlpha
  Base type: TrueColor
  Endianess: LSB
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
    alpha: 8-bit
  Channel statistics:
    Pixels: 18662400
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 127.852 (0.50138)
      standard deviation: 98.9807 (0.38816)
      kurtosis: -1.56957
      skewness: 0.121846
      entropy: 0.747748
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 133.131 (0.522081)
      standard deviation: 89.7938 (0.352132)
      kurtosis: -1.41754
      skewness: 0.14337
      entropy: 0.791323
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 144.295 (0.565861)
      standard deviation: 88.7483 (0.348032)
      kurtosis: -1.37766
      skewness: -0.130155
      entropy: 0.794532
    Alpha:
      min: 0 (0)
      max: 255 (1)
      mean: 193.895 (0.760374)
      standard deviation: 107.957 (0.423362)
      kurtosis: -0.494017
      skewness: 1.21938
      entropy: 0.129034
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I can achieve a similar lighter shadow when I convert the PSD to JPG, if I use -background white -flatten. If I leave out the -background white -flatten, then the shadow darkness seems to match between IM and PS TIFs.


Photoshop PSD to JPG
RGB-SRC_fred_ps_q12_standard_56K.jpg


IM PSD to JPG with flattening

Code: Select all

convert RGB-SRC.psd[0] -background white -flatten -quality 100 RGB-SRC_fred_im_q100_flatten.jpg

compare -metric rmse RGB-SRC_fred_im_q100_flatten.jpg RGB-SRC_fred_ps_q12_standard_56K.jpg -format "\n" null:
1453.1 (0.0221729)



IM PSD to JPG without flattening

Code: Select all

convert RGB-SRC.psd[0] -quality 100 RGB-SRC_fred_im_q100.jpg

compare -metric rmse RGB-SRC_fred_im_q100.jpg RGB-SRC_fred_ps_q12_standard_56K.jpg -format "\n" null:
218.795 (0.00333859)



Is it possible that IM is flattening the alpha with the RGB channels when converting PSD to TIF, but keeping the alpha as well?


EDIT: My client did not want the images shown publicly, so I have remove the links.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: bug when converting PSD to TIFF with transparency

Post by dlemstra »

Sorry for my confusing answer, let me try again. First run the following command:

Code: Select all

convert RGB-SRC.psd RGB-SRC.jpg
When you look at RGB-SRC-1.jpg you will notice a grey/black background on the part where the shadow is. I have the feeling that we lose that part of the information somehow when we read the merged (first) image. I was hoping that it would be a bug in older versions of Photoshop and saving it again would solve it.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

Sorry Dirk, I am not sure what you want me to do.

As above, I ran

Code: Select all

convert RGB-SRC.psd[0] -quality 100 RGB-SRC_fred_im_q100.jpg

compare -metric rmse RGB-SRC_fred_im_q100.jpg RGB-SRC_fred_ps_q12_standard_56K.jpg -format "\n" null:
218.795 (0.00333859)

And it looks visually the same as the PSD 0 layer with no lightening of the shadow.

Note that if I flatten the PSD in Photoshop, it does not lighten the shadow.

However, if I flatten the PSD 0 layer on a white background in IM, then I get a similar shadow lightening that I saw in the IM generated PSD to TIFF without flattening the TIFF.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: bug when converting PSD to TIFF with transparency

Post by dlemstra »

What I mean is to just look at the jpeg output, just visually inspect them. The layer (RGB-SRC-1.jpg) has a grey/black area in the part where the background should be darker. I am suspecting that this information is not copied to the merged image (RGB-SRC-0.jpg)
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

In photoshop, there is only one layer. So I do not know why converting to JPG in IM shows two layers. I would have thought that the PSD file had one layer and an equivalent flattened layer, though it only shows one layer. If that is true, then why is RGB-SRC-1.jpg so much bigger in dimension (WxH) than the flattened RGB-SRC-0.jpg? Furthermore, the layer -1 has other stripes and the shadow is way too dark.

I took a jpg image that I had and opened it in PS and converted it to PSD and saved it. It also shows only one layer. When I convert that to JPG in IM, I only get one image, not two. Perhaps it has to do with the alpha.

So I pasted that same jpg image into a transparent background in PS and save that as PSD. It shows only one layer in PSD. When I convert that to JPG in IM, I now get two images. The -0 is the original jpg in a white border the size of the transparent PSD file. The second is the original image without the transparency and the size of the original image.

So the transparency is what is causing us to get two JPG images when converted in IM.

However, for my test, the -1 image is smaller than the -0. But in the image I provided first, the -1 image is larger and has some strange striping.

I will have to inquire further of my client where this image came from and how it was created. Something strange seems to be going on in that image.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: bug when converting PSD to TIFF with transparency

Post by dlemstra »

When we read a PSD file we read the layers and the merged/flattened image. RGB-SRC-1.jpg is the layer and RGB-SRC-0.jpg is the merged/flattened image. I suspect something else that we are not aware off is stored inside the layer. But that should show up in the merged image and I don't understand why that is not happening.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I tried the following to convert to tiff. Rather than just the flattened layer, I did the whole psd.

Code: Select all

convert RGB-SRC.psd RGB-SRC.tif
convert: TIFF: negative image positions unsupported RGB-SRC.tif @ error/tiff.c/WriteTIFFImage/3533.

Although I get this error, I do get a two layer tiff. The first layer is the correct size, but the shadow is too light. The second layer is odd with the same gray texture pattern that is inside the image and is also outside the image and so the layer is too big, but the shadow looks reasonable.

So there must have been some strange processing of this image to get it to this state.

Perhaps the negative image position is causing IM trouble.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I did another test. I flattened the PSD file in PS so that it had a white background and saved as PSD (RGB-SRC_fred_ps_flattened.psd). I also save it as TIFF (RGB-SRC_fred_ps_flattened.tif). I then flattened the original PSD to TIF in IM and also just converted the PS flattened PSD to TIF in IM.

Code: Select all

convert RGB-SRC.psd -background white -flatten RGB-SRC_fred_im_flatten.psd

Code: Select all

convert RGB-SRC_fred_ps_flattened.psd RGB-SRC_fred_ps_flattened_im.tif
The RGB-SRC_fred_im_flatten.psd had a darker shadow than the other 3, whose shadows matched.

So PS flattening and IM flattening are different for this image, perhaps because of the odd way it was create that caused the strange -1 JPG and TIF image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

Dirk,

My client did not want the images shown publicly, so I removed them. If you want any of the images, let me know and I will send them to you privately.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I did another set of tests. I converted the PSD to TIF and PNG in PS. Then did the same in IM. In both cases, the IM conversion shows a lighter shadow than the PS version. So PS is doing something different when saving this image to tiff or png than IM using just the 0 (flattened) layer.

However, when I use my own created transparent PSD file and do the same, the compare results are perfect.

So there is something odd about the clients issue and how PS saves it to TIF or PNG
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: bug when converting PSD to TIFF with transparency

Post by fmw42 »

I can get a better TIF result from IM by using

Code: Select all

convert RGB-SRC.psd -background none -flatten RGB-SRC_im_transpflatten.tif
compared to the previous method

Code: Select all

convert RGB-SRC.psd[0] RGB-SRC_0_im.tif
The shadow is now darker, but its shape is slightly different. Perhaps because the other layer has negative offsets that IM does not know how to handle. It seems odd to me that the PSD 0 (flattened) layer does not appear to be truly flattened.

Code: Select all

compare -metric rmse RGB-SRC_ps_nolayers_none_transp_lzw.tif RGB-SRC_im_transpflatten.tif null:
1155.24 (0.0176279)

Code: Select all

compare -metric rmse RGB-SRC_ps_nolayers_none_transp_lzw.tif RGB-SRC_0_im.tif null:
1244.16 (0.0189846)
Post Reply