LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing to spreadsheet file in a loop?

Solved!
Go to solution

Hi,

 

I am trying to write a series of images to a spreadsheet file. It is basically a video that has about 540 frames each frame is 1780X500 pixels. I am running a for loop that takes acquires a frame from the stack of frames and writes it to a .txt file. This operation for the given file size takes about 2 mins for the writing process. I need the raw data so i cannot save the images in any other format. I am told that 2 mins is a long time to be saving a 9 sec video. 

 

I attached the code. Is there anything in the code that is slowing it down or is it running at speed limit. I am new to labview and I am not sure how I can speed this up. The write header is a custom VI that just creates a 6 line header to write in the beginning for each file. Any help is greatly appreciated

 

Thanks

0 Kudos
Message 1 of 11
(3,509 Views)

It does tend to take some time to write the data to disk.

It looks like you crop the image after converting it to an array. The "IMAQ image to array" has an optional rectangle input you can use to do this all in one step.

0 Kudos
Message 2 of 11
(3,486 Views)

Calling a PNG file a "LabVIEW Snippet" doesn't make it so!  A Snippet is created from the Block Diagram by selecting code and choosing "Make Snippet from Selection" from the Edit menu.  It may look like a .PNG file, but if you drag this to a LabVIEW Block Diagram, it will "open up" into working LabVIEW code, something your PNG file doesn't do.

 

I don't know the format of your Image, but why not write Images using an Image format, .jpg for stills, .avi for videos?  They are "designed" for images, and will undoubtedly be faster (and smaller) than writing text.  Indeed, you should be able to write a video file of 30 Frames/second to disk as fast as you acquire it.

 

Bob Schor

 

P.S. -- if you want more help on your code, post the code, not a picture of it.  You can also attach the VI directly ...

0 Kudos
Message 3 of 11
(3,482 Views)

A spreadsheet file is not really suitable for images. Why are you doing this? Is there some other software that needs to read it later?

 

You might also go over your code a little bit, for example your use of "insert into an empty array" is pure Rube Goldberg. You could just use a plain "build array" of height=1 to convert a scalar to a 1D array with one element. What's the purpose of the sequence structure? Where is the therminal for the "file path" control? Where is the "error out" terminal?

0 Kudos
Message 4 of 11
(3,460 Views)

As I said it is a video. I cannot save it as a video because most video formats will apply some compression and images are of bacteria so I really do need all the raw data. I have considered saving each frame as an image but that will lead to about 540 images in each experiment. and we do maybe 20 experiments in a day which would be about 2000 images. 

 

The sequence structure is for the whole take video operation. If you like i can attach the complete code. But it is a very big labview program so i just attached a picture of the part that i am having trouble with. As I said this was a part of a larger program and the error out and file path are local variables that are user inputs and outputs from the main program. The main VI has about 20 subVIs that are all interconnected. I am not sure if there is good way to give a complete picture without attaching all the VIs.

 

Thanks for the build array suggestion. I will put that in for sure.

0 Kudos
Message 5 of 11
(3,425 Views)

I need the raw data that is why I am not creating an AVI. The images are of bacteria and i cant afford to lose any information while converting to avi. I didnt do images because in a day I would get 2000 images which poses the problem of how to store and easily process such a large number of image files. I will be happy to make a "real" snippet if you think that will help you understand the program.

0 Kudos
Message 6 of 11
(3,411 Views)

I am not saying to create an AVI, but you could use a plain binary data structure. Not only would it be much more efficient and smaller, reading and writing would be much faster becasue there is no formatting.

0 Kudos
Message 7 of 11
(3,405 Views)

Altenbach,

 

I am not very familiar with technical language. What would be a plane binary data structure? Like a text file?

0 Kudos
Message 8 of 11
(3,402 Views)
Solution
Accepted by topic author Drew_2207

I assume that all  images are the same size and of the same datatype. You could just dump them to a binary file, because, given the sizes you can directly calculate the file location for each frame/pixel. there is no need for formatting or special termination character. No, this is not a "text" file because any byte from 0...255 is equally probably, not just the small subset of printable characters. 

 

(You really should take some LabVIEW tutorials. Whatever you are doing seems to be a straight translation from a bad text program. Why are none of your terminals connected to the code? Why is everything ripped apart by using local variables just to enforce execution order with gigantic sequence structures. Why do you use notifiers to synchronize two sequence trains while proper dataflow would enforce the execution order automatically. Properly written, this entire code could fit on the back of a postcard.

Wouldn't it be sufficient to optain the notifier once and then use the wire to the various locations?)

 

 

0 Kudos
Message 9 of 11
(3,397 Views)

Altenbach,

 

Unfortunately some of my predecessors wrote the code and I am having to edit it while also learning labview. I am trying to redo small parts of it at a time. At this time my priority is to figure out the writing the video part. Thanks for your binary file suggestion though. I will try to use that and hopefully speed things up.

 

0 Kudos
Message 10 of 11
(3,388 Views)