function [w, orig, im, binim, snew] = Erika_CellDivisionPlanes(im,w, binim)
orig = im;


[snew] = ErikaCellPlanes(im); % this opens the GUI 'Sector Extraction'. The user can adjust the extraction himself. 
im = max(im, [], 3);
binim = calc_binim(im); % extract the organ shape;
return 

function [binim] = calc_binim(im)
% try % if the image is in the format MxNxK, this is mainly taken from JRK_algorithm
% r = im(:,:,1);
% g = im(:,:,2);
% b = im(:,:,3);
% binim = (r-b)>140;
% clear r g b;
% binim = imclose(binim, strel('disk', 30));
% binim = bwfill(binim, 'holes');
% catch % if the image format is MxN, as is the case for the cell plane images    
%     % three imadjust steps seem to be better to reduce background noise;
level = graythresh(im);
binim = im2bw(im,level*0.001);
%binim = imadjust(im);
%binim = imadjust(binim, [0.05 ; 0.1], [0 ;1]); %0.45;
binim = imfill(binim,'holes');
%binim = imadjust(binim, [0.6 ; 0.9], [0 ;1]); %0.6,0.9;
binim = bwareaopen(binim, 10); % remove objects smaller than 1000 pixels;
return;

