function [masks] = convertStardist(mask, gsize) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Converts to an MxNxT matrix of neuron masks to an MxN image of masks used by %stardist. Meant to make training data, so it assumes that there's a %desired, square image size for the output. % Inputs: % - mask: MxNxT matrix of the neuron masks % - gsize: desired size for the square output image % Output: % - masks: MxN image of the masks where the value of the pixel % corresponds to the neuron number %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% masks = []; [d1 d2 d3] = size(mask); cd1 = gsize - d1; cd2 = gsize - d2; uniqval = unique(mask(:)); uniqval(uniqval ==0) = []; for fn = 1:length(uniqval) blank = zeros(size(mask)); ind = find(mask == uniqval(fn)); blank(ind) = 1; blank = padarray(blank, [floor(cd1/2) floor(cd2/2)], 0,'post'); blank = padarray(blank, [ceil(cd1/2) ceil(cd2/2)], 0,'pre'); if sum(blank(:)) ~= 0 masks = cat(3, masks, blank); end end end