0
$\begingroup$

I am using Mathematica for training dataset of fruits, for which i need to import the collection of images. Can we import a folder with images directly or Do we need to import each image in iteration format?

$\endgroup$
1
$\begingroup$

Import[FileNameJoin[{"Path", "To", "Directory", "*.jpeg"}], "JPEG"] is undocumented but will work (for now, subject to change).

I recommend perhaps FileSystemMap for this task. Simply Import[#, "JPEG"] & /@ FileNames["/Path/To/Directory/*.jpeg"] will work just fine as well.

$\endgroup$
  • $\begingroup$ Thank you so much for your Assistance..!! I tried the same with map function. Map[Import, FileNames["*_100.jpg", location]] $\endgroup$ – Azam Jainullabudin Mohamed Dec 6 '18 at 19:49
1
$\begingroup$

afaik. there is no easier way than doing

images = {}
names = FileNames[pattern,{directory}]
Do[AppendTo[images = Import[fileName]], {fileName, names}]

with

pattern = "*.png"
directory = "YourDirectoryName"

The code is untested but should work. Sadly i cannot easily test the code lacking such directory.

code from my old question (modified): DumpSave'ing while lengthy program runs

$\endgroup$
  • 1
    $\begingroup$ This is a bit over complicated, please see my response. $\endgroup$ – GenericAccountName Nov 9 '18 at 21:07
  • $\begingroup$ @GenericAccountName Good call to simplify that Do loop, i didn't have time to think about that. I made so many variables for the code to be readable. Thanks for pointing out the FileSystemMap, it seems very usefull. $\endgroup$ – Gladaed Nov 13 '18 at 12:26

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.