%get the background of the phantom function background = getBackground( image ) imageSize = size(image); %get a mask containing the contour of the phantom %e.g. where you can only see the shape of the phantom mask = zeros(size(image(:,:,1))); mask(25:end-25,25:end-25) = 1; %get the shape of the phantom bw = activecontour(image(:,:,50),mask,300); %create a matrix to store the values of the phantom-background in a matrix backgroundMatrix = zeros(60,imageSize(1)*imageSize(2)); for i=1:imageSize(3) %for every slice of the image set the background of the scan (not %background of the phantom!) to 0 actualImage = image(:,:,i); actualImage(bw<1) = 0; s = int2str(i); dicomwrite(actualImage, strcat('test', s)); %get the values of the image which are bigger than 0 %(With this I exclude spine, spheres and the background of the %scan) newValues = actualImage(actualImage >0); size(actualImage) %store values in matrix if(i>ceil(imageSize(3)/2 -5) && i0); end