-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXT3DCells.m
executable file
·139 lines (123 loc) · 4.43 KB
/
XT3DCells.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
% ImarisXT3DCells for Imaris 7.6.5
%
%
%
% Installation:
%
% - Copy this file into the XTensions folder in the Imaris installation directory
% - You will find this function in the Image Processing menu
%
% <CustomTools>
% <Menu>
% <Submenu name="Mouse">
% <Item name="Cells segmentation" icon="Matlab" tooltip="Detects the cells using a membrane marker">
% <Command>MatlabXT::XT3DCells(%i)</Command>
% </Item>
% </Submenu>
% </Menu>
% </CustomTools>
%
%
% Description:
%
% This XTension detects the cells using a membrane marker.
%
%
function XT3DCells(aImarisApplicationID) % ID corresponds to Imaris instance
if isa(aImarisApplicationID, 'Imaris.IApplicationPrxHelper')
vImarisApplication = aImarisApplicationID;
else
% Connect to Imaris interface
if exist('ImarisLib','class') == 0
javaaddpath ImarisLib.jar
end
vImarisLib = ImarisLib;
if ischar(aImarisApplicationID)
aImarisApplicationID = round(str2double(aImarisApplicationID));
end
vImarisApplication = vImarisLib.GetApplication(aImarisApplicationID);
end
% Get the dataset and the scene
aSurpassScene = vImarisApplication.GetSurpassScene;
aDataSet = vImarisApplication.GetDataSet.Clone;
sizeC = aDataSet.GetSizeC;
sizeT = aDataSet.GetSizeT;
%% Channel colors
% Red - Green - Blue - Magenta
rgbm = zeros(4,1);
for i=0:sizeC-1
rgba = aDataSet.GetChannelColorRGBA(i);
switch rgba
case 255
rgbm(1) = i+1;
case 65280
rgbm(2) = i+1;
case 16711680
rgbm(3) = i+1;
case 16711935;
rgbm(4) = i+1;
end
end
%% User interface
% We have the user select which channel corresponds to the DNA
name='Parameters';
numlines=1;
prompt={'Enter the channel number of the membranes (green):'};
prompt{2} = 'Enter the channel number of the (red) marker to quantify (0 if none):';
prompt{3} = 'Enter the DAPI (blue) channel number (0 if no blue):';
prompt{4} = 'Enter the magenta channel number (0 if no magenta):';
prompt{5} = 'Enter the approximate cell size: (diameter / µm)';
if sizeT > 1
prompt{6} = 'Enter the maximum search distance (tracking)';
end
defaultanswer={num2str(rgbm(2))};
defaultanswer{2}=num2str(rgbm(1));
defaultanswer{3}=num2str(rgbm(3));
defaultanswer{4}=num2str(rgbm(4));
defaultanswer{5}='10';
defaultanswer{6}='3';
% We retrieve the answers
answer=inputdlg(prompt,name,numlines,defaultanswer);
if isempty(answer)
return;
end
rgbm(1)=floor(str2double(answer{2})-1); % Red Channel
rgbm(2)=floor(str2double(answer{1})-1); % Green Channel
rgbm(3)=floor(str2double(answer{3})-1); % Blue Channel
rgbm(4)=floor(str2double(answer{4})-1); % Magenta Channel
cellsSize = str2double(answer{5});
% We rectify incorrect answers
rgbm(rgbm < 0) = -1;
rgbm(rgbm >= sizeC) = -1;
%% Smoothing
aSize = [5 5 1];
vImarisApplication.GetImageProcessing.GaussFilterChannel(aDataSet,rgbm(2),0.3);
vImarisApplication.GetImageProcessing.MedianFilterChannel(aDataSet,rgbm(2),aSize);
% if rgbm(2) >= 0
% vImarisApplication.GetImageProcessing.MedianFilterChannel(aDataSet,rgbm(2),aSize);
% end
%% Inverting
vImarisApplication.GetImageProcessing.InvertChannel(aDataSet,rgbm(2));
%% Segmentation
unit = aDataSet.GetUnit;
% DAPI Filter
blueFilter = '';
if rgbm(3) >= 0 && rgbm(3) < sizeC
blueFilter = [' "Intensity Mean Ch=',num2str(rgbm(3)+1),'" above automatic threshold'];
end
% Imaris Surfaces
aSurface = vImarisApplication.GetImageProcessing.DetectSurfacesRegionGrowing(aDataSet,[],rgbm(2),0.3,0,1,0,cellsSize,1,...
'"Quality" above 0', ...
['"Number of Voxels" between 10000 and automatic threshold'...
blueFilter, ...
' "Distance to Image Border XY" above ' num2str(cellsSize) ' ' char(unit)]);
% Put object in the scene
aRGBA=aDataSet.GetChannelColorRGBA(rgbm(2));
aSurface.SetColorRGBA(aRGBA);
aSurface.SetName('Cells');
aSurpassScene.AddChild(aSurface,-1);
%% Re-Inverting
vImarisApplication.GetImageProcessing.InvertChannel(aDataSet,rgbm(2));
%% Add stats
XT3DCells_distance(aImarisApplicationID);
end