-type Grayscale differences in 6.7.8-9

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
clownpleco
Posts: 8
Joined: 2012-09-24T10:23:12-07:00
Authentication code: 67789

-type Grayscale differences in 6.7.8-9

Post by clownpleco »

We updated from Centos 6 to Centos 7 and in the process updated from ImageMagick 6.7.2-7 to ImageMagick 6.7.8-9.
The results of the following command changed dramatically:
/usr/bin/convert SRC.jpg -type Grayscale -colors 256 DEST.png
The new images is extremely dark. The source jpg file only has gray shades.

Removing -type Grayscale makes the images visually the same, but the metadata is different (most notably RGB vs sRGB).
/usr/bin/convert SRC.jpg -colors 256 DEST.png

Is this an expected change? Is there an equivalent command I can use to retain RGB. I have to be careful as we are using this command for an operational product. I'm not sure if our client will have any problems with the sRGB images, but I need to be prepared if that is not the case.

User avatar
fmw42
Posts: 25941
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type Grayscale differences in 6.7.8-9

Post by fmw42 »

IM 6.7.8.9 may have been during the changes in colorspace and grayscale. You are getting linear grayscale in place of non-linear. The linear would be darker. It could also be a bug at that version. See https://imagemagick.org/discourse-serve ... =4&t=21269

What is the date of your IM version. Linux patches to update without changing version numbers. They also often only patch for security issues. So bugs or enhancements may not be included.

Try

Code: Select all

convert SRC.jpg -colorspace gray -colors 256 -type Grayscale DEST.png

or

convert SRC.jpg -colorspace Rec601Luma -colors 256 -type Grayscale DEST.png
Do either of those work?

User avatar
fmw42
Posts: 25941
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type Grayscale differences in 6.7.8-9

Post by fmw42 »

Sorry, I had not read your post fully. You want to keep the grayscale image, but have it list as RGB or sRGB, which? RGB should be dark. sRGB should be light.

-type grayscale should not produce a linear RGB and dark file by itself unless your input JPG might have been linear. Furthermore, it should list via identify as colorspace gray and type grayscale.

Post your input image so we can test and explain what you want the output to show.

clownpleco
Posts: 8
Joined: 2012-09-24T10:23:12-07:00
Authentication code: 67789

Re: -type Grayscale differences in 6.7.8-9

Post by clownpleco »

ImageMagick 6.7.8-9 2019-08-08 Q16
ImageMagick 6.7.2-7 2017-03-22 Q16

I wanted the png to visually match the jpg. Both ImageMagick 6.7.2-7 and ImageMagick 6.7.8-9 created RGB images. ImageMagick 6.7.8-9 was significantly darker. The images below were reduced in size using gimp so I'm not sure if the meta data was been preserved.

ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... -small.jpg
ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... -small.png
ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... -small.png
ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... -small.png

Here are the links to the full sized images.
ftp://ftp.ssec.wisc.edu/rickk/imagemagik/origin.jpg
ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... ersion.png
ftp://ftp.ssec.wisc.edu/rickk/imagemagi ... ersion.png
ftp://ftp.ssec.wisc.edu/rickk/imagemagik/test-fix.png

I was not sure how to post the images.
As an FYI, our client had no problems using the sRGB images created with ImageMagick 6.7.8-9.

User avatar
fmw42
Posts: 25941
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -type Grayscale differences in 6.7.8-9

Post by fmw42 »

IM 6.7.8.9 has the colorspaces for linear and non-linear reversed (a bug).

This fails:

Code: Select all

convert origin.jpg -colorspace gray -colors 256 -type grayscale x2.png
This works (though identify -verbose reports it as colorspace=lineargray):

Code: Select all

convert origin.jpg -set colorspace RGB -colorspace gray -colors 256 -type grayscale x3.png

Post Reply