forked from mporter-gre/mtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
distanceMeasure.m
104 lines (92 loc) · 3.75 KB
/
distanceMeasure.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function [roiIdx roishapeIdx badImage badCredentials data] = distanceMeasure(filepath, filename, credentials, fileNum, numFiles, conditionNum, numConditions, handles)
%Author Michael Porter
% Copyright (C) 2009-2014 University of Dundee.
% All rights reserved.
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
global client;
global session;
global gateway;
global fig1;
global ROIText;
global selectorOutput;
badImage = 0;
badCredentials = 0;
%Let the user know what's going on, position it in the centre of the screen...
scrsz = get(0,'ScreenSize');
fig1 = figure('Name','Processing...','NumberTitle','off','MenuBar','none','Position',[(scrsz(3)/2)-150 (scrsz(4)/2)-180 300 80]);
conditionText = uicontrol(fig1, 'Style', 'text', 'String', ['Condition ', num2str(conditionNum), ' of ' num2str(numConditions)], 'Position', [25 60 250 15]);
fileText = uicontrol(fig1, 'Style', 'text', 'String', ['ROI file ', num2str(fileNum), ' of ' num2str(numFiles)], 'Position', [25 35 250 15]);
drawnow;
try
[roiIdx roishapeIdx] = readROIs([filepath filename]);
catch
helpdlg(['There was a problem opening the ROI file ', filename, ', please check this file and retry it.', 'Problem']);
set(handles.beginAnalysisButton, 'Enable', 'on');
badImage = 1;
return;
end
% try
% gatewayConnect(credentials{1}, credentials{2}, credentials{3});
% catch
% helpdlg('Could not log you on to the server. Check your username and password');
% set(handles.beginAnalysisButton, 'Enable', 'on');
% badCredentials = 1;
% return;
% end
try
[pixelsId, imageName] = getPixIdFromROIFile([filepath filename], credentials{1}, credentials{3});
[imageName remain] = strtok(filename, '.');
catch
helpdlg(['Reference to ', filename, ' could not be found in your roiFileMap.xml. Please re-save the ROI file in Insight and try analysis again.']);
set(handles.beginAnalysisButton, 'Enable', 'on');
badImage = 1;
return;
end
pixelsId = str2double(pixelsId);
pixels = gateway.getPixels(pixelsId);
numChannels = pixels.getSizeC.getValue;
pixelsId = pixels.getId.getValue;
channelLabel{numChannels} = [];
for thisChannel = 1:numChannels
channelLabel{thisChannel} = session.getPixelsService.retrievePixDescription(pixelsId).getChannel(thisChannel-1).getLogicalChannel.getEmissionWave.getValue;
end
drawnow;
ROIText = uicontrol(fig1, 'Style', 'text', 'Position', [25 10 250 15]);
set(ROIText, 'String', 'Downloading image and segmenting...');
drawnow;
numROI = length(roiIdx);
for thisROI = 1:numROI
roishapeIdx{thisROI}.name = [imageName '_mask'];
roishapeIdx{thisROI}.origName = imageName;
end
freeMem = [];
for thisROI = 1:numROI
numROIZ = length(roishapeIdx{thisROI}.Z);
for thisChannel = 1:numChannels
for thisZ = 1:numROIZ
[planesThisROI{thisROI}{thisChannel}(:,:,thisZ)] = getPlaneFromPixelsId(pixelsId, roishapeIdx{thisROI}.Z(thisZ), thisChannel-1, 0);
end
end
end
data{numROI} = [];
for thisROI = 1:numROI
objectSelector(pixels, channelLabel, roishapeIdx{thisROI}, planesThisROI{thisROI}, credentials);
data{thisROI} = selectorOutput;
end
clear('planesThisROI');
close(fig1);
drawnow;
end