-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_zebrain.m
84 lines (68 loc) · 2.72 KB
/
export_zebrain.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
%% import mask database
cd zebrain % go to your copy of the code
load MaskDatabase.mat
%% export brain slices as PNG b&w images, 1px = 1px = 0.798 µm
mkdir PNG
cd PNG
% --- for each brain region ---
for i = 1:294
region = MaskDatabaseNames{i}; % get region name
disp(region); % displays it
mask = false(1406,621,138); % initialize empty mask
mask(MaskDatabase(:,i)) = true; % select corresponding region
% --- for each layer ---
for z = 1:138
img = mask(:,:,z); % use given layer
if max(img(:)) % if the layer contains a part of the region
fprintf("%d, ", z); % displays layer number
% define filename and replace slashes inside it
file = [num2str(z, '%03d') ' ' num2str(i, '%03d') ' ' MaskDatabaseNames{i} '.png'];
file = replace(file, '/', '-');
imwrite(img, file); % write the b&w image
end
end
fprintf("\n"); % linebreak
end
% at this point, there should be 7645 images in the PNG folder
cd ..
%% export region names correspondance table
fid = fopen('region-names.txt', 'w');
for i = 1:294
fprintf(fid, '%03d\t%s\n', i, MaskDatabaseNames{i});
end
fclose(fid);
%% [optional] export masks of vertically projected regions 1px = 0.3988 layer = 0.7977 µm
mkdir PROJ
cd PROJ
for i = 1:294
region = MaskDatabaseNames{i}; % get region name
disp(region); % displays it
mask = false(1406,621,138); % initialize empty mask
mask(MaskDatabase(:,i)) = true; % select corresponding region
% --- projection ---
img = max(mask, [], 3);
% define filename and replace slashes inside it
file = [num2str(i, '%03d') ' ' MaskDatabaseNames{i} '.png'];
file = replace(file, '/', '-');
imwrite(img, file); % write the b&w image
end
cd ..
%% [optional] export masks of horizontally projected regions
mkdir HPROJ
cd HPROJ
fac = 2.0/0.798; % size of layer interval in horizontal pixel
imwidth = round(138*fac); % width of the image in horizontal pixel
for i = 1:294
region = MaskDatabaseNames{i}; % get region name
disp(region); % displays it
mask = false(1406,621,138); % initialize empty mask
mask(MaskDatabase(:,i)) = true; % select corresponding region
% --- projection ---
img = squeeze(max(mask, [], 2));
img = imresize(img, [1406,imwidth]);
% define filename and replace slashes inside it
file = [num2str(i, '%03d') ' ' MaskDatabaseNames{i} '.png'];
file = replace(file, '/', '-');
imwrite(img, file); % write the b&w image
end
cd ..