Skip to content

Commit 6323781

Browse files
committed
Squashed '@TIFFStack/' changes from 9e73c53..e80689f
e80689f Merge branch 'pr5' f72457e * Added an overloaded `saveobj` method, to ensure object is serialised correctly, and to ensure that `delete` doesn't get called on a loaded object * `TS_UnitTest` now tests saving and loaded of a `TIFFStack` * Upgraded `tiffread` to version 3.31 0e3df90 Add loadobj method, useable with default saveobj 5db9a02 Added licensing information to `README.md` and `LICENSE.md` git-subtree-dir: @tiffstack git-subtree-split: e80689f4f6a222b3f011d2be125ff8e4f28d5269
1 parent 95b726b commit 6323781

File tree

8 files changed

+895
-561
lines changed

8 files changed

+895
-561
lines changed

LICENSE.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## License
2+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">TIFFStack</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://dylan-muir.com" property="cc:attributionName" rel="cc:attributionURL">Dylan Muir</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://github.com/DylanMuir/TIFFStack" rel="dct:source">http://github.com/DylanMuir/TIFFStack</a>.
3+
4+
This work was published in [Frontiers in Neuroinformatics]: DR Muir and
5+
BM Kampa. 2015. *[FocusStack and StimServer: A new open source MATLAB
6+
toolchain for visual stimulation and analysis of two-photon calcium
7+
neuronal imaging data](http://dx.doi.org/10.3389/fninf.2014.00085)*, **Frontiers in Neuroinformatics** 8 *85*. DOI: [dx.doi.org/10.3389/fninf.2014.00085](http://dx.doi.org/10.3389/fninf.2014.00085).
8+
Please cite our publication in lieu of thanks, if you use this code.
9+
10+
[Frontiers in Neuroinformatics]: http://www.frontiersin.org/neuroinformatics

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ reading and caching the header information (the image file directories —
141141
IFDs). Each frame can then be read directly without re-opening the file
142142
and re-reading the IFDs.
143143

144+
## License
145+
<a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/80x15.png" /></a><br /><span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">TIFFStack</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://dylan-muir.com" property="cc:attributionName" rel="cc:attributionURL">Dylan Muir</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License</a>.<br />Based on a work at <a xmlns:dct="http://purl.org/dc/terms/" href="http://github.com/DylanMuir/TIFFStack" rel="dct:source">http://github.com/DylanMuir/TIFFStack</a>.
146+
144147
[Frontiers in Neuroinformatics]: http://www.frontiersin.org/neuroinformatics
145148
[FFSS]: http://journal.frontiersin.org/Journal/10.3389/fninf.2014.00085
146149
[10.1103/PhysRevLett.86.3192]: //dx.doi.org/10.1103/PhysRevLett.86.3192

TIFFStack.m

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,15 @@
144144
end
145145

146146
properties (SetAccess = private, GetAccess = private)
147+
bForceTiffread % - Force the use of tiffread, rather than trying to use TiffLib
147148
vnDataSize; % - Cached size of the TIFF stack
148149
vnApparentSize; % - Apparent size of the TIFF stack
149150
TIF; % \_ Cached header info for tiffread29 speedups
150151
HEADER; % /
151152
bUseTiffLib; % - Flag indicating whether TiffLib is being used
152153
fhReadFun; % - When using Tiff class, function for reading data
153154
fhSetDirFun; % - When using Tiff class, function for setting the directory
154-
vnDimensionOrder; % - Internal dimensions order to support permution
155+
vnDimensionOrder; % - Internal dimensions order to support permutation
155156
fhRepSum; % - Function handle to (hopefully) accellerated repsum function
156157
fhCastFun; % - The matlab function that casts data to the required return class
157158
end
@@ -170,6 +171,7 @@
170171
if (~exist('bForceTiffread', 'var') || isempty(bForceTiffread))
171172
bForceTiffread = false;
172173
end
174+
oStack.bForceTiffread = bForceTiffread;
173175

174176
% - Can we use the accelerated TIFF library?
175177
if (exist('tifflib') ~= 3) %#ok<EXIST>
@@ -340,10 +342,10 @@
340342

341343
else
342344
% - Read TIFF header for tiffread29
343-
[oStack.TIF, oStack.HEADER] = tiffread29_header(strFilename);
345+
[oStack.TIF, oStack.HEADER] = tiffread31_header(strFilename);
344346

345347
% - Use tiffread29 to get the data class for this tiff
346-
fPixel = tiffread29_readimage(oStack.TIF, oStack.HEADER, 1);
348+
fPixel = tiffread31_readimage(oStack.TIF, oStack.HEADER, 1);
347349
fPixel = fPixel(1, 1, :);
348350
oStack.strDataClass = class(fPixel);
349351
end
@@ -727,8 +729,36 @@ function diagnostic(oStack)
727729
oStack.bInvert = bInvert;
728730
end
729731
end
732+
733+
734+
%% --- Overloaded save method
735+
% saveobj - Save method
736+
function sSerialised = saveobj(tsStack)
737+
% - Serialise object and remove transient properties
738+
w = warning('off', 'MATLAB:structOnObject');
739+
sSerialised = struct(tsStack);
740+
sSerialised = rmfield(sSerialised, {'TIF', 'HEADER', 'fhReadFun', 'fhSetDirFun', 'fhRepSum', 'fhCastFun'});
741+
warning(w);
742+
end
730743

731744
end
745+
746+
%% -- Overloaded load method
747+
748+
methods (Static)
749+
750+
% loadobj - Load method
751+
function oStack = loadobj(sSavedVar)
752+
% - Create a new TIFFStack
753+
oStack = TIFFStack(sSavedVar.strFilename, sSavedVar.bInvert, [], ...
754+
sSavedVar.bForceTiffread);
755+
756+
% - Adjust dimensions to look like saved stack
757+
oStack.vnApparentSize = sSavedVar.vnApparentSize;
758+
oStack.vnDimensionOrder = sSavedVar.vnDimensionOrder;
759+
end
760+
761+
end
732762
end
733763

734764
%% --- Helper functions ---
@@ -771,7 +801,7 @@ function diagnostic(oStack)
771801

772802
% - Read data block
773803
try
774-
tfDataBlock = tiffread29_readimage(oStack.TIF, oStack.HEADER, vnFrameIndices);
804+
tfDataBlock = tiffread31_readimage(oStack.TIF, oStack.HEADER, vnFrameIndices);
775805

776806
catch mErr
777807
% - Record error state

private/TS_UnitTest.m

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
function TS_UnitTest(strFilename)
1515
% - Make sure TIFFStack is on the path
1616
strTSDir = fileparts(which('TIFFStack'));
17+
18+
if (isempty(strTSDir))
19+
error('TIFFStack:Path', '*** Error: ''TIFFStack'' is not available on the matlab path.');
20+
end
21+
1722
strBaseDir = fileparts(strTSDir);
1823
addpath(strBaseDir);
1924

@@ -73,12 +78,12 @@ function TS_UnitTest(strFilename)
7378
TSUT_TestReferencing(tsStack, tfStack, 'Raw stack');
7479

7580
%% - Test permuted stack
76-
tsStack = permute(tsStack, [3 1 2]);
77-
tfStack = permute(tfStack, [3 1 2]);
81+
tsStack = permute(tsStack, [3 1 2 4]);
82+
tfStack = permute(tfStack, [3 1 2 4]);
7883
TSUT_TestReferencing(tsStack, tfStack, 'Simple permutation');
79-
tsStack = ipermute(tsStack, [3 1 2]);
80-
tfStack = ipermute(tfStack, [3 1 2]);
81-
84+
tsStack = ipermute(tsStack, [3 1 2 4]);
85+
tfStack = ipermute(tfStack, [3 1 2 4]);
86+
8287
%% - Test inverted stack
8388
tsStack.bInvert = true;
8489
tfStack = 255 - tfStack;
@@ -98,6 +103,12 @@ function TS_UnitTest(strFilename)
98103
tfStack = reshape(tfStack, [size(tfStack, 1) size(tfStack, 2) 1 1 nNumFrames size(tfStack, 4)]);
99104
TSUT_TestReferencing(tsStack, tfStack, 'Deinterleaved stack');
100105

106+
%% - Test saving / loading a stack
107+
strMatFile = tempname;
108+
save(strMatFile, 'tsStack');
109+
s = load(strMatFile);
110+
TSUT_TestReferencing(tsStack, s.tsStack, 'Serialised/Deserialised stack');
111+
101112
%% - Success if we reach here with no errors
102113
disp('--- TS_UnitTest: Unit tests for ''TIFFStack'' passed.');
103114
end

0 commit comments

Comments
 (0)