Skip to content

Commit

Permalink
sanity changes before purging dev-20200414
Browse files Browse the repository at this point in the history
  • Loading branch information
skim2257 committed Dec 6, 2021
1 parent 0ca7011 commit 91e453c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 33 deletions.
14 changes: 2 additions & 12 deletions imgtools/io/common.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import os
import glob
import re
from typing import Optional
from collections import namedtuple
from itertools import chain

import numpy as np
import pandas as pd
import SimpleITK as sitk
from pydicom import dcmread

from pydicom.misc import is_dicom

from ..utils import image_to_array



Expand All @@ -35,7 +25,7 @@ def find_dicom_paths(root_path: str, yield_directories: bool = False) -> str:
"""
# TODO add some filtering options
for root, dirs, files in os.walk(root_path):
for root, _, files in os.walk(root_path):
if yield_directories:
if any((is_dicom(os.path.join(root, f)) for f in files)):
yield root
Expand Down
2 changes: 0 additions & 2 deletions imgtools/io/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import re
from typing import Optional, List
from collections import namedtuple
from itertools import chain
import json

import numpy as np
import pandas as pd
import SimpleITK as sitk
import nrrd
Expand Down
13 changes: 8 additions & 5 deletions imgtools/modules/dose.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import pydicom
from matplotlib import pyplot as plt
import os
import glob
import warnings

import numpy as np
from matplotlib import pyplot as plt

import SimpleITK as sitk
import warnings
from pydicom import dcmread



def read_image(path):
reader = sitk.ImageSeriesReader()
Expand Down Expand Up @@ -32,7 +35,7 @@ def from_dicom_rtdose(cls, path):

#Get the metadata
dcm_path = os.path.join(path, os.listdir(path)[0])
df = pydicom.dcmread(dcm_path)
df = dcmread(dcm_path)

#Convert to SUV
factor = float(df.DoseGridScaling)
Expand Down
12 changes: 7 additions & 5 deletions imgtools/modules/pet.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import pydicom
from matplotlib import pyplot as plt
import os
import numpy as np
import SimpleITK as sitk
import warnings
import datetime

import numpy as np
from matplotlib import pyplot as plt

import SimpleITK as sitk
from pydicom import dcmread

def read_image(path):
reader = sitk.ImageSeriesReader()
dicom_names = reader.GetGDCMSeriesFileNames(path)
Expand Down Expand Up @@ -37,7 +39,7 @@ def from_dicom_pet(cls, path, type="SUV"):
'''
pet = read_image(path)
path_one = os.path.join(path,os.listdir(path)[0])
df = pydicom.dcmread(path_one)
df = dcmread(path_one)
try:
if type=="SUV":
factor = df.to_json_dict()['70531000']["Value"][0]
Expand Down
3 changes: 1 addition & 2 deletions imgtools/modules/structureset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import numpy as np
import SimpleITK as sitk
from pydicom import dcmread
from itertools import chain, groupby
from itertools import groupby
from skimage.draw import polygon2mask

from .segmentation import Segmentation
from ..utils import physical_points_to_idxs
from ..utils import array_to_image


def _get_roi_points(rtstruct, roi_index):
Expand Down
14 changes: 10 additions & 4 deletions imgtools/ops/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Sequence, Union, Tuple, Optional
from collections import namedtuple

from imgtools.modules import segmentation

from ..modules import Segmentation


Expand Down Expand Up @@ -381,7 +383,8 @@ def bounding_box(mask: sitk.Image, label: int = 1) -> Tuple[Tuple, Tuple]:
"""

if isinstance(mask, Segmentation):
mask = mask.get_label(label=label, relabel=True)
seg = Segmentation(mask)
mask = seg.get_label(label=label, relabel=True)

filter_ = sitk.LabelShapeStatisticsImageFilter()
filter_.Execute(mask)
Expand Down Expand Up @@ -418,7 +421,8 @@ def centroid(mask: sitk.Image,
"""

if isinstance(mask, Segmentation):
mask = mask.get_label(label=label, relabel=True)
seg = Segmentation(mask)
mask = seg.get_label(label=label, relabel=True)

filter_ = sitk.LabelShapeStatisticsImageFilter()
filter_.Execute(mask)
Expand Down Expand Up @@ -460,7 +464,8 @@ def crop_to_mask_bounding_box(image: sitk.Image,
"""

if isinstance(mask, Segmentation):
mask = mask.get_label(label=label, relabel=True)
seg = Segmentation(mask)
mask = seg.get_label(label=label, relabel=True)

if isinstance(margin, Sequence):
margin = np.asarray(margin)
Expand Down Expand Up @@ -576,7 +581,8 @@ def image_statistics(image: sitk.Image,

if mask is not None:
if isinstance(mask, Segmentation):
mask = mask.get_label(label=label, relabel=True)
seg = Segmentation(mask)
mask = seg.get_label(label=label, relabel=True)

filter_ = sitk.LabelStatisticsImageFilter()
filter_.Execute(image, mask)
Expand Down
2 changes: 0 additions & 2 deletions imgtools/ops/ops.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from posixpath import expanduser
from typing import List, TypeVar, Sequence, Union, Tuple, Optional, Any
from itertools import chain

import numpy as np
import SimpleITK as sitk
Expand Down
2 changes: 1 addition & 1 deletion imgtools/utils/imageutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def image_to_array(image):
def show_image(image, mask=None, ax=None):
import matplotlib.pyplot as plt
if ax is None:
fig, ax = plt.subplots()
ax = plt.subplots()

image_array, *_ = image_to_array(image)

Expand Down

0 comments on commit 91e453c

Please sign in to comment.