Getting pixels from a grayscale PSD with alpha

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixels from a grayscale PSD with alpha

Post by fmw42 »

In case it had to do with 16-bit per channel from Q16, I will try again at 8-bits per channel

Code: Select all

convert -size 128x128 gradient: -alpha copy -depth 8 test.psd
convert test.psd -format "%[pixel:u.p{20,20}]\n" info:
graya(215,1)
graya(215,1)

Code: Select all

convert -size 128x128 gradient: -alpha copy -depth 8 test.psd
convert test.psd -format "%[pixel:u.p{100,100}]\n" info:
graya(54,1)
graya(54,1)


Still the same issue. But viewing the PSD file in Mac GraphicConverter, shows the alpha channel reversed in polarity, though it is not fully opaque.

So even -format "%[pixel:u.p{20,20}]\n" in command line is not reading the pixel values from the PSD file correctly.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixels from a grayscale PSD with alpha

Post by fmw42 »

I do not know that IM can convert a grayscale PSD to truecolor.

Code: Select all

convert -size 128x128 gradient: -alpha copy -depth 8 -define colorspace:auto-grayscale=off -type truecoloralpha test.psd
convert test.psd -format "%[pixel:u.p{100,100}]\n" info:
graya(54,1)
graya(54,1)

Result is still the same
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixels from a grayscale PSD with alpha

Post by fmw42 »

GIMP displays the PSD file the same as GraphicConverter with inverted alpha values. But it also complains

"Calling error for procedure 'gimp-image-set-resolution': Image resolution is out of bounds, using the default resolution in stead"

Perhaps because I did not set a density or units?
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Getting pixels from a grayscale PSD with alpha

Post by dlemstra »

valen wrote: 2017-06-15T08:02:54-07:00 The first image (grayscale, no alpha) prints out 512 pixel values. This is because ImageMagick reads 2 channels from it. Why 2? I don't know. All the values it prints out are 35. I assume this is a gamma adjusted value based on the original 50 we used.
You have 2 channels. One is the value of the red channel (RedPixelChannel) and the other value is (IndexPixelChannel). To know which value is which you should call the .offset method of the Pixels class. I am guessing that the colormap that is created contains values where the index has the same value as it's value.
valen wrote: 2017-06-15T08:02:54-07:00 The second image (grayscale, yes alpha) prints out 768 pixel values. This is because ImageMagick reads 3 channels from it. Why 3? I don't know. The values print out in a repeating pattern "186, 255, 186". Over and over again until all 768 are printed, that pattern repeats. I assume the 186 is a gamma adjusted value based on the original 200 we used. I don't know where the 255 came from. And notice the actual grayscale values of 50 (or adjusted 35) are nowhere to be found!!!??
You have 3 channels. One is the value of the red channel (RedPixelChannel), one is the alpha channel (AlphaPixelChannel) and the other value is (IndexPixelChannel). To know which value is which you should call the .offset method of the Pixels class. The 255 value is the value of the alpha channel. And I think you are not getting 35 because the alpha is blended into the red channel. This would explain why the alpha channel is fully opaque.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply