2
$\begingroup$

I imported pictures into Mathematica, and used names for them that follow the easy scheme "name" string joined with an integer, ranging from 14 to 20. Printing these images on screen works nicely:

Do[Print[ToExpression[StringJoin["name", ToString[i]]]], {i, 14, 20}]

However, applying operations like ColorNegate[] or ColorReplace[] instead of Print[] will result in neither any output nor error message. Is it possible to process several images at once?

$\endgroup$
2
  • $\begingroup$ Use Table[], and store the result somewhere else? $\endgroup$ Commented Apr 30, 2013 at 15:40
  • $\begingroup$ Maybe I was not specific enough: I would like to print out the processed images on screen to see the result of an operation (filtering, color changing etc). $\endgroup$
    – R.S.
    Commented Apr 30, 2013 at 15:42

2 Answers 2

3
$\begingroup$

Might be better to use Table[] instead, so you can still use the processed images later:

girls = Table[ImageEffect[ExampleData[{"TestImage", img}], "Charcoal"],
              {img, {"Elaine", "Lena", "Tiffany"}}]

girls in charcoal

so for instance girls[[2]] gives Lenna in charcoal.

For your specific example,

Table[ColorNegate[ToExpression["name" <> ToString[i]]], {i, 14, 20}]
$\endgroup$
6
  • $\begingroup$ +1 naming schemes like "stringNNN" aren't usually a good idea $\endgroup$ Commented Apr 30, 2013 at 15:56
  • $\begingroup$ This solution is very efficient, thanks! @belisarius Could you explain why? $\endgroup$
    – R.S.
    Commented Apr 30, 2013 at 16:09
  • $\begingroup$ @R.S., unless you have a good justification for indexing your pics, you should use more descriptive names for them instead. $\endgroup$ Commented Apr 30, 2013 at 16:13
  • $\begingroup$ Ok got it - I simplified my example of course. The original dataset is a confocal z-stack of a stem cell cluster, where I included the "slice distance" (usually in micrometers) as integers in the filename. Legit enough? You decide! $\endgroup$
    – R.S.
    Commented Apr 30, 2013 at 16:22
  • 4
    $\begingroup$ @J.M Also - you just made me download all these mathematica girls, and judged from a distance, Tiffany is definitely holding a banana. I thank god everybody here has left already. $\endgroup$
    – R.S.
    Commented Apr 30, 2013 at 16:36
2
$\begingroup$

The problem is that Do doesn't return anything so you just need to prepend Print to your function to see the result: Do[Print@ColorNegate[ToExpression[StringJoin["name", ToString[i]]]], {i, 14, 20}]

$\endgroup$
2
  • $\begingroup$ Thank you for this answer. Could you give me a hint what the @ means? Never saw it before in MMA code. $\endgroup$
    – R.S.
    Commented Apr 30, 2013 at 15:46
  • 1
    $\begingroup$ You can answer this yourself. Whenever you don't know what something means in Mathematica, highlight it and press f1. It will display the help file for that item. So you can read all about Prefix, in this case. $\endgroup$
    – bill s
    Commented Apr 30, 2013 at 15:49

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.