create a binary sphere

by

 

create a binary sphere

cutellipsoid.m
a_mean=16;
b_mean=16;
c_mean=16;
N=3000;
Nc=32;
Nx=64;
Ny=Nx;
Nz=Ny;

aa = a_mean; % 
  bb = b_mean;
  cc = c_mean;
  
  for layer=1:cc
      a=sqrt((1-(((c_mean)-layer)/cc)^2)*(aa^2));
      b=sqrt((1-(((c_mean)-layer)/cc)^2)*(bb^2));
      
  for cpt=N:-1:1  %top right
    X(N-cpt+1,layer) = Nc + (cpt-1)* a /(N-1);
    Y(N-cpt+1,layer) = sqrt( a^2- ( X(N-cpt+1,layer)-Nc )^2 )* b/a + Nc;
    if (cpt==N)
      Y(N-cpt+1,layer) = real(Y(N-cpt+1,layer));
    end
  end
  
  for cpt=1:N   %top left
    X(N+cpt,layer) = Nc - (cpt-1)* a/ (N-1);
    Y(N+cpt,layer) = sqrt( a^2- ( X(N+cpt,layer)-Nc )^2 )* b/a + Nc;
    if (cpt==N)
      Y(N+cpt,layer) = real(Y(N+cpt,layer));
    end
  end
  
  for cpt=N:-1:1   %bottom left
    X(3*N-cpt+1,layer) = Nc - (cpt-1)* a/ (N-1);
    Y(3*N-cpt+1,layer) = -sqrt( a^2- ( X((3*N-cpt+1),layer)-Nc )^2 )* b/a + Nc;
    if (cpt==N)
      Y(3*N-cpt+1,layer) = real(Y(3*N-cpt+1,layer));
    end
  end
  
  for cpt=1:N   %bottom right
    X(3*N+cpt,layer) = Nc + (cpt-1)* a/ (N-1);
    Y(3*N+cpt,layer) = -sqrt( a^2- ( X((3*N+cpt),layer)-Nc )^2 )* b/a + Nc;
    if (cpt==N)
      Y(3*N+cpt,layer) = real(Y(3*N+cpt,layer));
    end
  end
  %Y(3*N+1:4*N,layer,e)=Y(3*N:-1:2*N+1,layer,e);
  X(:,((c_mean*2+1)-layer))=X(:,layer);
  Y(:,((c_mean*2+1)-layer))=Y(:,layer);
  end 
  
  
  
  training_set_curves = zeros(64,64,64);
  
  for layer=1:(c_mean*2)
  for cpt=1:4*3000
    training_set_curves(ceil(Y(cpt,layer)),ceil(X(cpt,layer)),((Nx/2-c_mean)+layer)) = 1;
  end
  training_set_curves(:,:,layer) = double(bwmorph(training_set_curves(:,:,layer),'ske',Inf));
  %training_set_curves(:,:,layer,e) = double(bwmorph(training_set_curves(:,:,layer,e),'bridge',Inf));%connect previous unconnected point
  end
    
  for l=1:64
  new(:,:,l)= double(bwfill(training_set_curves(:,:,l),'holes'));
  end
  
  new=-(new-1);
  
  for u=16:48
      imshow(new(:,:,u));
      pause(0.2);
  end
  


 
  
 
  
  

Contact us