-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_tensors.m
More file actions
142 lines (109 loc) · 4.5 KB
/
Copy pathmap_tensors.m
File metadata and controls
142 lines (109 loc) · 4.5 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
close all, clear all, clc;
% disp(sprintf('Processing Exp # %d, Cond: %d, Video: %d, Frame %d', i, j, n, k));
folder = '/Use/z'[9] C3 HD70 10^-5 M'}; %'[7] A3 HD70 CN'}; %,'[8] A3 HD70 10^-4 M',...
% '[9] C3 HD70 10^-5 M'};
file_info = {};
for i = 1:length(experimental_dirs)
for j = 5
vid_numbers = {'1','2','3','4','5'};
cd(strcat(basefolder, experimental_dirs{i},'/', vid_numbers{j}));
imgs = dir('I*.jpg');
for k = 1:length(imgs)
% close all;
img = imread(imgs(k).name);
img = rgb2gray(img);
img_adjust = imfilter( img, ...
fspecial( 'gaussian', 7 ), ...
'symmetric' ); %(1+2*2*filtSize)
figure; imshow(img);
temp = entropyfilt( img_adjust, true((3)) );
temp = temp - min(min( temp ));
temp = temp ./ max(max( temp ));
imshow(temp);
keyboard
temp = imopen( temp, ...
strel('disk',7) );
imshow(temp);
keyboard;
temp = temp >= 0.45; % binarize
imshow(temp);
keyboard;
temp = imfill(temp, 'holes');
imshow(temp);
keyboard;
% temp = bwareaopen(temp, 3000);
% figure(f2), imshow(temp);
% temp = imerode(temp, strel('disk',1));
% figure(f2), imshow(temp);
img_final = bwareaopen(temp, 2000);
% f1 = figure;
% f2 = figure;
% figure(f1), imshow(img);
% figure(f2), imshow(img_final);
% keyboard;
% end
% Uncomment for plotting boundary pixels for image mask
keyboard;
boundary.x = bwmorph(img_final, 'remove');
[row,col] = find(boundary.x);
% imshow(img); hold on;
% plot(col, row, '.c');
% Uncomment to view boundary outlines on original image
% boundary(i).x = bwmorph(img_final, 'remove');
% [row,col] = find(boundary(i).x);
% fig = figure;
imshow(img); hold on;
plot(col, row, '.c');
export_fig(sprintf('boundary %d.jpg',b));
keyboard;
% close all;
% figure; imshow(img);
% close all;
% % double comment for connected component analysis
cc = bwconncomp(img_final);
C(k).x = regionprops(cc,'centroid');
B(k).x = regionprops(cc,'boundingbox');
A(k).x = regionprops(cc,'Area');
%
%index centroid values, plot on original image, save image
%index centroid values, to be used to find crop bounding box.
for w = 1:length(C(k).x(:,1))
c(:,w,k) = C(k).x(w).Centroid;
a(:,w,k) = A(k).x(w).Area;
g = c(1,w,k); % x-coordinate
l = c(2,w,k); % y-coordinate
crp = imcrop(img, B(k).x(w).BoundingBox);
% Uncomment to resize images
% zsximgcrp1 = imcrop(img_final, B(i).x(w).BoundingBox);
% sz = size(crp);
%
% if sz(1) || sz(2) < 224
%
% if sz(1) < sz(2)
%
% crp = imresize(crp, [224 NaN]);
% crp1 = imresize(crp1, [224 NaN]);
%
% else
%
% crp = imresize(crp, [NaN 224]);
% crp1 = imresize(crp1, [NaN 224]);
%
% end
%
% end
img_name = sprintf('Image%04d',k);
img_file_name = sprintf('Experiment#1_%s_Video#%d_%s_%d.jpg',...
experimental_dirs{i}, j, img_name, w);
% TODO: index image name, pixel area, centroid value x, centroid
% value y
img_info = {img_file_name, a(:,w,k), g, l};
file_info = cat(1,file_info,img_info);
imwrite(crp, fullfile(folder, img_file_name));
end
end
end
end
cd(folder);
T = cell2table(file_info,'VariableNames',{'Name' 'Area' 'x' 'y'});
writetable(T,'image_info_neurons.txt');