% contact region areas have defined interval of voxels, because they are
% the smallest parts in the data
MINVOXELNUMBER_CONTACTS=4;% at least 4 as minimum value
MAXVOXELNUMBER_CONTACTS=50;
% for head
% bolt head areas have defined minimum of voxels, as they are bigger than
% contact regions
% a maximum is also defined, as there are sometimes cable artifacts left in
% the data, so the heads are not the biggest areas in the data
MINVOXELNUMBER_HEAD=300;
MAXVOXELNUMBER_HEAD=900;
% TODO: find some solution for electrodes, where the contacts regions are
% "melted" together and no seperate regions and head are defined
%% get nifti img to binary img, so we can apply some functions
maskedImg=CT_post.img;
% structEle = strel('sphere', ceil(3 / max(CT_post.voxsize)) ); % make sure brain mask contains no skull
%
% brainMask = imerode(brainMask,structEle);
% maskedImg(~(brainMask)) = NaN;
cc=bwconncomp(maskedImg,26);% 26 for 3D images
disp([num2str(cc.NumObjects)' potential metal components detected within brain.']);
ccProps=regionprops(cc,CT_post.img,'Area','PixelIdxList','PixelList','PixelValues','BoundingBox','Centroid');% TODO not really needed as that info is already in cc
[areas,idxs]=sort([ccProps.Area],'descend');% sort by size