-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhist_image_batch.m
138 lines (92 loc) · 4.94 KB
/
hist_image_batch.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
close all
clear all
srcFile = dir('D:\swarang\golgi_membrane\Analysis-Cells-16022021\Doxorubicin-20-nM-120-hours-18-hours-Cycloheximide-+ve\*.tif');
image_folder ='D:\swarang\golgi_membrane\Analysis-Cells-16022021\Doxorubicin-20-nM-120-hours-18-hours-Cycloheximide-+ve\'
%specify folder for saving
% memb_save_folder = 'D:\swarang\golgi_membrane\yo\Analysis-Cells-16012021\trial_run\memb_data';
% golgi_save_folder = 'D:\swarang\golgi_membrane\yo\Analysis-Cells-16012021\trial_run\golgi_data';
for n=1:length(srcFile)
% baseFileName="Cell4"
% FileName=baseFileName+'.tif'
% change this to the file name of image file
FileName = strcat(image_folder,srcFile(n).name);
% read image and split channels
I1=imread(FileName,1);
I2=imread(FileName,2);
% maxI1=max(I1, [], 'all')
% maxI2=max(I2, [], 'all')
% max_absolute=max(maxI1,maxI2)
% --------------------------------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%% GOLGI SECTION %%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------------------------------------
[level,metric] = multithresh(I2); %multi level thresholding of red (golgi) channel
seg_I2 = imquantize(I2,level);
RGB = label2rgb(seg_I2);
% figure;
% % imshow(seg_I2,[])
% imshow(RGB)
seg=seg_I2-1;
% var_golgi = (immultiply(uint16(seg_I2),I1))./2; %multiply sugmented red channel with original green channel
golgi = immultiply(uint16(seg),I1);
max_golgi=max(golgi, [], 'all')
% max_golgi=max(var_golgi, [], 'all')
% golgi=var_golgi./max_golgi;
% figure
% imshow(golgi,[])
% file=golgi;
% imwrite(file,baseFileName+'golgi','tiff'); %write segmented golgi (red) channel image to a tiff file
% --------------------------------------------------------------------------------------------------
%%%%%%%%%%%%%%%% MEMBRANE SECTION %%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------------------------------------
Golgi_rem_Image=I1-(golgi);
% figure;
% imshow(Golgi_rem_Image,[])
% Get the green channel.
% imhist(grayImage);
% Get a binary image.
mask = Golgi_rem_Image > 100;
% Take only the largest blob. Use 4-connectivity.
mask = bwareafilt(mask, 1, 4);
% To find the average length and width we need to get the Euclidean distance transform and the skeleton of it.
edtImage = bwdist(~mask);
edtImage=edtImage./max(edtImage,[],'all');
% var_memb = (immultiply(uint16(edtImage),I1))./(2^4);
memb = immultiply(uint16(edtImage),Golgi_rem_Image);
max_memb=max(memb, [], 'all')
% max_memb=max(var_memb, [], 'all')
% memb=var_memb./max_memb;
% figure
% imshow(memb,[]);
path=strcat(image_folder, srcFile(n).name)
% path_memb=strcat(memb_save_folder, srcFile(n).name)
% path_golgi=strcat(golgi_save_folder, srcFile(n).name)
mean_memb_arr=[]
% %%%%%%%%%% MEMBRANE HISTOGRAM %%%%%%%%%%
figure
h_memb=histogram(memb,'BinWidth',5, 'BinLimits',[1,4090]) %plot histogram of membrane
title(string(srcFile(n).name) + ' histogram of membrane')
data_memb = h_memb.Values;
counts_memb = data_memb;
centerBinGrayLevels_memb = (h_memb.BinEdges(1:end-1) + h_memb.BinEdges(2:end)) / 2;
meanBinnedGrayLevel_memb = sum(centerBinGrayLevels_memb .* counts_memb) / sum(counts_memb)
mean_memb_arr = [mean_memb_arr, meanBinnedGrayLevel_memb];
xline(meanBinnedGrayLevel_memb, 'Color', 'g', 'LineWidth', 2);
saveas(gcf, string(path)+'_memb_mean.png')
close
% %%%%%%%%%% GOLGI HISTOGRAM %%%%%%%%%%
figure
h_golgi=histogram(golgi,'BinWidth',5, 'BinLimits',[1,4090]) %plot histogram of golgi
title(string(srcFile(n).name) +' histogram of golgi')
data_golgi = h_golgi.Values;
counts_golgi = data_golgi;
centerBinGrayLevels_golgi = (h_golgi.BinEdges(1:end-1) + h_golgi.BinEdges(2:end)) / 2;
meanBinnedGrayLevel_golgi = sum(centerBinGrayLevels_golgi .* counts_golgi) / sum(counts_golgi)
xline(meanBinnedGrayLevel_golgi, 'Color', 'r', 'LineWidth', 2);
saveas(gcf, string(path) + '_golgi_mean.png')
close
% data_golgi_filename=string(path_golgi)+'.csv';
% data_memb_filename=string(path_memb)+'.csv';
csvwrite(string(path)+'_golgi_data.csv', transpose(data_golgi));
csvwrite(string(path)+'_memb_data.csv', transpose(data_memb));
end
% imwrite(memb,baseFileName+'membrane.tif','tiff')