Skip to content

Instantly share code, notes, and snippets.

@jrkerns
Created December 5, 2016 00:14
Show Gist options
  • Save jrkerns/6e0a2a3182e2e2cadc22b236e4bc87aa to your computer and use it in GitHub Desktop.
Save jrkerns/6e0a2a3182e2e2cadc22b236e4bc87aa to your computer and use it in GitHub Desktop.
Manually clean up a faulty WL image.
# original problem here: https://groups.google.com/forum/#!topic/pylinac/4YkFEfwYjBQ
# solution: overwrite pixel artifacts, save modified image, load that one into pylinac's WL
import pylinac
path = r'path/to/image.dcm'
orig_img = pylinac.image.DicomImage(path)
# the guilty pixels all seem to have a value of 8,
# so let's threshold everything under 20 to be the background value (in this case, the max)
orig_img.array[orig_img.array < 20] = orig_img.array.max()
new_img_path = orig_img.save(r'path/to/newimage.dcm')
# do this for all the affected images, move them into a new folder, then load them
new_path = r'path/to/all/new/image/dir'
wl = WinstonLutz(new__path)
...
# all should be well *crosses fingers*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment