LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

labview, working with pictures

Hi everyone! I have a small problem with one subtask. I think it can be solved quickly, but I don't know how :(.

I have a lot of pictures in one folder, they are all in the right order and called in the specific format "slice_1, slice_2,...,slice_N".

Also I have a for cycle with N iterations. My goal is to show a new picture on the new iteration in my labview program. However, in order to show a picture on the graph palette (For example), labview has always asked me to actually choose a specific picture using a mouse. When I created a file path control, I couldn't only choose a folder, I had to choose a specific picture. 

Imagine I have 100 iterations and 100 pictures. I can't choose a new picture every time by mouse. Can my program read pictures (and show them at the screen) in the folder consequentially, depending on the number of iteration? Could you give any tips or ideas, please? It would be very helpful!

 

Sorry for my english, hope you understood what I had meant

0 Kudos
Message 1 of 8
(1,824 Views)

Hi everyone! I have a small problem with one subtask. I think it can be solved quickly, but I don't know how :(.

I have a lot of pictures in one folder, they are all in the right order and called in the specific format "slice_1, slice_2,...,slice_N".

Also I have a for cycle with N iterations. My goal is to show a new picture on the new iteration in my labview program. However, in order to show a picture on the graph palette (For example), labview has always asked me to actually choose a specific picture using a mouse. When I created a file path control, I couldn't only choose a folder, I had to choose a specific picture.

Imagine I have 100 iterations and 100 pictures. I can't choose a new picture every time by mouse. Can my program read pictures (and show them at the screen) in the folder consequentially, depending on the number of iteration? Could you give any tips or ideas, please? It would be very helpful!

Sorry for my english, hope you understood what I had meant

0 Kudos
Message 2 of 8
(1,817 Views)

Your English is much better than my Russian (or other Slavic languages).  And your question is clear, and the solution (I think) is fairly simple.

 

Your task is to get an Array of Paths corresponding to a set of Image files (having a particular File Name pattern, and a particular extension) that live in a specified Folder.

 

Take a look at the File I/O Palette.  Nothing "obvious" is on the top level.  However, look at the Advanced File Functions at the bottom.  Do any of these functions look promising?  What about "List Folder"?  The Help says that it takes a Path (to a Folder) and returns two Arrays of Strings -- one with the sub-Folders (which you might not need) and another with the FileNames (also as a string).  Furthermore, there is a "Pattern" input, so you can ask it to give you all the "*.bmp" or "*.png" or "MyPix*.* FileNames.  I'm uncertain in what order it returns the names, but since they are returned as an Array of Strings, you can always write a Sorting Algorithm that sorts the String Array.

 

So now you have the Path to the folder, and an Array of Strings.  Sounds like time to drop down a For Loop, wire the Path and the Array (using the default Indexing Tunnel), combine them inside the loop with Build Path, and you'll have the Paths to all of your Images.

 

Bob Schor

 

P.S. -- no need to ask 4 times (though you might have had a "glitch" on the Forum from your end ...).

0 Kudos
Message 3 of 8
(1,779 Views)

@Bob_Schor wrote:

P.S. -- no need to ask 4 times (though you might have had a "glitch" on the Forum from your end ...).


(The forum was very glitchy this morning, but they just fixed it. I removed some of the duplicates above)

 

I'll add a few more comments:

 

How many images do you have, what are their sizes and at what rate do you want to display them later? Are all the same size? (If they are the same size and 8bit greyscale, you could read them all into a single 3D array, then index over it for display, etc.)

 

When you say that the images are "in the right order" that does not say much, because windows explorer can display them in many different ways. "List folder" will get them in alphabetical order, so if you want them sorted by creation time or size, additional code is needed. Also remember that sorting is alphabetically, not numerically (for example 12.png is before 2.png, while 02.png is before 12.png)

0 Kudos
Message 4 of 8
(1,763 Views)

Hi everyone! I have a small problem with one subtask. I think it can be solved quickly, but I don't know how :(.

I have a lot of pictures in one folder, they are all in the right order and called in the specific format "slice_1, slice_2,...,slice_N".

Also I have a for cycle with N iterations. My goal is to show a new picture on the new iteration in my labview program. However, in order to show a picture on the graph palette (For example), labview has always asked me to actually choose a specific picture using a mouse. When I created a file path control, I couldn't only choose a folder, I had to choose a specific picture.

Imagine I have 100 iterations and 100 pictures. I can't choose a new picture every time by mouse. Can my program read pictures (and show them at the screen) in the folder consequentially, depending on the number of iteration? Could you give any tips or ideas, please? It would be very helpful!

Sorry for my english, hope you understood what I had meant

0 Kudos
Message 5 of 8
(1,775 Views)

@LeonidLeites wrote:


I have a lot of pictures in one folder, they are all in the right order and called in the specific format "slice_1, slice_2,...,slice_N".
ant


As I said, pictures are sorted alphabetically, not numerically. So if you can have up to 999 pictures, you should name them slice_001, slice_002, slice_003, ....slice_100. You can of course sort your file names too, but that would require significantly more code.

0 Kudos
Message 6 of 8
(1,719 Views)

As you and Altenbach note, your file names are in the form "slice-<n>" where <n> is a string representing numbers from 1 to some higher number.  If you sort it as a string, "slice-2" will "sort" after "slice-11" or any 2, 3, ... number starting with 1 (e.g. 100000).

 

Here's one way I've used to handle such sorts.  Create a Sort Cluster with two elements -- an I32 called "number" and a string called "Slice ID".  Take your Array of filenames of the form "Slice-<n>" and create a corresponding Array of Sort Clusters:

  • "number" is the result of passing "Slice-<n>" through a Scan from String function whose Format String is "Slice-%d", i.e. the string "Slice-" followed by a decimal number.  Save the number in the "number" slot, and save the entire String in the "Slice ID" slot.
  • Sort the resulting Array of Clusters.  Because the first element of the Clusters are all (different) numbers, they will sort in "numeric" order.
  • Now pass the sorted Array of Clusters through another For loop and extract the "Slice ID" by itself, passing in through the output edge.

You now have your Array of Strings sorted in "numeric" rather than "string" order, as you wanted.

 

I've deliberately not attached the functions to do this -- you'll learn (and remember!) this technique if you try to implement it for yourself.  If you don't know about Clusters, this is an important topic that you need to learn.

 

Bob Schor

 

0 Kudos
Message 7 of 8
(1,669 Views)

If you know that all of the filenames are consecutive integers between 1 and N, where N is the number of files in the directory, you could also use a For loop and the "i" terminal (with Increment) and Build Path/Format String to get your array of paths.

 

If there's a chance that some slices are missing, or that you have extra files in the directory (README.txt, MyAwesomeLabNotebook.txt), then Bob Schor and altenbach's methods are much more robust.

In the "generated" filename case, you'd have to handle errors in the case of non-existent files if you have extra/missing slices.


GCentral
0 Kudos
Message 8 of 8
(1,666 Views)