Extracted Red channel is getting brighter.

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.
Post Reply
par
Posts: 3
Joined: 2018-02-02T06:57:17-07:00
Authentication code: 1152

Extracted Red channel is getting brighter.

Post by par » 2018-02-02T07:01:38-07:00

I need to extract Red channel from a PNG file.

I use this command.
convert image.png -channel R channel.png

Unfortunately brightness is slightly increasing in pixels of the output image.
For example a pixel with red value of 100 becomes 132 in the output image.

Now I wonder if I'm using IM correctly?

I run ImageMagick 6.9.9-26 on Mac OS Sierra

Input
Image

Output
Image

Pavel
YoWindow Weather project

snibgo
Posts: 10481
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extracted Red channel is getting brighter.

Post by snibgo » 2018-02-02T07:41:46-07:00

Your input image is grayscale. What do you mean by "extract Red channel"? The red channel is no different to the green or blue channels, or the gray value.

Your command doesn't extract a channel, it merely sets what channels any following operations should operate on, but there aren't any operations. Your output is identical to your input.
snibgo's IM pages: im.snibgo.com

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

Re: Extracted Red channel is getting brighter.

Post by fmw42 » 2018-02-02T10:09:03-07:00

ImageMagick compare function says the pixel data is identical. Both images are type=grayscale, but your input shows it as colorspace sRGB, while your output has colorspace Gray.

Code: Select all

compare -metric rmse XAln75t.png L0Yiqwm.png null:
0 (0)

The difference is in the PNG meta data:

Input:

Code: Select all

  png:IHDR.color_type: 2 (Truecolor)
      png:sRGB: intent=0 (Perceptual Intent)
 
Output:

Code: Select all

 png:IHDR.color-type-orig: 0
 
And intent is not specified.

Try the following:

Code: Select all

convert input.png -define png:color-type=2 -intent perceptual output.png
That seems to match in meta data for me.


Unfortunately, I do not think you can set rendering intent to perceptual on a uniquely colorspace gray image. So you need to leave the image as colorspace sRGB and type=grayscale to keep the intent=perceptual.

I tried

Code: Select all

convert input.png -colorspace gray -intent perceptual output.png
But the verbose information says that rendering intent is undefined and no PNG intent is set.

snibgo
Posts: 10481
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extracted Red channel is getting brighter.

Post by snibgo » 2018-02-02T10:24:45-07:00

Is intent relevant? There is no profile.
snibgo's IM pages: im.snibgo.com

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

Re: Extracted Red channel is getting brighter.

Post by fmw42 » 2018-02-02T10:49:59-07:00

snibgo wrote:
2018-02-02T10:24:45-07:00
Is intent relevant? There is no profile.
I do not know. I thought if it was colorspace sRGB vs grayscale, that intent would be relevant. It is listed in the input verbose information Rendering Intent and as PNG:sRGB intent=perceptual

par
Posts: 3
Joined: 2018-02-02T06:57:17-07:00
Authentication code: 1152

Re: Extracted Red channel is getting brighter.

Post by par » 2018-02-02T11:18:23-07:00

Guys, thank you for responding so quickly!
I have a PNG image in sRGB format.
All three RGB channels contain the same values.
I just need to extract one of them (Red, for example) to a file in grayscale format to save space and memory.

I've tried the spells proposed by Fred.
Unfortunately, they produce an RGB image that stores all three channels.

The last one produces a grayscale image, but the brightness is higher than in the original. Just like in my attempt.

Code: Select all

convert input.png -colorspace gray -intent perceptual output.png
snibgo wrote:
2018-02-02T07:41:46-07:00
Your command doesn't extract a channel, it merely sets what channels any following operations should operate on...
Thank you, snibgo.
What is the proper way to extract a channel with Image Magick?

par
Posts: 3
Joined: 2018-02-02T06:57:17-07:00
Authentication code: 1152

Re: Extracted Red channel is getting brighter.

Post by par » 2018-02-02T11:28:05-07:00

For the reference the input and output images side by side in Photoshop.
Notice that the building to the right is brighter.

Image

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

Re: Extracted Red channel is getting brighter.

Post by fmw42 » 2018-02-02T12:06:08-07:00

I do not think you can do that since I think you cannot specify perceptual intent for grayscale single channel images. If you change your input to have intent unspecified, then they would look the same. Perhaps using profiles and intent you can manage to get what you want. As I mentioned before the actual pixel data is identical. It seems that the perceptual intent on your input is what makes it look different.

How did you create your input? What tool?

Try this:

Code: Select all

convert input.png -profile /Users/fred/images/profiles/GrayGamma22.icm output.png 

snibgo
Posts: 10481
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Extracted Red channel is getting brighter.

Post by snibgo » 2018-02-02T12:15:10-07:00

wrote:I have a PNG image in sRGB format.
All three RGB channels contain the same values.
I just need to extract one of them (Red, for example) to a file in grayscale format to save space and memory.
Here you go:

Code: Select all

convert in.png out.png
For your input file (which exiftool says has RGB channels), this creates an output that exiftool says is grayscale, ie only one channel.

I don't know why Photoshop displays them as different.
snibgo's IM pages: im.snibgo.com

textureLand
Posts: 5
Joined: 2017-12-05T09:12:57-07:00
Authentication code: 1152

Re: Extracted Red channel is getting brighter.

Post by textureLand » 2018-02-06T16:07:34-07:00

I believe the difference in the images you show are due to Color Profiles in Photoshop.
This has bitten me many, many times. (I don't seem to learn my lesson)

Below is a link to one of the best descriptions of Photoshop color profiles I have found: an introduction to what they do, and how to adjust color profiles.
In their example -- they want the browser image to look the same as the image in Photoshop:

https://www.howtogeek.com/70161/my-phot ... -fix-them/

Post Reply