Group Abstract Group Abstract

Message Boards Message Boards

1
|
10K 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

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
Posted 8 years ago
POSTED BY: Alexey Popkov

One additional interesting evaluation is to observe the conversion of a 2 channel image to RGB

im = Image[{{{1, 0}}}, ColorSpace -> Automatic, Interleaving -> True];
im2 = ColorConvert[im, "RGB"];
ImageData[im2]

{{{0., 0.707106, 0.707106}}}

Okay, I have no idea why that formula is used. Pretty interesting.

And, finally, when an image with automatic colorspace is displayed in a notebook, the same computations that we see in ColorConvert[-image-, "RBG"] are used. Here is one way to show that (I don't want to upload an image here):

In[33]:= Rasterize[im, "Image"] === Rasterize[ColorConvert[im, "RGB"]]

Out[33]= True
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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard