Skip to content

Commit

Permalink
Merge pull request #125 from sustrev/main
Browse files Browse the repository at this point in the history
More DICOM conversion
- for  e2e, img,boct, poct
  • Loading branch information
marksgraham authored Nov 7, 2023
2 parents e1de3d8 + a2a90c1 commit 4307962
Show file tree
Hide file tree
Showing 18 changed files with 1,149 additions and 51 deletions.
11 changes: 11 additions & 0 deletions examples/demo_boct_extraction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from oct_converter.dicom import create_dicom_from_oct
from oct_converter.readers import BOCT

filepath = "../sample_files/sample.OCT"
Expand All @@ -11,3 +12,13 @@
oct.save(
"boct_testing.png"
) # save volume as a set of sequential images, fds_testing_[1...N].png

# create DICOM from .OCT
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# If multiple volumes are identified within the file,
# multiple DICOMs will be outputted.
# Additionally, diskbuffered can be specified to store
# volume on disk using HDF5 to reduce memory usage
dcm = create_dicom_from_oct(filepath, diskbuffered=True)
8 changes: 8 additions & 0 deletions examples/demo_e2e_extraction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from oct_converter.dicom import create_dicom_from_oct
from oct_converter.readers import E2E

filepath = "../sample_files/sample.E2E"
Expand All @@ -21,3 +22,10 @@
metadata = file.read_all_metadata()
with open("metadata.json", "w") as outfile:
outfile.write(json.dumps(metadata, indent=4))

# create a DICOM from E2E
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# If multiple volumes are present in the E2E file,
# multiple files will be created.
2 changes: 0 additions & 2 deletions examples/demo_fda_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# Output filename can be specified, otherwise
# will default to the input filename.
2 changes: 0 additions & 2 deletions examples/demo_fds_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# Output filename can be specified, otherwise
# will default to the input filename.
9 changes: 9 additions & 0 deletions examples/demo_img_extraction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from oct_converter.dicom import create_dicom_from_oct
from oct_converter.readers import IMG

filepath = "../sample_files/file.img"
Expand All @@ -7,3 +8,11 @@
) # returns an OCT volume with additional metadata if available
oct_volume.peek() # plots a montage of the volume
oct_volume.save("img_testing.avi") # save volume

# create a DICOM from .img
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# Additionally, rows, columns, and interlaced can
# be specified to more accurately create an image.
dcm = create_dicom_from_oct(filepath, interlaced=True)
8 changes: 8 additions & 0 deletions examples/demo_optovue_extraction.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from oct_converter.dicom import create_dicom_from_oct
from oct_converter.readers import POCT

filepath = "../sample_files/sample.OCT"
Expand All @@ -7,3 +8,10 @@
for volume in oct_volumes:
volume.peek() # plots a montage of the volume
print("debug")

# create DICOM from .OCT
dcm = create_dicom_from_oct(filepath)
# Output dir can be specified, otherwise will
# default to current working directory.
# If multiple volumes are identified within the file,
# multiple DICOMs will be outputted.
108 changes: 108 additions & 0 deletions oct_converter/dicom/boct_meta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
from oct_converter.dicom.metadata import (
DicomMetadata,
ImageGeometry,
ManufacturerMeta,
OCTDetectorType,
OCTImageParams,
OPTAcquisitionDevice,
OPTAnatomyStructure,
PatientMeta,
SeriesMeta,
)
from oct_converter.image_types import OCTVolumeWithMetaData


def boct_series_meta(boct: OCTVolumeWithMetaData) -> SeriesMeta:
"""Creates SeriesMeta from Bioptigen OCT metadata
Args:
boct: OCTVolumeWithMetaData with laterality and acquisition_date attributes
Returns:
SeriesMeta: Series metadata populated with laterality and acquisition_date
"""
series = SeriesMeta()

series.study_id = ""
series.series_id = 0
series.laterality = boct.laterality
series.acquisition_date = boct.acquisition_date
series.opt_anatomy = OPTAnatomyStructure.Retina

return series


def boct_manu_meta() -> ManufacturerMeta:
"""Creates base ManufacturerMeta for Bioptigen
Args:
None
Returns:
ManufacturerMeta: base Bioptigen manufacture metadata
"""

manufacture = ManufacturerMeta()

manufacture.manufacturer = "Bioptigen"
manufacture.manufacturer_model = ""
manufacture.device_serial = ""
manufacture.software_version = ""

return manufacture


def boct_image_geom() -> ImageGeometry:
"""Creates ImageGeometry from Bioptigen OCT metadata
Args:
pixel_spacing: Pixel spacing calculated in the boct reader
Returns:
ImageGeometry: Geometry data populated by pixel_spacing
"""
image_geom = ImageGeometry()
image_geom.pixel_spacing = [0.02, 0.02] # Placeholder value
image_geom.slice_thickness = 0.2 # Placeholder value
image_geom.image_orientation = [1, 0, 0, 0, 1, 0]

return image_geom


def boct_image_params() -> OCTImageParams:
"""Creates OCTImageParams specific to Bioptigen
Args:
None
Returns:
OCTImageParams: Image params populated with Bioptigen defaults
"""
image_params = OCTImageParams()
image_params.opt_acquisition_device = OPTAcquisitionDevice.OCTScanner
image_params.DetectorType = OCTDetectorType.CCD
image_params.IlluminationWaveLength = 880
image_params.IlluminationPower = 1200
image_params.IlluminationBandwidth = 50
image_params.DepthSpatialResolution = 7
image_params.MaximumDepthDistortion = 0.5
image_params.AlongscanSpatialResolution = []
image_params.MaximumAlongscanDistortion = []
image_params.AcrossscanSpatialResolution = []
image_params.MaximumAcrossscanDistortion = []

return image_params


def boct_dicom_metadata(boct: OCTVolumeWithMetaData) -> DicomMetadata:
"""Creates DicomMetadata and populates each module
Args:
oct: OCTVolumeWithMetaData created by the boct reader
Returns:
DicomMetadata: Populated DicomMetadata created with OCT metadata
"""
meta = DicomMetadata
meta.patient_info = PatientMeta()
meta.series_info = boct_series_meta(boct)
meta.manufacturer_info = boct_manu_meta()
meta.image_geometry = boct_image_geom()
meta.oct_image_params = boct_image_params()

return meta
Loading

0 comments on commit 4307962

Please sign in to comment.