Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
I formatted the code for you. Please read the faq on how to format your code. Or, better yet, look at the edit link to see how I did it. –  rcollyer Apr 30 '13 at 15:37
    
Use Table[], and store the result somewhere else? –  J. M. Apr 30 '13 at 15:40
    
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). –  R.S. Apr 30 '13 at 15:42
add comment

2 Answers

up vote 3 down vote accepted

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}]
share|improve this answer
    
+1 naming schemes like "stringNNN" aren't usually a good idea –  belisarius Apr 30 '13 at 15:56
    
This solution is very efficient, thanks! @belisarius Could you explain why? –  R.S. Apr 30 '13 at 16:09
    
@R.S., unless you have a good justification for indexing your pics, you should use more descriptive names for them instead. –  J. M. Apr 30 '13 at 16:13
    
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! –  R.S. Apr 30 '13 at 16:22
4  
@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. –  R.S. Apr 30 '13 at 16:36
show 1 more comment

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

share|improve this answer
    
Thank you for this answer. Could you give me a hint what the @ means? Never saw it before in MMA code. –  R.S. Apr 30 '13 at 15:46
1  
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. –  bill s Apr 30 '13 at 15:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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