Skip to content

Instantly share code, notes, and snippets.

@addisonElliott
Last active March 1, 2018 03:35
Show Gist options
  • Save addisonElliott/97b9c615fa13455f5ea4699a507a63ae to your computer and use it in GitHub Desktop.
Save addisonElliott/97b9c615fa13455f5ea4699a507a63ae to your computer and use it in GitHub Desktop.
import nrrd
fakeData = np.zeros((320, 260, 215), dtype=np.uint8)
fakeData[100:200, 200:300, 50:64] = 255
nrrd.write('test1.nrrd', fakeData)
# This should be L5 which for Subject0001_Final has a L5 at 50 and L4 is at 64, so that means 50-63 should be L5. (64 means where to stop in numpy array)
# Since this is a cube, trapezoidal integration should just yield the same values in between because nothing changes
# So, square area for each slice should be area = (200 - 100) * (300 - 200) * 1.40625^2 = 19775.390625mm^2
# volume = area * (64 - 50) * 3 (interpolation) = 830566.40625 mm^3
# So, you should have 39 slices of areas (trapArea variable) equal to 19775 for each one. Add those up and get the volume part.
fakeData = np.zeros((320, 260, 215), dtype=np.uint8)
fakeData[100:200, 200:300, 104:115:2] = 255
nrrd.write('test2.nrrd', fakeData)
# Same as example above but for L1 now and we only have the cube every OTHER slice. So 104, 106, 108, 110, 112, 114
# This will change the interpolation and test what you have there
# So there is a constant value at each slice that is a square, but the value is different. So here is what it looks like before
# interpolation. Assume that you scale the 255 to 1 again, which I think you do.
# 104 105 106 107 108 109 110 111 112 113 114
# 1 0 1 0 1 0 1 0 1 0 1
# Already, so interpolating by 3 means adding two space in between first.
# 104 105 106 107 108 109 110 111 112 113 114
# 1 2/3 1/3 0 1/3 2/3 1 2/3 1/3 0 1/3 2/3 1 2/3 1/3 0 1/3 2/3 1 2/3 1/3 0 1/3 2/3 1 2/3 1/3 0 1/3 2/3 1 2/3 1/3
# Linear interpolation from 1 -> 0 with two values means it just goes 1, 2/3, 1/3, 0. Make sense?
# Area for full on (1): (200 - 100) * (300 - 200) * 1 = 10000mm^2
# Area for 2/3: (200 - 100) * (300 - 200) * 2/3 = 6666.666mm^2
# Area for 1/3: (200 - 100) * (300 - 200) * 1/3 = 3333.333mm^2
# Number of slices that we have for this: 11 2/3's, 11 1/3's and 6 1s: volume = 170000mm^3
# Manually edited to add the space directions... not worth the trouble of coding for two tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment