Group Abstract Group Abstract

Message Boards Message Boards

1
|
9.8K Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Avoid inconsistent behavior of ColorSpace -> Automatic?

Posted 8 years ago
POSTED BY: Alexey Popkov
4 Replies
POSTED BY: Chad Knutson

1) By specifying the 2nd argument to ColorConvert as "RGB", you are asking for an "RGB" color. So whatever you pass to that function will necessarily be converted to 3 channels. If you have a alternative suggestion for how to convert multi-dimensional (greater than 3), unspecified colorspaces to RGB, please share. Or you could simply define your own function and use it.

To me, an analogous problem is projecting a 5-dimensional object to 3 dimensions. How would you determine the correspondence of the 5 dimensions to 3D space? Obviously, there are many ways to do this, but I don't know how you would determine which approach is 'best'.

2) I don't understand this comment. You can certainly create a 6 channel image. You can do many calculations in Mathematica on the 6 channel image without any consideration for how to represent the pixel data visually. If you ask the front end to display the image, Mathematica will use the colorspace conversion you showed in your calculations.

For practical purposes, I'd advise using one of our defined colorspaces (and corresponding number of channels).

3) Behavior depends on the function. Binarize will take the mean of all channel data at a pixel. The *Filter functions work on each channel indepe

POSTED BY: Chad Knutson
Posted 8 years ago

If you have a alternative suggestion for how to convert multi-dimensional (greater than 3), unspecified colorspaces to RGB, please share.

I would certainly expect at least an error message warning the user that the operation is ambiguous and telling what choice Mathematica does in this situation. Without the warning current behavior just deceives the user because he/she almost certainly does NOT want/expect to obtain what Mathematica generates from images having 2 or 4 channels, or more. Personally I would prefer the warning and $Failed as the output (for making debugging and programming easier), but I insist only on the warning message.

Obviously, there are many ways to do this, but I don't know how you would determine which approach is 'best'.

This is the reason why the warning message in such situation is necessary, as well as clear explanation in the Documentation of the Mathematica's approach to the problem. At the moment there is neither the one nor the other.

I don't understand this comment.

Probably I wasn't sufficiently clear. I mean that if really the colorspace is unspecified, then the problem of correct conversion to RGB has no solution. Since Mathematica currently performs the conversion, it apparently assumes an artificial "colorspace" under ColorSpace -> Automatic. In the other words, ColorSpace -> Automatic does mean some undocumented and completely imaginary colorspace in the context of ColorConvert, what directly contradicts the cited statement from the Documentation.

Binarize will take the mean of all channel data at a pixel.

Thanks, didn't know this. Is it documented anywhere?

POSTED BY: Alexey Popkov

In the doc page for Binarize (under Details and Options), is this statement: Binarize works with 2D and 3D images. It converts multichannel and color images into grayscale images, then produces an image in which every pixel has value 0 or 1.

Interestingly, this statement is not completely accurate, as my function below demonstrates. But at least the behavior for Binarize makes more sense than the ColorConvert to "Grayscale" evaluation. I'd argue that the latter implementation is a bug.

In[98]:= binComp[imageData_List, thresh_] :=
 Module[{im, im2},
  im = Image[imageData, ColorSpace -> Automatic, Interleaving -> True];
  im2 = ColorConvert[im, "Grayscale"];
  ImageData /@ {Binarize[im, thresh], Binarize[im2, thresh]}
  ]

In[99]:= binComp[{{{1, 1, 1, 0, 0, 0}}}, 0.5]

Out[99]= {{{0}}, {{1}}}

In[100]:= binComp[{{{1, 1, 1.001, 0, 0, 0}}}, 0.5]

Out[100]= {{{1}}, {{1}}}

I argue that this evaluation is a bug:

In[102]:= 
ColorConvert[
  Image[{{{1, 1, 1, 0, 0, 0}}}, ColorSpace -> Automatic, 
   Interleaving -> True], "Grayscale"] // ImageData

Out[102]= {{0.5925}}

Thanks for your input. Your objections are certainly valid!

POSTED BY: Chad Knutson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard