Function to find points along a vector line in a CT image

15 views Asked by At

I need to find the points along a vector line in a CT image. I am trying to find the voxels (3D pixels) that contain the skull in that particular vector direction. This can be done using line equation`: starting_point + t * vector. Problem is determining the magnitude for t. If I set the magnitude of t to be too big, it will exceed the boundary of the image. The other issue is setting the lower and upper limits for t. I know the image has a size of (91, 109, 91) so t can only be within this size. So how do I make my code efficient but only choosing t values that fit within the limits of the image?

import numpy as np
center = np.array(center)
valid_points = []
intensity_values = []
skull_layer = np.zeros([91, 109, 91])

for i in range(648):
  for t in np.linspace(0, 100, 101):
    
    normal_vector = normals[i]
    
    starting_point = normal_vector * 1
    
    
    
    point = starting_point + t * normal_vector
    
    point = np.floor(point).astype(int)  # Round towards the nearest pixel
    index_coord = center + point
    xi = index_coord[0]
    yi = index_coord[1]
    zi = index_coord[2]
    
    
     
    if 0 < xi < 91 and 0 < yi < 109 and 0 < zi < 91:
         valid_point = [xi, yi, zi]
         intensity_value = image_array[xi, yi, zi]
         if intensity_value > 250:
             
             skull_layer[xi, yi, zi] = intensity_value
             
             valid_points.append(valid_point)
             intensity_values.append(intensity_value)
             
    else: 
       for t in np.linspace(-100, 0, 101):
            
            vector = normals[i]
        
            starting_point = vector * 1
        
            point = np.floor(point).astype(int)  # Round towards the nearest pixel
            index_coord = center + point
            xi = index_coord[0]
            yi = index_coord[1]
            zi = index_coord[2]
             
            if 0 < xi < 91 and 0 < yi < 109 and 0 < zi < 91:
                 valid_point = [xi, yi, zi]
                 intensity_value = image_array[xi, yi, zi]
                 if intensity_value > 250:
                     
                     skull_layer[xi, yi, zi] = intensity_value
                 
                 valid_points.append(valid_point)
                 intensity_values.append(intensity_value)
0

There are 0 answers