5 replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
source | link

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address


An alternative to the way I used makeColorFn above is this:

myBlend[body_][n_] := Blend[body, n]

colorfn = myBlend[{w, MapThread[Append, {colors, vars}]}\[Transpose]];

With[{colorfn = colorfn}, 
  Manipulate[
    Image3D[img, ColorFunction -> colorfn], 
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

The key here is to inject a color function in a form that is open to evaluation so that it "picks up" the values of α[x]. Function doesn't work here as its body is held. Compare:

Manipulate[Blend[x, #] &, {x, 0, 5}]

Manipulate[myBlend[x], {x, 0, 5}]

enter image description here

I still need With to get colorfn inside Manipulate before it is evaluated and the GUI is built, or the vars variables are not recognized and replaced correctly.

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address


An alternative to the way I used makeColorFn above is this:

myBlend[body_][n_] := Blend[body, n]

colorfn = myBlend[{w, MapThread[Append, {colors, vars}]}\[Transpose]];

With[{colorfn = colorfn}, 
  Manipulate[
    Image3D[img, ColorFunction -> colorfn], 
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

The key here is to inject a color function in a form that is open to evaluation so that it "picks up" the values of α[x]. Function doesn't work here as its body is held. Compare:

Manipulate[Blend[x, #] &, {x, 0, 5}]

Manipulate[myBlend[x], {x, 0, 5}]

enter image description here

I still need With to get colorfn inside Manipulate before it is evaluated and the GUI is built, or the vars variables are not recognized and replaced correctly.

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address


An alternative to the way I used makeColorFn above is this:

myBlend[body_][n_] := Blend[body, n]

colorfn = myBlend[{w, MapThread[Append, {colors, vars}]}\[Transpose]];

With[{colorfn = colorfn}, 
  Manipulate[
    Image3D[img, ColorFunction -> colorfn], 
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

The key here is to inject a color function in a form that is open to evaluation so that it "picks up" the values of α[x]. Function doesn't work here as its body is held. Compare:

Manipulate[Blend[x, #] &, {x, 0, 5}]

Manipulate[myBlend[x], {x, 0, 5}]

enter image description here

I still need With to get colorfn inside Manipulate before it is evaluated and the GUI is built, or the vars variables are not recognized and replaced correctly.

4 added 937 characters in body
source | link

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address


An alternative to the way I used makeColorFn above is this:

myBlend[body_][n_] := Blend[body, n]

colorfn = myBlend[{w, MapThread[Append, {colors, vars}]}\[Transpose]];

With[{colorfn = colorfn}, 
  Manipulate[
    Image3D[img, ColorFunction -> colorfn], 
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

The key here is to inject a color function in a form that is open to evaluation so that it "picks up" the values of α[x]. Function doesn't work here as its body is held. Compare:

Manipulate[Blend[x, #] &, {x, 0, 5}]

Manipulate[myBlend[x], {x, 0, 5}]

enter image description here

I still need With to get colorfn inside Manipulate before it is evaluated and the GUI is built, or the vars variables are not recognized and replaced correctly.

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] :=
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address


An alternative to the way I used makeColorFn above is this:

myBlend[body_][n_] := Blend[body, n]

colorfn = myBlend[{w, MapThread[Append, {colors, vars}]}\[Transpose]];

With[{colorfn = colorfn}, 
  Manipulate[
    Image3D[img, ColorFunction -> colorfn], 
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

The key here is to inject a color function in a form that is open to evaluation so that it "picks up" the values of α[x]. Function doesn't work here as its body is held. Compare:

Manipulate[Blend[x, #] &, {x, 0, 5}]

Manipulate[myBlend[x], {x, 0, 5}]

enter image description here

I still need With to get colorfn inside Manipulate before it is evaluated and the GUI is built, or the vars variables are not recognized and replaced correctly.

3 one more code tweak
source | link

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

With[{opa =makeColorFn[colors_, varsw_, specvars_] := Sequence @@ 
 ({#, 0, 1} & /@ vars)}w,
  Manipulate[
    co = MapThread[Append, {colors, opavars}];
    colorfn = {w, co]}\[Transpose] /. body_ :> (Blend[body, #] &);

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> colorfn]makeColorFn[colors, w, opa]],
    specEvaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

With[{opa = vars, spec = Sequence @@ ({#, 0, 1} & /@ vars)},
  Manipulate[
    co = MapThread[Append, {colors, opa}];
    colorfn = {w, co}\[Transpose] /. body_ :> (Blend[body, #] &);
    Image3D[img, ColorFunction -> colorfn],
    spec
  ]
]

enter image description here

The main problem is the use of AppendTo where Append would suffice. You could instead use:

co = MapThread[Append, {colors, opacities}];

Full code:

Okay, cleaner now

img = ExampleData[{"TestImage3D", "MRknee"}];

colors =
 {Black, Blue, Purple, Red, Brown, Gray, Green, Orange, Pink, Cyan, Yellow, White};

vars = Array[α, Length@colors];

w = List @@@ ColorConvert[colors, "RGB"].{0.2989, 0.5870, 0.1140};

makeColorFn[colors_, w_, vars_] := 
 {w, MapThread[Append, {colors, vars}]}\[Transpose] /. body_ :> (Blend[body, #] &)

With[{opa = vars},
  Manipulate[
    Image3D[img, ColorFunction -> makeColorFn[colors, w, opa]],
    Evaluate[Sequence @@ ({#, 0, 1} & /@ vars)]
  ]
]

enter image description here

In the code above With is used to address

2 deleted 222 characters in body
source | link
1
source | link