Skip to content

Commit

Permalink
improve the conversion between probabilistic and indexed representation
Browse files Browse the repository at this point in the history
  • Loading branch information
robertoostenveld committed Aug 23, 2023
1 parent 1af47b1 commit 3f2c1e3
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions utilities/private/convert_segmentationstyle.m
Expand Up @@ -10,23 +10,36 @@
case 'indexed'

% convert the probabilistic representation to an indexed representation
threshold = 0.5;
tissue = zeros(dim);
tissuelabel = cell(1,numel(fn));

alltissue = zeros(prod(segmentation.dim), length(fn));
for i=1:length(fn)
tmp = segmentation.(fn{i})>threshold;
if any(tissue(tmp(:)))
ft_error('overlapping tissue probability maps cannot be converted to an indexed representation');
% FIXME in principle it is possible to represent two tissue types at one voxel
else
tissue(tmp) = i;
tissuelabel{i} = fn{i};
end
alltissue(:,i) = reshape(segmentation.(fn{i}), prod(segmentation.dim), 1);
end
% for each voxel take the most likely tissue
[val, tissue] = max(alltissue, [], 2);
tissue(val==0) = 0;

segmentation = rmfield(segmentation, fn);
segmentation.tissue = tissue;
segmentation.tissuelabel = tissuelabel;
segmentation.tissue = reshape(tissue, segmentation.dim);
segmentation.tissuelabel = fn;

% threshold = 0.5;
% tissue = zeros(dim);
% tissuelabel = cell(1,numel(fn));
%
% for i=1:length(fn)
% tmp = segmentation.(fn{i})>threshold;
% if any(tissue(tmp(:)))
% ft_error('overlapping tissue probability maps cannot be converted to an indexed representation');
% % FIXME in principle it is possible to represent two tissue types at one voxel
% else
% tissue(tmp) = i;
% tissuelabel{i} = fn{i};
% end
% end
% segmentation = rmfield(segmentation, fn);
% segmentation.tissue = tissue;
% segmentation.tissuelabel = tissuelabel;

case 'probabilistic'
% convert the indexed representation to a probabilistic one
Expand Down

0 comments on commit 3f2c1e3

Please sign in to comment.