File Exchange

image thumbnail

Read / Write .SPE-files

version 1.0 (10 KB) by

This code allows reading/writing .SPE files.

4.66667
3 Ratings

21 Downloads

Updated

View License

This code provides for reading .SPE files (v2+), typically produced with Princeton Instruments camera systems. Its counterpart also allows for writing data into a valid SPE (v2) container.

Both functions are implemented similar to the build in MATLAB-functions: 'VideoReader' and 'VideoWriter'.

Comments and Ratings (9)

Dear all,

i'm trying to convert a multiple Tiff file into a multiple spe file.
The output file contains the good number of frames but (1) they is a rotation and (2) the data don't conrrespond to the original one...
Thanks for your help.

I'm using this code:

clear all
vidObj = SpeWriter('MyOutputFile.spe');
open(vidObj);

info = imfinfo('MyInputFile.tif');

[img_size1 img_size2 img_size3]=size(imread('MyInputFile.tif', 1, 'Info', info));
img_type=['uint' num2str(info(1).BitDepth)];

num_images = numel(info);

xyt_stack=zeros([img_size1 img_size2 num_images img_size3], img_type);
%preallocate array of correct type and size to improve speed

for k = 1:num_images
A = imread('MyInputFile.tif', k, 'Info', info);
for ch=1:size(A,3)
xyt_stack(:,:,k,ch)=A(:,:,ch);
writeVideo(vidObj,A(:,:,ch));
end
end

close(vidObj);

Adam Wright

Really useful, thanks!

I believe that the bug in which the image shifts with increasing frame number is a result of the code not accounting for the presence of metadata after each frame in a .SPE v3 file. I got rid of my offset by changing the line
seekstart = seekstart + frameskip*width*height*databytes;
to
seekstart = seekstart + frameskip*(width*height*databytes + 8*numMetaDataTypes);
where numMetaDataTypes is the integer number of metadata types stored for each frame - these can be seen by looking at the 'file information' of the .spe file in LightField.

Ding Zhong

I can not read the wavelength information (only number of counts can be read). Is it the way I call the function incorrect, or it is not supported?

Thanks, the reader component is very useful. But for multi-frame-SPE I encounter the same "bug" as Nick Sinclair. There is an images shift with increasing frame number (Matlab 2014a)
- edit: Seems like this problem occurs only, when there are timestamps in the spe-file itself

zhang xw

thanks

Nick Sinclair

Thanks. This has been very useful. I have only used the reader component, though.

I have encountered a bug in reading multi-frame SPE files. The images are being shifted off to the right with increasing frame#, by about 4 pixels per frame. This is for SpeFormat version 3.0, Matlab version 2014b.

Tomasz

Tomasz (view profile)

And @239 change frameWidth <-> frameHeight, like that:
[frameWidth, frameHeight] = SpeWriter.getFrameSize(frame);

Apologize for spam, but I can't edit my previous post.

Tomasz

Tomasz (view profile)

Probably I found a bug.
In SpeWriter, @function writeFrames @351 line should be:
height = size(frames,2) % change 1 -> 2

and @359 line:
width = size(frames,1); % change 2 -> 1

now (in my case) is OK.

Felix

Felix (view profile)

This does not work. SOpa

MATLAB Release
MATLAB 7.13 (R2011b)
Acknowledgements

Inspired by: readSPE

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video