Skip to content

Commit

Permalink
DicomExtract (#8)
Browse files Browse the repository at this point in the history
* attempted to add DICOM Extraction

* changed file name to match class

* adding function for mCT metadata extraction

* Add parameter extraction code

* Delete MetadataExtractor/Extractors/Data/ParameterExtract.py

removed superfluous file

* Delete MetadataExtractor/Extractors/Data/mCTExtract.py

removed superfluous file

* Update IDataExtract.py

Removed , "dcm" from default

* Updated DicomExtract.py to use dicom_metadata

Removed the undefined attribute parameter.

* adding pydicom, adding DicomExtract to config
    new file:   Examples/2022-03-07_18h21_M3_Cy7.mCT
	new file:   Examples/2022-03-07_18h21_M3_Cy7.parameters
	new file:   Examples/EnIm1.dcm
	modified:   MetadataExtractor/Extractors/Data/DicomExtract.py
	modified:   MetadataExtractor/Extractors/Data/IDataExtract.py
	deleted:    MetadataExtractor/Extractors/Data/ParameterExtract.py
	deleted:    MetadataExtractor/Extractors/Data/mCTExtract.py
	modified:   defaultConfigs.py
	modified:   requirements.txt

* dicom extractor appears to work now
  • Loading branch information
catgonzftw1 authored Apr 24, 2024
1 parent 6873e08 commit d1fde15
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 2 deletions.
31 changes: 31 additions & 0 deletions Examples/2022-03-07_18h21_M3_Cy7.mCT
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# mCT settings file v1.0

[mCT]
name = FLT totalbody normal
magnification = total_body
scan_angle = 360.000000
scan_mode = normal
lin_stage_position = -1.000000
mode = step_and_shoot
angle_start = 0.000000
angle_speed_deg_s = 0.000000
angle_step_deg = 0.750000
binning = x11
exposure_ms = 75.000000
frame_averaging = 1
xray_voltage_kV = 55.000000
xray_current_mA = 0.170000
exposure2_ms = 0.000000
xray_voltage2_kV = 0.000000
xray_current2_mA = 0.000000
origin_offset_z = 236.200000
HU_calibration = 20342.444444
BeamHardening = 0.245556
HU_calibration2 = 0.000000
BeamHardening2 = 0.000000
NrScans = 1
gating_proj_per_angle = 1
filter_1 = Al400
filter_2 =
fixed_filter = Al 100�m
Pitch (if helical) = 0.000000
23 changes: 23 additions & 0 deletions Examples/2022-03-07_18h21_M3_Cy7.parameters
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# U-SPECT parameter file v4.0

[System]
ScannerID = "80481"
SoftwareVersion = "12.27-st"
ScannerType = "U-CT"

[Animal]
ScanID = "2022-03-07_18h21_M3_Cy7"
AnimalID = "SS_FluoInserts"

[Images]
FovXY_mm = 88.000000
FovZ_mm = 230.000000

[Acquisition]
AcqStartTime = "2022-03-07 18:50:00"
SPECT = 0
CT = 1
OI = 0
FLT = 1
BLT = 0
Fluoroscopy = 0
Binary file added Examples/EnIm1.dcm
Binary file not shown.
59 changes: 59 additions & 0 deletions MetadataExtractor/Extractors/Data/DicomExtract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from .IDataExtract import IDataExtract
from MetadataExtractor.Util import metadataCreation, metadataFormatter
import pydicom
from pathlib import Path
from pydicom._version import __version_info__
import logging

log = logging.getLogger(__name__)


class DicomExtract(IDataExtract):
def extract(self, fileInfo):
log.info('Extracting metadata for Dicom file "' + fileInfo["file"] + '".')
text = ""

dicom_metadata = pydicom.dcmread(fileInfo["file"])

for elem in dicom_metadata.iterall():
if elem.tag.is_private:
continue # Skip private tags
tag_str = elem.tag
value = elem.value
if isinstance(value, pydicom.valuerep.DSfloat):
value = float(value)
logging.info(dicom_metadata.keys)
# Construct a DataElement instance
data_element = pydicom.DataElement(tag_str, elem.VR, value)
dicom_metadata[tag_str] = data_element

values = []
identifier = fileInfo["identifier"]

for attribute in dicom_metadata.keys():
objectValue = dicom_metadata[attribute]
values.append(
{
"predicate": "mexattr:" + metadataFormatter.replaceForbiddenValues(str(attribute)),
"object": objectValue,
}
)

metadata = metadataCreation.addEntryToFileGraph(
fileInfo,
self._IExtract__config,
{
"additionalPrefixes": [
"@prefix dcat: <http://www.w3.org/ns/dcat#>",
"@prefix dcterms: <http://purl.org/dc/terms/>",
],
"identifier": identifier,
"ontology": "mex",
"values": values,
},
)

return (text, metadata)

def registerMimeTypes(self):
self.mimeTypes["concrete"] = ["application/dcm", "application/dicom"]
3 changes: 2 additions & 1 deletion defaultConfigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def getDefaultConfig():
"Data": [
"ExeExtract",
"FcsExtract",
"Hdf5Extract"
"Hdf5Extract",
"DicomExtract"
],
"Image": [
"DescriptiveImageExtract",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ pandas==1.5.1
flowkit==1.0.0
openai-whisper
soundfile
pefile==2023.2.7
pefile==2023.2.7
pydicom==2.4.4

0 comments on commit d1fde15

Please sign in to comment.