0

Trying to create a ghost 3d image with a known volume to create a calibrated gold standard : a sphere.

I've tried this code but it doesn't provide me what i'm really want.

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import medpy.io as mdpy
from scipy import signal

def create_bin_sphere(arr_size, center, r):
    coords = np.ogrid[:arr_size[0], :arr_size[1], :arr_size[2]]
    distance = np.sqrt((coords[0] - center[0])**2 + (coords[1]-center[1])**2 + (coords[2]-center[2])**2) 
    return 10*(distance <= r)


arr_size = (100,100,100)
sphere_center = (50,50,50)
r=30
sphere = create_bin_sphere(arr_size,sphere_center, r)


kernel = np.array([[[0,1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1,0]]])
sphere_smooth = scipy.signal.oaconvolve(sphere, kernel, mode="same")
from medpy.io import load, save
save(sphere_smooth ,r'x\x\x\x\x\sphere_smooth.mhd')

Does not work as i wish :image in itk snap in x plan

I would rather not change the sphere shape (the "smoothed" become ovoid), have the blurr effect on the whole circumference and reducing its thickness, and finally invert the density (white outside and grey inside the sphere).

If you can help me i will appreciate...

Beethov
  • 1
  • 1
  • Does this answer your question? [How to generate a sphere in 3D Numpy array](https://stackoverflow.com/questions/46626267/how-to-generate-a-sphere-in-3d-numpy-array) – norok2 May 26 '20 at 21:34
  • Thank you for the suggestion, i've tried theses methods too and they allow to create another sphere with an alternative method but the density and the blurr problems are not resolved. – Beethov May 27 '20 at 09:18
  • Nothing else?.... – Beethov Jun 01 '20 at 05:49
  • Not really. The Python package suggested there has a ["smoothing" option](https://stackoverflow.com/q/60493488/5218354) and inverting the values is just a `1 - sphere` matter. So I do not think there is more to it. – norok2 Jun 01 '20 at 06:05

0 Answers0