0

Recently i was struggling trying to take the pixel values of a 3D volume (np array) using specific space coordinate of a STL object. The STL object is spatially overlapped with the 3D volume but the latter has no coordinate and so i don't know how to pick pixel values corresponding to the STL coordinates. Any idea?

273K
  • 29,503
  • 10
  • 41
  • 64
Zimmer
  • 1
  • 2

1 Answers1

0

If the STL object is truly in the 3d volume's coordinate space, then you can simply STL's coordinate as an index to lookup the value from the 3d array. This lookup does nearest neighbor interpolation of the 3d image. For better looking results you'd want to do linear (or even cubic) interpolation of the nearby pixels.

In most 3d imaging tasks, those coordinate spaces do not align. So there is a transform to go from world space to 3d volume space. But if all you have is a 3d numpy array, then there is no transformation information.

Update: To index into the 3d volume take the X, Y, Z coordinates of your point from the STL object and convert them into integer value I, J, K. Then lookup in the numpy array using I,J,K as indices: np_array[K][J][I]. I think you have to reverse the order of the indices because of the array ordering numpy uses.

When you way 3d array and the STL align in python, how are you showing that? The original DICOM or Nifti certainly have world coordinate transformations in the metadata.

Dave Chen
  • 1,905
  • 1
  • 12
  • 18
  • Thanks for your answer! Loading in 3D Slicer the STL and the DICOM original volume of the numpy array they align perfectly so when using them in python i assume they are in the same coordinate space. But i don't understand how to use the STL's coordinate as index for the 3d array that has no coordinate. – Zimmer Dec 16 '21 at 10:42
  • Moreover i also have DICOM and nifti file of the same 3D array (the 3D array infact is extracted from the nifti file of the volume) – Zimmer Dec 16 '21 at 10:49