Find sphere fit on binary matrix
4 views (last 30 days)
Show older comments
Hi all,
I have a (239,239,85) binary matrix in which the 1's correspond to the mask of a geometrical shape (see attachment). I want to fit a sphere around it, so that it fits best to the binary mask. I have already tried this: https://nl.mathworks.com/matlabcentral/fileexchange/34129-sphere-fit-least-squared, but that does not work since the matrix is singular. Can anybody help me out? Thanks in advance!
1 Comment
Walter Roberson
on 18 Feb 2022
If the matrix is singular then enter the data all lies in the same plane or else you are passing the wrong information to the fitting function.
Accepted Answer
KSSV
on 18 Feb 2022
load('matrixfit.mat')
[m,n,p] = size(tumor3) ;
[X,Y,Z] = ndgrid(1:m,1:n,1:p) ;
k = tumor3(:) ;
x = X(:) ;
y = Y(:) ;
z = Z(:) ;
P = [x(k==1) y(k==1) z(k==1)] ;
[Center,Radius] = sphereFit(P) ; % Use that file exchange function
I got:
Center = [100.8695 103.3629 37.2319] ;
Radius = 3.0785 ;
5 Comments
Torsten
on 21 Feb 2022
Usually,
solid_sphere= sqrt((X-Center(1)).^2 + (Y-Center(2)).^2 + (Z-Center(3)).^2) <= radius ;
Is it different in your case ?
More Answers (0)
See Also
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!