Page 1 of 1

Extracted Red channel is getting brighter.

Posted: 2018-02-02T07:01:38-07:00
by par
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

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T07:41:46-07:00
by snibgo
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.

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T10:09:03-07:00
by fmw42
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.

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T10:24:45-07:00
by snibgo
Is intent relevant? There is no profile.

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T10:49:59-07:00
by fmw42
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

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T11:18:23-07:00
by par
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?

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T11:28:05-07:00
by par
For the reference the input and output images side by side in Photoshop.
Notice that the building to the right is brighter.

Image

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T12:06:08-07:00
by fmw42
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 

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-02T12:15:10-07:00
by snibgo
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.

Re: Extracted Red channel is getting brighter.

Posted: 2018-02-06T16:07:34-07:00
by textureLand
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/