Skip to content

CT 3D Visual #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OverLordGoldDragon opened this issue Nov 14, 2020 · 1 comment
Closed

CT 3D Visual #32

OverLordGoldDragon opened this issue Nov 14, 2020 · 1 comment

Comments

@OverLordGoldDragon
Copy link

OverLordGoldDragon commented Nov 14, 2020

Figured it helpful to interactively dig in skeletons:

Requirement: plotly. Guide.

import os
import glob
import torch
import torch.nn as nn
import numpy as np
import SimpleITK as sitk

import plotly.graph_objs as go
from plotly.offline import plot  # for IDE (e.g. Spyder use)

#%%# Load data ###############################################################
_dir = r"C:\LUNA\\"  # replace with path to your 'subset*' directory
path = glob.glob(os.path.join(_dir, 'subset*\\*.mhd'))[0]

ct_mhd = sitk.ReadImage(path)
ct_a = np.array(sitk.GetArrayFromImage(ct_mhd), dtype=np.float32)
ct_a.clip(-1000, 1000, ct_a)

#%%# Downsample #######
ct_a_t = torch.tensor([[ct_a]])
ctm = nn.MaxPool3d(4)(ct_a_t).numpy()[0][0]

#%%# Prepare to plot ##
a, b, c = ctm.shape
l = 16
X, Y, Z = np.mgrid[-l:l:a*1j, -l:l:b*1j, -l:l:c*1j]

#%%# Plot in browser #########################################################
fig = go.Figure(data=go.Volume(
    x=X.flatten(),
    y=Y.flatten(),
    z=Z.flatten(),
    value=ctm.flatten(),
    opacity=0.15, # small to see through surfaces
    surface_count=12, # larger -> better volume rendering
    colorscale='RdBu',
    ))
plot(fig, auto_open=True)
@elistevens
Copy link
Member

Thanks for the contribution! Since this isn't really an issue, per se, I'm going to close this, but I'd like to welcome you to turn it into a gist or a PR for a file in a reader_contributions/ subdir that could hold things like this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants