-
Notifications
You must be signed in to change notification settings - Fork 0
/
parc_slice.m
64 lines (56 loc) · 2.15 KB
/
parc_slice.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
function img_slice=parc_slice(img_bg,img_parc,index)
% draw a slice as color patches
% Inputs:
% img_bg, image for the background
% img_parc, image of the parcellation results
% index, a vector whose length is 3. Two of the three elements are 0
% and the rest one could index the desired plane
% img_slice, image of this slice
% 2014-7-30 09:38:18
% SLIC: a whole brain parcellation toolbox
% Copyright (C) 2016 Jing Wang
%
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.
ix=find(index~=0);
[a,b,c]=size(img_bg);
% take out the plane and reshape it to a 2D image
if ix==1
img_bg=img_bg(index(1),:,:);
img_parc=img_parc(index(1),:,:);
img_bg=reshape(img_bg,b,c);
img_parc=reshape(img_parc,b,c);
elseif ix==2
img_bg=img_bg(:,index(2),:);
img_parc=img_parc(:,index(2),:);
img_bg=reshape(img_bg,a,c);
img_parc=reshape(img_parc,a,c);
else
img_bg=img_bg(:,:,index(3));
img_parc=img_parc(:,:,index(3));
img_bg=reshape(img_bg,a,b);
img_parc=reshape(img_parc,a,b);
end
rng(1);
cmp=randi([0,255],[1000,1,3]);
img_slice=repmat(img_bg,[1,1,3]); % gray space to color space
sLabel=unique(img_parc);
nLabel=length(sLabel);
for iLabel=2:nLabel % overlay color patches for each cluster except label=0
cLabel=sLabel(iLabel); % current label
[A,B]=find(img_parc==cLabel);
nVoxel=length(A); % number of voxels in this cluster
for iVoxel=1:nVoxel
img_slice(A(iVoxel),B(iVoxel),:)=cmp(cLabel,1,:);
end
end