...

/

Visualize the Windowing

Visualize the Windowing

Learn to visualize the image before and after transformation.

An image before and after windowed()

Let’s visualize the image before and after applying the windowed() function. In the code below, we can see the difference between the original image and the image after applying windowed().

Press + to interact
from matplotlib import pyplot as plt
import nibabel
import numpy as np
filepath = 'volume_pt5/volume-44.nii'
imagedata = nibabel.load(filepath)
array = imagedata.get_fdata()
array = np.rot90(np.array(array))
def windowed(px, w, l):
px_min = l - w//2
px_max = l + w//2
px[px<px_min] = px_min
px[px>px_max] = px_max
return (px-px_min) / (px_max-px_min)
f = plt.figure(figsize=(12,12))
ax = f.add_subplot(121)
ax2 = f.add_subplot(122)
ax.imshow(array[...,50].astype(np.float32),cmap=plt.cm.bone)
ax.title.set_text('Original image')
ax2.imshow(windowed(array[...,50].astype(np.float32), 150,30), cmap=plt.cm.bone)
ax2.title.set_text('Windowing image')

Let’s take a closer look at the code above.

  • In line 7
...