Page 1 of 2

CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T07:29:53-07:00
by mik0rz
Goal: Convert the attached CMYK PSD to RGB PNG preserving the transparency

Problem: The command I'm running converts the image, but the drop shadow has a white glow in it (so if you place the resulting PNG on a solid background the shadow is not correct). I can convert in photoshop with no issue, but in imagemagick there's a white glow mixed in with the shadow.

Here's the command I'm using:

convert INPUT.psd -profile GRACoL2006_Coated1v2.icc -profile sRGB-IEC61966-2.1.icc -background None -layers merge -scale 400x400 -resample 72 OUPUT.png

http://s000.tinyupload.com/index.php?fi ... 5784777482

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T08:16:00-07:00
by mik0rz
ImageMagick Version 7.0.5-0 Q8 (32-bit) on Windows Server

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T10:23:53-07:00
by fmw42
try adding -define psd:alpha-unblend=off before reading the psd file in your command. See http://www.imagemagick.org/script/comma ... php#define

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T11:22:53-07:00
by mik0rz
fmw42 wrote: 2017-03-31T10:23:53-07:00 try adding -define psd:alpha-unblend=off before reading the psd file in your command. See http://www.imagemagick.org/script/comma ... php#define

Yep. Did that already. Like:

convert -define psd:alpha-unblend=off INPUT.psd -profile GRACoL2006_Coated1v2.icc -profile sRGB-IEC61966-2.1.icc -background None -layers merge -scale 400x400 -resample 72 OUPUT.png

Same result unfortunately.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T12:12:22-07:00
by mik0rz
It would be awesome if someone else could give it a whirl and see what happens ..

Here's the input PSD - http://s000.tinyupload.com/index.php?fi ... 5784777482

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T13:01:29-07:00
by snibgo
I assume you want the [0] image.

The object was probably photographed on a light background, so the shadow is a light shade of gray. Thus, flattening against a dark background will look strange.

A cure is to turn the shadow to black. We do this by turning all semi-transparent pixels black. (The code also turns all fully-transparent pixels black, which doesn't matter.)

This would leave a narrow aliased black line around the object, which is ugly. The "-level" and "-blur" cleans this up.

Windows BAT script. Use different profiles if you want. Resample or whatever as you wish.

Code: Select all

%IM%convert ^
  shadow_example.psd[0] ^
  -profile UncoatedFOGRA29.icc -profile sRGB.icc ^
  ( +clone ^
    -alpha extract ^
    +write mpr:ALPHA ^
    -level 50,100%% ^
    -blur 0x1 ^
  ) ^
  -compose Darken -composite ^
  ( mpr:ALPHA -channel RGB -evaluate Pow 1 +channel ) ^
  -compose CopyOpacity -composite ^
  x.png

%IM%convert ^
  x.png ^
  -background Blue -layers Flatten ^
  x2.png
x.png is the "corrected" version of the input. x2.png is flattened against a dark background.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:00:22-07:00
by fmw42
mik0rz wrote: 2017-03-31T12:12:22-07:00 It would be awesome if someone else could give it a whirl and see what happens ..

Here's the input PSD - http://s000.tinyupload.com/index.php?fi ... 5784777482
I tried all of the following with no success using IM 7.0.5.3 Q16 Mac OSX.

Code: Select all

magick -define psd:alpha-unblend=off shadow_example.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
-background None -layers merge tmp1.png

Code: Select all

magick -define psd:alpha-unblend=off shadow_example.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
-background None -compose multiply -layers merge tmp2.png

Code: Select all

magick -define psd:alpha-unblend=off shadow_example.psd[0] \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
tmp3.png

Note that in Photoshop your second layer is composed with multiply. I even tried changing that to normal and saved the new file and tried the above also. But no luck.

Code: Select all

magick -define psd:alpha-unblend=off shadow_example2.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
-background None -layers merge tmp1b.png

Code: Select all

magick -define psd:alpha-unblend=off shadow_example2.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
-background None -compose over -layers merge tmp2b.png

Code: Select all

magick -define psd:alpha-unblend=off shadow_example2.psd[0] \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
tmp3b.png

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:08:52-07:00
by fmw42
I am not a Photoshop expert, but might the difference be due to the gray and spot dot grain in the color control panel in PS. IM does not know how to handle either.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:19:05-07:00
by snibgo
Fred: I think my post above identifies the problem, and gives a solution.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:25:08-07:00
by fmw42
snibgo wrote: 2017-03-31T14:19:05-07:00 Fred: I think my post above identifies the problem, and gives a solution.

Yes. But I think the proper way to do the antialiasing as I mentioned in my PM is to blur first and then do the -level. At least that is the way I always do it.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:28:28-07:00
by fmw42
Also depending upon the image and how I want it antialiased, I sometimes do -level 0x50% rather than -level 50x100%. I have to test both ways to see which way I like best.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T14:33:35-07:00
by snibgo
Swapping those two also works, but neither is perfect.

Consider the edge of the large object. With no blur or level, an ugly black line is introduced on both sides of the object, near the top of the image.

My level then blur removes this, but unfortunately also slightly lightens the edge of the shadow at the base of the object.

Fred's suggestion of blur then level correctly handles the shadow at the base, but it leaves the black lines near the top. They are now aliased so look better, but they shouldn't be there at all.

Doubtless, more tweaking could give a result that is either more accurate technically, or more pleasing, or both.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-03-31T15:34:12-07:00
by fmw42
I think this might do it. I noticed that there are 3 layer. The first layer [0] seems to be the flattened layer, but does not have the correct shadow. So we reconstruct the image from the second and third layers, which are smaller than the first layer. So we need to copy the first layer and make it fully transparent and then -layers merge the other two with it after removing the original first layer.

Code: Select all

magick shadow_example.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -clone 0 -alpha transparent \)  \
-delete 0 +insert \
-background none -layers merge \
shadow_im.png
If that works to match your original PSD converted to PNG, then you can now do your other processing.

comparing this result with one saved from Photoshop using profiles, I get

Code: Select all

compare -metric rmse shadow_im.png shadow_ps.png null:
484.19 (0.00738826)

So less than 1% error that is slightly visible when I flicker compare the two images.

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-04-03T07:28:07-07:00
by mik0rz
fmw42 wrote: 2017-03-31T15:34:12-07:00 I think this might do it. I noticed that there are 3 layer. The first layer [0] seems to be the flattened layer, but does not have the correct shadow. So we reconstruct the image from the second and third layers, which are smaller than the first layer. So we need to copy the first layer and make it fully transparent and then -layers merge the other two with it after removing the original first layer.

Code: Select all

magick shadow_example.psd \
-profile /Users/fred/images/profiles/GRACoL2006_Coated1v2.icc \
-profile /Users/fred/images/profiles/sRGB.icc \
\( -clone 0 -alpha transparent \)  \
-delete 0 +insert \
-background none -layers merge \
shadow_im.png
If that works to match your original PSD converted to PNG, then you can now do your other processing.

comparing this result with one saved from Photoshop using profiles, I get

Code: Select all

compare -metric rmse shadow_im.png shadow_ps.png null:
484.19 (0.00738826)

So less than 1% error that is slightly visible when I flicker compare the two images.


i think this one may be close enough. i notice when i run some other images through it i have a very small (1px) white border around the object itself --oddly only visible on lighter solid backgrounds (not visible on really dark backgrounds) -- i'm hoping it will go unnoticed.

Thanks for everyone's input!

Re: CMYK PSD to transparent RGB PNG - drop shadow ghosting

Posted: 2017-04-03T09:36:59-07:00
by fmw42
Post one of those example psd image that have this issue. It might be solved by antialiasing or modifying the transparency layer