From 12:00 AM CDT Sunday, October 17 - 11:30 AM CDT Sunday, October 17, will be undergoing system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.


Showing results for 
Search instead for 
Did you mean: 

Read images from a folder

Go to solution

Hi! I have a folder containing several images, I need to select the first, read it, do some processing stuff and then pick up the second and do the same thing in a loop, how can I do that?




The images are called for example as:



"acquisitionL2-14-31-58" and so on...

when the last 3 numbers are hours/minutes/seconds of acquistion


I have Labview 2016 with vision toolbox 


0 Kudos
Message 1 of 11
-Use list folder function to get file names along with pattern as image type extension.
- Then use build path inside for loop to build path for each file.
- once you have array of paths then you can load them individually by the same logic which you have now.
- Remember me to keep some delay inside while loop else it will use most of course resources.
0 Kudos
Message 2 of 11

ok, thank you, it seems working

0 Kudos
Message 3 of 11

I did like this:




However I noticed just now that the order is:






aquisitionL122 ....








which is not correct : /


0 Kudos
Message 4 of 11

If you want to view the images in an order specified by an ordering of the filename, then you need to appropriately sort the list of filenames.  The list that you show is, in fact, "dictionary-sorted", since "3" comes after "123".  If you are making up the file names yourself and are "counting" them (1, 2, 3, ...), then you can use the count as part of the name if you format it with sufficient leading zeros.  That is, if you know you'll never have 1000 files, you could number them 001, 002, 003, etc., which puts 003 way before 123 and solves your "ordering" problem.  Otherwise, you'll need to parse (take apart) the name, find the numeric part, and sort on that (tricky coding).


Bob Schor

0 Kudos
Message 5 of 11

The problem is that filenames are already those and i cannot remake the experiment so can't generate new data with another name, so I have to handle with these names

0 Kudos
Message 6 of 11

I'm confused by your posts, as you seem to have two conflicting series of names for your files.  The original post suggested that the names were of the form <CommonTextString><Number>-<2-digit Hour>-<2-digit Minute>-<2-digit Second>.  The fact that the numbers following the CommonTextString (which is either "AcquisitionL" or "AquisitionL") are separated by hyphens makes parsing simpler.  The first number seems to be a sequence, suggesting that the remaining 3 can be ignored, but that's also not clear.


What do you want as a "sorting rule"?  I'm assuming that you are not renaming anything (despite the names in the second post being completely different from the names in the first).


A "trick" that can help with a "Parse-sort" is to take your array of Names and create an array of Clusters consisting of a (unique) number based on the Name, which I'll call the "Indexer", and the Name.  If the Indexer is the first element of the Cluster, then if you sort this array, you'll be sorting the Names as you want.  So in one For Loop, you take a Name, create the Cluster, and build the Array of Clusters, you sort the Cluster, then in the second For loop, you retrieve the Name part, ending with a (sorted) Array of Names.


So it call comes down to creating the Indexer.  Let's assume the format is the following:  "Bob2-9-11-12", where the name starts with "Bob", has a number representing who-knows-what (but first in sort order), then a time in H, M, S, all the numbers separated by hyphens.  Use Scan from String to isolate the four numbers -- if you feed the string in, use a Format string of "Bob%d-%d-%d-%d", and ask for four I32 outputs, you would get 2, 9, 11, 12.  Now you want a unique sortable number, which you can get by adding 2*1000000 + 9*10000 + 11*100 + 12 = 2091112.  Do you get the idea?


Bob Schor

0 Kudos
Message 7 of 11

Windows Explorer -> Right-click -> Rename


As it stands, that oder makes perfect sense.  Why can't you use basic Windows dunctionality to rename the files?


If you have a valid reason, it'll be on you to write a quick algorithm to sort through your array of names and put them in your desired order.

0 Kudos
Message 8 of 11

At the end I solved rearranging the strings in the order I wanted: Immagine.png

0 Kudos
Message 9 of 11
Accepted by topic author micheleG_Unipd

While I'm disappointed you didn't follow the suggestions for how to (easily) sort your set of filenames, you did seem to answer the question that the first number is, indeed, the index.  Just in case someone with a similar problem stumbles on this post and is tempted to use your awkward method, I'm posting what I (and others) had hoped you would try, a method that works even if (as in my simple example) some elements are missing.  Even you should admit this method is much simpler and easier to understand.

Sort Filenames.pngSort Filenames BD.png


Bob Schor

0 Kudos
Message 10 of 11