|
a |
|
b/sitk_show.py |
|
|
1 |
# -*- coding: utf-8 -*- |
|
|
2 |
""" |
|
|
3 |
Created on Thu Oct 13 23:56:36 2016 |
|
|
4 |
|
|
|
5 |
@author: seeker105 |
|
|
6 |
""" |
|
|
7 |
import numpy |
|
|
8 |
import matplotlib.pyplot as plt |
|
|
9 |
import SimpleITK |
|
|
10 |
|
|
|
11 |
def sitk_show(img, title=None, margin=0.05, dpi=40 ): |
|
|
12 |
nda = SimpleITK.GetArrayFromImage(img) |
|
|
13 |
spacing = img.GetSpacing() |
|
|
14 |
figsize = (1 + margin) * nda.shape[0] / dpi, (1 + margin) * nda.shape[1] / dpi |
|
|
15 |
extent = (0, nda.shape[1]*spacing[1], nda.shape[0]*spacing[0], 0) |
|
|
16 |
fig = plt.figure(figsize=figsize, dpi=dpi) |
|
|
17 |
ax = fig.add_axes([margin, margin, 1 - 2*margin, 1 - 2*margin]) |
|
|
18 |
|
|
|
19 |
plt.set_cmap("gray") |
|
|
20 |
ax.imshow(nda,extent=extent,interpolation=None) |
|
|
21 |
|
|
|
22 |
if title: |
|
|
23 |
plt.title(title) |
|
|
24 |
|
|
|
25 |
plt.show() |