-
Notifications
You must be signed in to change notification settings - Fork 0
/
splitScan.m
73 lines (63 loc) · 2.38 KB
/
splitScan.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
function [] = splitScan(infile, varargin)
% Example command to divide infile scan into 16 quadrants and save to
% outDir:
% splitScan('pathToInfile', 'splitX', 4, 'splitY', 4, 'outDir', 'splitScans')
p = inputParser;
p.addRequired('infile', @ischar);
p.addParameter('splitX', 4, @isnumeric);
p.addParameter('splitY', 4, @isnumeric);
p.addParameter('outDir', '', @ischar);
p.parse(infile, varargin{:});
infile = p.Results.infile;
splitX = p.Results.splitX;
splitY = p.Results.splitX;
if ~isempty(p.Results.outDir)
outDir = p.Results.outDir
else
[path, name, ext] = fileparts(infile);
outDir = sprintf('%s_splitScan', name)
end
if ~exist(outDir, 'dir')
mkdir(outDir)
end
reader = bfGetReader(infile);
omeMeta = reader.getMetadataStore();
dimensionX = omeMeta.getPixelsSizeX(0).getValue();
dimensionY = omeMeta.getPixelsSizeY(0).getValue();
wavelengths = omeMeta.getPixelsSizeC(0).getValue();
width = floor(dimensionX/splitX+1);
height = floor(dimensionX/splitY+1);
stepsX = floor(linspace(1, dimensionX-width, splitX+1));
stepsY = floor(linspace(1, dimensionY-height, splitY+1));
for i = 1:numel(stepsX)-1
for ii = 1:numel(stepsY)-1
for iii = 1:wavelengths
reader.setSeries(0); %Can change this for multipoint scans
iPlane = reader.getIndex(0, iii - 1, 0) + 1;
tmpPlane = bfGetPlane(reader, iPlane, stepsX(i), stepsY(ii),width,height);
imwrite(tmpPlane, fullfile(outDir, sprintf('xDim%d_yDim%d_channel%d.tiff', i, ii, iii)))
end
end
end
end
%% For testing
% testFile = '10X10Scan20X001.nd2';
% reader = bfGetReader(testFile);
% omeMeta = reader.getMetadataStore();
%
% splitX = 3;
% splitY = 3;
%
% dimensionX = omeMeta.getPixelsSizeX(0).getValue();
% dimensionY = omeMeta.getPixelsSizeY(0).getValue();
% wavelengths = omeMeta.getPixelsSizeC(0).getValue();
%
% width = floor(dimensionX/splitX+1);
% height = floor(dimensionX/splitY+1);
%
% stepsX = floor(linspace(1, dimensionX-width, splitX+1));
% stepsY = floor(linspace(1, dimensionY-height, splitY+1));
%
% reader.setSeries(0); %Can change this for multipoint scans
% iPlane = reader.getIndex(0, 6 - 1, 0) + 1;
% tmpPlane = bfGetPlane(reader, iPlane, stepsX(2), stepsY(2),width,height);