colorspace: gray channel handling

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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

colorspace: gray channel handling

Post by fmw42 »

I am converting to grayscale so I am using the average of RGB values.
-colorspace gray is not an equal mix (average) of the r,g,b channels, if that matters. To get equal average, use -colorspace OHTA -channel R.

see
http://www.imagemagick.org/script/comma ... colorspace
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Getting pixel coordinates of individual pixels in an ima

Post by anthony »

The R channel from OHTA seems a lot darker than average. Mayby it is another colorspace bug?

see the last image (Average OHTA) added to the example in...
http://www.imagemagick.org/Usage/color_ ... #grayscale
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixel coordinates of individual pixels in an ima

Post by fmw42 »

anthony wrote:The R channel from OHTA seems a lot darker than average. Mayby it is another colorspace bug?

see the last image (Average OHTA) added to the example in...
http://www.imagemagick.org/Usage/color_ ... #grayscale

I get the same results from using my graytoning script (which uses -color-matrix) and using the first channel of OHTA


graytoning -r 33.3333 -g 33.3333 -b 33.3333 rose: rose_ave.gif

convert rose: -set colorspace RGB -colorspace OHTA -channel r -separate rose_ohta_r.gif

Note that both use -set colorspace RGB. So you have to compare both with or both without. If without (linear gray), both results will be darker.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Getting pixel coordinates of individual pixels in an ima

Post by anthony »

Then the OHTA colorspace is not defined right!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixel coordinates of individual pixels in an ima

Post by fmw42 »

anthony wrote:Then the OHTA colorspace is not defined right!
Same thing with all the other colorspaces. They convert to linear channels and will show darker than if converted keeping them non-linear.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Getting pixel coordinates of individual pixels in an ima

Post by anthony »

fmw42 wrote:
anthony wrote:Then the OHTA colorspace is not defined right!
Same thing with all the other colorspaces. They convert to linear channels and will show darker than if converted keeping them non-linear.
Hmmm I re-ran the examples for pulling grays from various colorspaces..
http://www.imagemagick.org/Usage/color_ ... #grayscale

The LAB lightness channel seems to be very odd!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixel coordinates of individual pixels in an ima

Post by fmw42 »

my results from running your tests on IM 6.7.8.8 at http://www.imagemagick.org/Usage/color_ ... #grayscale are totally different from yours due to the channels being linear, except for OHTA. Most if not all images are much darker or more binary. By the way, you misspelled OHTA (as OTHA).

If I run them adding -set colorspace RGB, then I get your results, except for OHTA looks bright and LAB looks very bright.
Last edited by fmw42 on 2012-08-07T22:04:59-07:00, edited 1 time in total.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Getting pixel coordinates of individual pixels in an ima

Post by anthony »

fmw42 wrote:my results from running your tests on IM 6.7.8.8 at http://www.imagemagick.org/Usage/color_ ... #grayscale are totally different from yours due to the fact that now individual channels are linear. Most if not all images are much darker. By the way, you misspelled OHTA (as OTHA).
GIVE it tome to update!!!!
The LAB image stands out, everything else is rather 'dark' by comparision.

Also this round trip failed!

Code: Select all

   convert rose: -separate -swap 0,2 -combine rose_rb_swap.gif
As such I do not think -separate actually sets colorspace quite right internally.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixel coordinates of individual pixels in an ima

Post by fmw42 »

Also this round trip failed!

Code: Select all

convert rose: -separate -swap 0,2 -combine rose_rb_swap.gif
That is not a round trip. Perhaps I misunderstand what you are doing.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Getting pixel coordinates of individual pixels in an ima

Post by fmw42 »

When this all gets straightened out, it might be nice to show both the linear and non-linear versions, especially as now that grayscale is linear and before it was non-linear.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Getting pixel coordinates of individual pixels in an ima

Post by anthony »

fmw42 wrote:
Also this round trip failed!

Code: Select all

convert rose: -separate -swap 0,2 -combine rose_rb_swap.gif
That is not a round trip. Perhaps I misunderstand what you are doing.
Yes. not really, but this is and the result is still 'darker' than it should be if colorspaces are being handled right.

Code: Select all

convert rose: -separate -combine test.gif
Neither of the two commands should really change data values in the image. The point of these are to gain access to data values, not modify them. Sure the 'gray' channel images from -separate is marked 'linear-gray' the values however should still conatin non-linear sRGB channel values, as that is what was asked for. Look like that is not the case!

Though really -combine needs a destination 'colorspace' argument. as such this I would have definatally expected to come out correct! But also comes out dark.

Code: Select all

   convert rose: -separate -combine -set colorspace sRGB test.gif
Actually it needs to be a proper argument so the -combine can handle CMYK due to the extra channel, ditto for RGBA or sRGBA. That is something that should have been done a LONG time ago!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply