forked from LeonardoLupori/brainAlignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatchEditSliceMask.m
51 lines (36 loc) · 1.43 KB
/
batchEditSliceMask.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
clearvars, clc
% -------------------------------------------------------------------------
defaultFolder = 'D:\PizzorussoLAB\proj_PNN-highFatDiet\DATASET';
% -------------------------------------------------------------------------
%% Load all slices from an XML file (a single mouse)
filter = [defaultFolder filesep '.xml'];
tit = 'Select an INFO XML file';
[file,path] = uigetfile(filter,tit);
if file ~= 0
xml = [path filesep file];
sliceArray = allSlicesFromXml(xml);
end
%% (OPTIONAL) - Run this cell if you want to preprocess all masks
% Objects smaller than this number of pixels will be removed
threshold = 50;
for i = 1:length(sliceArray)
msk = sliceArray(i).mask;
temp = bwareaopen(msk,threshold);
% Invert the mask and perform the same processing
temp = bwareaopen(~temp,threshold);
% Dilate the mask to erode a few pixels on the outside of the slice
temp = imdilate(temp,strel('disk',3));
% Invert back the mask to normal
temp = ~temp;
% Save the mask back into the objects
sliceArray(i).mask = temp;
end
fprintf('\nMasks for all slices filtered.\n')
%% Run the maskEditor GUI on all the slices
maskEditor(sliceArray);
%% (OPTIONAL) - Use this cell to show one specific slice
if ~exist('annotationVolume','var')
load('annotationVolume.mat');
end
sl = Slice(7,xml);
sl.show('volume',annotationVolume,'borders',true,'mask',true);