-
Notifications
You must be signed in to change notification settings - Fork 12
/
as_tutorial.m
180 lines (109 loc) · 5.46 KB
/
as_tutorial.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
%-------------------------------------------------------------------------%
% Name: as_tutorial. %
% Description: The purpose of this script is to help new users of AxonSeg %
% start exploring the functions and utilities. %
% %
% %
% %
%-------------------------------------------------------------------------%
%% PART 1 - SEGMENT AXONS AND MYELIN USING AxonSeg GUI
% load and display test image
test=imread('test_image_OM.tif');
figure; imshow(test);
% Use AxonSeg to perform axon and myelin on test image
AxonSeg test_image_OM.tif;
% After segmentation, the segmentation parameters is saved (SegParameters.mat) you can segment new images using:
AxonSeg('test_image_OM.tif','SegParameters.mat','-nogui');
%% PART 2 - EXPLORE AXONLIST STRUCTURE FOR MORPHOMETRY ANALYSIS OF THE DATA
load('axonlist.mat');
% Extract a specific stat (axon diameters) for all axons in axonlist
Axon_diameters = cat(1,axonlist.axonEquivDiameter);
% Plot distribution of stats in histogram (50 bins)
figure;
hist(Axon_diameters,50);
% Calculate stats of distribution
diam_mean=mean(Axon_diameters);
diam_median=median(Axon_diameters);
diam_std=std(Axon_diameters);
diam_max=max(Axon_diameters);
diam_min=min(Axon_diameters);
%% PART 3 - Filter final axonlist results depending on a parameter/feature
% Remove axons larger than a certain size (for example 10 um here) from the axonlist
axonlist([axonlist.axonEquivDiameter]>15)=[];
% Remove axons that have >50% of their myelin in conflict with their
% other axons
axonlist([axonlist.conflict]>0.5)=[];
% You can apply the same method in order to filter the axonlist based on a
% specific metric, for instance the gRatio here
axonlist([axonlist.gRatio]>0.9)=[];
% Remove false positive axons detected in the background
% --> Manually draw a Polygon on your image and get the index of the axons found in this region:
[Index, Stats] = as_stats_Roi(axonlist, img);
% --> Remove these axons
axonlist(Index)=[];
%% PART 4 - EXPLORE AXON AND MYELIN DISPLAY OPTIONS AVAILABLE
% Note: If your image is very big (>20 megapixels), go to the end of this
% section, otherwise you will experience memory saturation
% Produce an axon display colorcoded for axon diameter on initial gray
% image
axonseg_ind=as_display_label(axonlist,size(img),'axonEquivDiameter','axon');
rgb=sc(sc(axonseg_ind,'hot')+sc(img));
imshow(rgb);
% display myelin colorcoded for g-ratio
myelinseg_ind=as_display_label(axonlist,size(img),'gRatio','myelin');
rgb=sc(sc(myelinseg_ind,'hicontrast')+sc(img));
imshow(rgb);
% Save last display to current folder
imwrite(rgb,'gratio_rgb.png');
% Get the binary image of entire fibers (axon + myelin)
bw_axonseg_axons=as_display_label(axonlist,size(img),'axonEquivDiameter','axon');
bw_axonseg_myelins=as_display_label(axonlist,size(img),'axonEquivDiameter','myelin');
img_BW_fibers=im2bw(bw_axonseg_axons+bw_axonseg_myelins,0);
imshow(img_BW_fibers);
% FOR LARGE IMAGES: to prevent memory saturation:
[~, RGB_hot]=as_display_label(axonlist,size(img),'gRatio','myelin');
% enhance img contrast, convert to RGB and display
img =imadjust(img);
img = repmat(img,[1 1 3]);
as_display_LargeImage(.5*RGB_hot+.5*img) % zoom by drawing a square
%% PART 5 - Correct the axonal mask and redo the myelin segmentation with the modified mask
% If the axon segmentation is not good enough, you can manually correct it
% on another image processing software (for instance GIMP) by adding,
% removing or modifying the axon shapes. Then, you can segment the myelin
% again using the new axonal mask (axon_mask.tif).
AxonSeg({'test_image_OM.tif','axon_mask.tif'},'SegParameters.mat','-nogui');
% convert axonlist into excel file
axontable = struct2table(axonlist);
axontable.axonID=[];
axontable.data=[];
writetable(axontable);
%% PART 6 - SEGMENT ONLY AXONS
% In your SegParameters.mat structure, specify option to skip myelin segmentation
segParam.skipmyelin = true;
% Compute the axon segmentation mask
axon_mask=as_Segmentation(im_in,segParam);
% If needed, you can then launch the myelin segmentation on the axon segmentation mask obtained previously.
% Before, make sure you save the modified SegParameters.mat structure and the axonal mask as an image file.
AxonSeg({'img.png','axon_mask.png'}, 'SegParameters.mat', '-nogui');
%% PART 7 - ROI STATS EXTRACTION
% SOLUTION 1: MANUALLY DRAW A POLYGON ON YOUR IMAGE
[Index, Stats] = as_stats_Roi(axonlist, img);
% SOLUTION 2: CREATE A LOW RESOLUTION COLOR-CODED ATLAS OF THE DIFFERENT REGIONS (E.G. USING POWERPOINT) AND
% REGISTER THE MASK
% create and load a RGB mask with different ROIs
mask=imread('mask.png');
imshow(mask);
% Register the mask on the image
[mask_reg_labeled, P_color]=as_reg_mask(mask,img);
% Get indexes of axons belonging to each ROI of the mask in order to
% compute statistics
[indexes,mask_stats]=as_stats_mask_labeled_2(axonlist, mask_reg_labeled,PixelSize);
% Compute statistics for each ROI and plot results
as_stats_barplot_2(mask_stats,P_color);
%% PART 8 - MISC
% calculate myelin volume fraction (MVF) in an image
total_area=size(img,1)*size(img,2);
bw_axonseg=as_display_label(axonlist,size(img),'axonEquivDiameter','myelin');
img_BW_myelins=im2bw(bw_axonseg,0);
myelin_area=nnz(img_BW_myelins);
MVF=myelin_area/total_area;