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.

This question already has an answer here:

I am using Mathematica for the processing of images. For this I have to process a lot of images. Currently, I import one by one of the images to run the simulation. I want to import all the image files of a folder and assign variable to each of them...How to do it? Any suggestion?

share|improve this question

marked as duplicate by Yves Klett, gpap, Sjoerd C. de Vries, bobthechemist, m_goldberg Mar 10 at 14:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Welcome to mma.se! Please consider setting a username, it might even get you an upvote or two :P –  Jacob Akkerboom Mar 10 at 9:39
add comment

2 Answers 2

SetDirectory["c:\\users\\rasher\\downloads\\"];
images = FileNames["*.jpg"];
count = 1
Do[imagevar[count++] = Import[image], {image, images}]

Images will be in imagevar[1], imagevar[2]... so you can easily index into them.

Obviously, change directory / filenames to suit.

share|improve this answer
add comment

If you have numbered or desired variable names in mind (acknowledging there are number padding issues for large numbers) you could use. Assuming you have set working directory as per rasher:

images = FileNames["*.jpg"];
MapThread[
 Set[#1, #2] &, {ToExpression /@ 
   Table["img" <> 
     ToString@NumberForm[j, 3, NumberPadding -> {"0", ""}], {j,Length[images]}], 
  img}];

In this case img0001 is set to images[[1]], img0002 is set to images[[2]],...

However, using an array (as per rasher) will be much easier to deal with and refer to for all but the smallest sets. Otherwise just import the image files into one variable and choose relevant parts of interest.

share|improve this answer
add comment

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