-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInitial_Image_Analysis.m
More file actions
172 lines (141 loc) · 5.38 KB
/
Copy pathInitial_Image_Analysis.m
File metadata and controls
172 lines (141 loc) · 5.38 KB
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
162
163
164
165
166
167
168
169
170
171
172
out
%% Load in Data
data.('name') = 'Cropped_fiber_matrix_S_400_400'
data.('local') = '_data/Cropped_fiber_matrix_400_400.mat'
data.('header') = '_data/Cropped_fiber_matrix_400_400.mat.json'
% Mat variable name called cropped
load( data.local);
cropped = double( cropped );
data.('voxels').('min') = min( cropped(:)) ;
data.('voxels').('max') = max( cropped(:)) ;
data.('voxels').('mean') = mean( cropped(:)) ;
data.('voxels').('std') = std( cropped(:)) ;
data.('voxels').('size') = size( cropped) ;
s = savejson( [], data );
fo = fopen( data.header, 'w'); fwrite( fo, s ); fclose(fo);
%% Visualization Tools
% Vol3d
% Sliceomatic
%% Visualize Faces
pcolor( squeeze( cropped(:,:,1) ));
shading flat;
axis equal;
colorbar;
colormap gray;
saveas(gcf, './assets/S_topslice-xy.png' );
data.('images').('top')(1) = struct( 'src', '/assets/S_topslice-xy.png', 'description', 'Top XY Slice of Sample Image' );
pcolor( squeeze( cropped(:,1,:) ));
shading flat;
axis equal;
colorbar;
colormap gray;
saveas(gcf, './assets/S_topslice-xz.png' );
data.('images').('top')(2) = struct( 'src', '/assets/S_topslice-xz.png', 'description', 'Top XZ Slice of Sample Image' );
pcolor( squeeze( cropped(1,:,:) ));
shading flat;
axis equal;
colorbar;
colormap gray;
saveas(gcf, './assets/S_topslice-yz.png' );
data.('images').('top')(3) = struct( 'src', '/assets/S_topslice-yz.png', 'description', 'Top YZ Slice of Sample Image' );
s = savejson( [], data );
fo = fopen( data.header, 'w'); fwrite( fo, s ); fclose(fo);
%% Visualize Slices
pcolor( squeeze( cropped(:,:,round(size(cropped,3)./2)) ));
shading flat
axis equal;
colorbar
colormap gray
saveas(gcf, './assets/midslice-xy.png' )
data.('images').('mid')(1) = struct( 'src', '/assets/midslice-xy.png', 'description', 'Middle XY Slice of Sample Image' )
pcolor( squeeze( cropped(:,round(size(cropped,2)./2),:) ));
shading flat
axis equal;
colorbar
colormap gray
saveas(gcf, './assets/midslice-xz.png' )
data.('images').('mid')(2) = struct( 'src', '/assets/midslice-xz.png', 'description', 'Middle XZ Slice of Sample Image' )
pcolor( squeeze( cropped(round(size(cropped,1)./2),:,:) ));
shading flat
axis equal;
colorbar
colormap gray
saveas(gcf, './assets/midslice-yz.png' )
data.('images').('mid')(3) = struct( 'src', '/assets/midslice-yz.png', 'description', 'Middle YZ Slice of Sample Image' )
s = savejson( [], data )
fo = fopen( data.header, 'w'); fwrite( fo, s ); fclose(fo);
%% Image Histogram
cropped = double(cropped);
[yy,xx] = hist( cropped(:),151);
[ax, h1,h2] = plotyy( xx, yy,... Plot distribution
xx, [gradient(yy); gradient(gradient(yy))] ... Plot gradients of distribution
);
figure(gcf)
% set(gca,'Yscale','log')
legend([h1;h2], 'Raw','First Derivative','Second Derivative');
grid( ax(1), 'on');
set( [h1;h2], 'LineWidth',3);
set( ax,'Fontsize',16);
ylabel(ax(1), 'Raw Data');
ylabel(ax(2), 'Gradients');
saveas( gcf,'./assets/raw-image-stats.png');
data.('images').('distribution') = struct( 'src', '/assets/raw-image-stats.png', 'description', 'This distribution of pixels values and their gradients.' )
s = savejson( [], data )
fo = fopen( data.header, 'w'); fwrite( fo, s ); fclose(fo);
%% Peak fitting
figure
[yy,xx] = hist( cropped(:),151)
[ p,e ]= peakfit( [xx;yy], 0,0,2,1 );
saveas( gcf,'./assets/2_peak_fit_N.png')
data.('images').('Peak_fit2') = struct( 'src', '/assets/2_peak_fit_S.png', 'description', 'This is the peak fit using 2 peaks.' )
figure
[yy,xx] = hist( cropped(:),151)
[ p,e ]= peakfit( [xx;yy], 0,0,3,1 );
saveas( gcf,'./assets/3_peak_fi-N.png')
data.('images').('Peak_fit3') = struct( 'src', '/assets/3_peak_fit_S.png', 'description', 'This is the peak fit using 3 peaks.' )
s = savejson( [], data )
fo = fopen( data.header, 'w'); fwrite( fo, s ); fclose(fo);
%% Using imadjust
%%
[yy,xx] = hist( cropped(:),151)
[ p,e ]= peakfit( [xx;yy], 0,0,3,1 );
figure(gcf);
grid on
hold( gca, 'on')
GRADE = [ gradient(yy); gradient(gradient(yy)) ];
%%%%%%%%%% NORMALIZE GRADIENTS FOR VISUALIZATION ONLY!
% The range of error values in the peak fit plot is orders of magnitude
% less than the gradients. The normalization allows them to be viewed
% simultaneously. We are not relying on the magnitudes of the gradients in
% this plot.
dGradient = diff([min(GRADE(:)),max(GRADE(:))])
dScale = diff( ylim( gca ) );
GRADEPLOT = GRADE .* dScale./dGradient;
%%%%%%%%%%
% h = plot( gca, xx, GRADEPLOT, ... Plot gradients of distribution
% 'LineWidth',3)
hold off
% legend( h, 'First Gradient', 'Second Gradient' )
set( gcf, 'Position', get(0,'ScreenSize')./[ 1 1 2 1] )
saveas( gcf,'./assets/peak-fit-test.png')
data.('images').('peaks') = struct( 'src', '/assets/peak-fit-test.png', 'description', 'Peak fitting of the histogram generated from a 3-D volume.' )
%% Using IM adjust
normalize = @(A)( A-min(A(:)) ) ./ ( max(A(:)) - min(A(:)) )
adjust = @(A)reshape( ... back to original shape
imadjust( ... adjust image
reshape( ... flatten to 2-D image
normalize(A), ... normalize from zero to one
size(A,1), numel(A)./size(A,1))), ... Reshape to 2-D array
size(A) ... Reshape back to original size
);
%%
return
bnds = 6000
for ll = [100 + [-1:1]; [1:3]];
subplot(1,3,ll(2))
pcolor( double( cropped(:,:,ll(1)) > bnds(1) & cropped(:,:,ll(1)) > bnds(1) ) .* cropped(:,:,ll(1)) );
shading flat
axis equal
colorbar
end
figure(gcf)