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?

  • $\begingroup$ Use Table[], and store the result somewhere else? $\endgroup$ – J. M.'s technical difficulties Apr 30 '13 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. Apr 30 '13 at 15:42

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}]
| improve this answer | |
  • $\begingroup$ +1 naming schemes like "stringNNN" aren't usually a good idea $\endgroup$ – Dr. belisarius Apr 30 '13 at 15:56
  • $\begingroup$ This solution is very efficient, thanks! @belisarius Could you explain why? $\endgroup$ – R.S. Apr 30 '13 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$ – J. M.'s technical difficulties Apr 30 '13 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. Apr 30 '13 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. Apr 30 '13 at 16:36

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}]

| improve this answer | |
  • $\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. Apr 30 '13 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 Apr 30 '13 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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