7
$\begingroup$

Normally,we use Image[RandomReal[1, {3, 4, 3}]] or use Image[RandomReal[1, {3, 4}]] to generate a image.

But in this answer(The image is very cool!),he use Image[RandomReal[1, {3, 4, 2}]] structure to generate a Image.

data = RandomReal[1, {3, 4, 2}];
Image@data

Blockquote

data == ImageData[Image[data]]

True

And then I try

Multicolumn[Table[Image[RandomReal[1, {3, 4, i}]], {i, 2, 101}]]

I get

enter image description here

You can see with the increase of variable i,the image is more like a deep color.So strange...

data = RandomReal[1, {3, 4, 100}];
data == ImageData[Image[data]]
(*Amazing,it is a color Image,but the length of a pixel is 100!!!*)

True

So how to interpreter the usage of parameters of Image?

$\endgroup$

3 Answers 3

3
$\begingroup$

I don't know the theory of this, but if you convert the "two channel" color to RGB you find you always get a color with one of the three components zero:

ListPlot[
 Transpose[
  Table[ImageData[
     ColorConvert[Image[{{ {Cos[t], Sin[t]}}}], "RGB"]][[1, 1]],
   {t, 0, Pi/2, .01}]], Joined -> True, 
 PlotStyle -> {Red, Green, Blue}, DataRange -> {0, Pi/2}]

enter image description here

here is a map of the full color space..

Image[Table[ {i, j}/100, {i, 0, 100}, {j, 0, 100}]]

enter image description here

or looking beyond the range 0-1 :

Image[Table[ {i, j}, {i, -3, 3, .002}, {j, -3, 3, .002}]]

enter image description here

the circles represent Norm[{c1,c2}]== n Sqrt[2]

$\endgroup$
5
$\begingroup$

If the data is 2D, then each row is taken as one row of pixels, whose gray level is given by one value

white = 1; black = 0; gray = 0.5;
data = {{white, black, gray},
        { gray, white, black},
        {white, gray, black}};
r = Image[data]

Since data is 2D, then the image will have 9 pixels, with 3 rows and 3 columns, each pixel value is gray level given as above

Mathematica graphics

If the data is 3D, and if each entry contains 3 numbers, then they are interpreted as RGB value of each pixel. So using the same data as above, but making it 3D, we get one row with only 3 pixels now

 Image[{data}]

Mathematica graphics

First pixel above has color RBG {1,0,.5} and second pixel has {.5,1,0} and third pixel has color RGB {1,.5,0}

Now if the data is 3D, but each element do not have 3 numbers in it, but only 2 or 4, 5, etc... numbers, as in your example, then Mathematica interpret these as "equally spaced hues"

Mathematica graphics

So now

data = {{white, black},{ gray, white},{white, gray}};
Image[{data}]

Mathematica graphics

In your example, data is 3D, but each entry has only 2 numbers. So it falls into the above case.

Mathematica graphics

Your data data = RandomReal[1, {3, 4, 2}] has 3 rows and 4 columns. But has 2 numbers in each entry of each row.

To make it RGB, then use data = RandomReal[1, {3, 4, 3}]

So this is RGB

data = RandomReal[1, {3, 4, 3}];
Image[data]

Mathematica graphics

And this is Hue

data = RandomReal[1, {3, 4, 2}];
Image[data]

Mathematica graphics

$\endgroup$
2
  • $\begingroup$ Thank you,but what is equally spaced hues?HSV has three parameter,but here we only have two,they don't match $\endgroup$
    – partida
    Jan 13, 2017 at 8:44
  • $\begingroup$ @partida I am not a color theory specialist, I just took what Mathematica help page said as you can see. May be this page can shed light on what "equally spaced hue" actually mean. en.wikipedia.org/wiki/Hue $\endgroup$
    – Nasser
    Jan 13, 2017 at 8:46
4
$\begingroup$

2-channel Image

Image[Sqrt[2] {{{1, 0}, {0, 1}}}]

Hue[#/2] & /@ Range[2]

can be expressed as Hue .

Table[{x, y}, {x, -2, 2, .05}, {y, -2, 2, .05}] // Image

and

mod[x_, y_] := If[# == 0, y, #] &@Mod[x, y];
Table[If[x == y == 0, Black, 
   Hue[3/Pi ArcTan[y, x], 1, mod[Sqrt[(x^2 + y^2)/2], 1]]], {x, -2, 
   2, .05}, {y, -2, 2, .05}] // Image

behave similarly

2-Channel Image

Multichannel Image

ImageAssemble[
 Table[ColorConvert[Image[Table[n IdentityMatrix[m], {n, 0, 4, .1}]], 
   "RGB"], {m, 10}]]

can be expressed as RGBColor .

n-Channel Image

4-channel Image:

t = RandomReal[Ceiling[4/3], {4}];
{Image[{{t}}], Image@RGBColor[#, (#2 + #3)/2, #4] & @@ t}

5-channel Image:

t = RandomReal[Ceiling[5/3], {5}];
{Image[{{t}}], Image@RGBColor[#, (#2 + #3)/2, (#4 + #5)/2] & @@ t}

6-channel Image:

t = RandomReal[Ceiling[6/3], {6}];
{Image[{{t}}], 
 Image@RGBColor[(#1 + #2)/2, (#3 + #4)/2, (#5 + #6)/2] & @@ t}

10-channel Image:

{Image[{{#}}], 
   Module[{l = Length[#], r, g}, If[l < 3, Abort[]]; 
    g = Ceiling[l/3];
    r = If[3 g == l, g, g - 1];
    RGBColor @@ (Mean /@ {#[[;; r]], #[[r + 1 ;; 
            r + g]], #[[r + g + 1 ;; l]]}) // Image]} &[
 RandomReal[1, {10}]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.