API¶
- rap_sitkcore.is_dicom_xray(filepath_or_url: str | Path, strict: bool = False) bool¶
For a DICOM file, inspects the Modality meta-data field to determine if the image is an x-ray. This classification is for the TBPortals collection to primarily x-ray from CT scans.
If the filename is not in DICOM format, then false is returned. If the filename does not refer to a file, then the “FileNotFound” exception will be thrown.
- rap_sitkcore.read_dcm(filename: Path, keep_all_tags: bool = False) Image¶
Read an x-ray DICOM file with GDCMImageIO, reducing it to 2D from 3D as needed. If the file cannot be read by the GDCM library, then pydicom is tried. Color images are converted to grayscale.
The pixel spacing of the output image is 1 and the direction cosine matrix is the identity.
- When keep_all_tags is False, only selected DICOM tags are present in the output image. The supported tags include:
“StudyInstanceUID”
“SeriesInstanceUID”
“Modality”
“PixelSpacing”
“ImagerPixelSpacing”
“DistanceSourceToDetector”
“ViewPosition”
“PatientSex”
This can be overridden as needed by setting keep_all_tags to True. In this case, all tags are copied.
- Parameters:
filename – A DICOM filename
keep_all_tags – If True, all DICOM tags are copied to the output image. This includes private tags. The tags
describe the DICOM file, and image buffer transformations can be applied making the tag no longer correct. :returns: a 2D SimpleITK Image
- rap_sitkcore.read_dcm_header_pydicom(filepath_or_url: str | Path, download_chunk_size_bytes: int = 10240, stream: bool = True, **kwargs: Any) FileDataset¶
Get the DICOM headers from either a local file (by file path) or a remote file (by URL).
- Parameters:
filepath_or_url – A string containing either a path or a URL. The URL must be prefixed by either ‘http://’ or ‘https://’. Or a filepath as a pathlib Path object.
download_chunk_size_bytes – An integer controlling the download chunk size if the file is remote, defaults to 1024 bytes.
stream –
A boolean indicating whether the HTTP request (if filepath_or_url points to a remote file) should be streamed.
If filepath_or_url points to a local file, this parameter is ignored.
For this to work, the server must support the chunked transfer-encoding. If it doesn’t, requests should treat this as a normal request and download the entire request contents before passing to pydicom dcmread.
kwargs – keywords are forwarded to pydicom.dcmread
- Returns:
a pydicom.dataset.FileDataset representing the DICOM indicated by filepath_or_url
- rap_sitkcore.resize_and_scale_uint8(image: Image, new_size: List[int]) Image¶
Resize the given image to the given size, with isotropic pixel spacing and scale the intensities to [0,255].
Resizing retains the original aspect ratio, with the original image centered in the new image. Zero padding is added outside the original image extent.
- Parameters:
image – A SimpleITK image.
new_size – List of ints specifying the new image size.
- Returns:
a 2D SimpleITK image with desired size and a pixel type of sitkUInt8
- rap_sitkcore._util.srgb2gray(img: Image) Image¶
Convert an sRGB [0, 255] image to gray scale and rescale results to [0,255].
- Parameters:
img – SimpleITK Image with 3 components, any dimension.
- Returns:
scalar SimpleITK Image of UInt8
- rap_sitkcore._dicom_util.convert_float_list_to_mv_ds(value: List[float]) str¶
Convert a iterable of float to the DICOM multi-value representation for decimal string (DS).
This method is intended to convert the pydicom MV DS data elements to the representation that GDCM produced for SimpleITK.
- Parameters:
value – an iterable or list like object of convertable to float values.
- Returns:
The value encode in for DICOM representation.
- rap_sitkcore._dicom_util.convert_int_list_to_mv_ds(value: List[float]) str¶
Convert a iterable of int to the DICOM multi-value representation for (unsigned) integer (US/IS).
This method is intended to convert the pydicom MV DS data elements to the representation that GDCM produced for SimpleITK.
- Parameters:
value – an iterable or list like object of convertable to float values.
- Returns:
The value encode in for DICOM representation.
- rap_sitkcore._dicom_util.convert_mv_ds_to_float_list(rep: str, vm: int = 0) List[float]¶
Converts the file representation, into data for a multi-value Decimal String (DS).
- Parameters:
rep – the representation of attribute occurring in the file
vm – the expected Value Multiplicity of rep, if 0 then any number of multivalues is accepted
- Returns:
a list of float converted from rep
- rap_sitkcore._dicom_util.keyword_to_gdcm_tag(keyword: str) str¶
Converts a DICOM keyword to a DICOM tag formatted as a string to match GDCM representation.
Example: “SeriesDescription”-> “0008|103e”
- Parameters:
keyword – a string representation of a DICOM metadata keyword, following the defined camel case convention
- Returns:
a string representation of the keyword as a metadata tag, consisting of the group in hex, a ‘|’ deliminator and the element in hex.