08-10-2017 07:36 PM - edited 08-10-2017 07:37 PM
Hi! Back in 2009 I learned a tiny little bit of LV 5.1 and wrote a simple VI to read an array of ints from a binary file and display it on an intensity graph:
I now need to re-create this functionality in LV 2016, but so much has changed that I don't even know where to begin. The basic functionality I need is this:
Can someone help me get started? Thanks!
C++-style file format follows, below:
struct IMGSTRUCT
{
char Title[8];
long x;
long y;
long nFrames;
long nType; //0 = float, 1 = word
long version;
long lPixelSkip;
long lLineSkip;
long numOfBits;
long lChannels;
float fPixelPeriod; //in nanoseconds
float fGain;
float fOffset;
long lMTFInfo;
float fPixelPitch;
//new items for version 4
DWORD dwDataStart;//starting offset to the data = IMGSTRUCT
float fVmin; //minimum input voltage to AD
float fVmax; //maximum input voltage to AD
BOOL bCDSenabled; //TRUE if CDS was enabled;
};
Solved! Go to Solution.
08-11-2017 01:11 AM - edited 08-11-2017 01:14 AM
08-11-2017 08:19 PM - edited 08-11-2017 08:21 PM
Thanks! I was trying to read it in as an array, instead of reading it in as a stream of Singles or U16s and then resizing the array as you've shown. I have it working now!
After much trial and error I also figured out how to read the header and use the X, Y, and dwDataStart data to set up the file read and array parameters successfully.
There are just 2 features that I'd like to add, but that I can't figure out:
Thanks!
08-12-2017 03:24 AM
08-13-2017 07:41 PM
Partial success! The Case structure worked as expected, and I can now choose either Type 1 or Type 0 files, and both graph properly.
I tried using an IndexArray to pick the Nth frame/page from a multi-frame file, but I'm getting garbage. Even a single-frame file displays incorrectly. This is supposed to look like the "Brother holding cat" photo, from above.
The VI is attached, and the binary data file is uploaded, here.
08-14-2017 12:57 AM - edited 08-14-2017 12:58 AM
Hi Waterbug,
the error is in the ReshapeArray to a 3D array.
Using the known approach to reshape to a 2D array works fine on your example data:
(Note the subtle changes I made to your VI… 😄 What's the purpose of a single frame flat sequence here?)
Do some debugging: try to load a multi-frame file and to find the correct conversion settings…
08-14-2017 02:34 PM
Thanks! Yes, the multiple outputs from the IndexArray really cleans things up.
I'm still struggling with the reduction to a single frame. If I read in a multi-frame data file, don't I need to read it in as a 3D array and then extract the Nth page from that?
My goal is to be able to allow the user to page through the frames by fiddling with the Frame # control, without having to reload the file every time. Someday I'd like to actually be able to play them back in a loop, just like a video.
I'd put the whole thing in a frame because when I hook this up to the data acquisition system later I'll want to run this continuously in a loop, with another frame triggering the acquisition system to read 1 page of data from hardware and write new data to a file. Someday^2 I'll figure out to pass the data by pointer with a callback (instead of with a file), but that's for much later.
For now I just have to demonstrate rudimentary control and import. And, as you can tell, I know very little about LabVIEW!
08-16-2017 02:30 PM
Fixed!
I had the dimensions wired in the wrong order. Frame, Y, X works:
I'd tried this once before, but I also had the Frame index wrong; it's zero-based, so when I left the default at 1, it didn't work on my single-frame files, which led me to believe that the problem _wasn't_ the index ordering.
So I had to fix both errors simultaneously, which took a lot of trial and error.
09-06-2017 02:37 PM - edited 09-06-2017 02:38 PM
Making more progress, here!
I've wired a horizontal Scrollbar to the IndexArray to choose the frame number, and I've put that in an Event structure to update any time the Scrollbar changes value. If you scroll through a 500 frame file (220 MB), the performance is quite reasonable.
But I still have some things I haven't figured out:
Many thanks to all who have contributed. It's been a great learning experience!