Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion pixeldata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ pub struct ConvertOptions {
pub voi_lut: VoiLutOption,
/// Output image bit depth
pub bit_depth: BitDepthOption,
/// Photometric interpretation conversion option
pub photometric_interpretation: PhotometricInterpretationOption,
}

impl ConvertOptions {
Expand Down Expand Up @@ -350,6 +352,15 @@ impl ConvertOptions {
self.bit_depth = BitDepthOption::Force16Bit;
self
}

/// Set the photometric interpretation option.
pub fn with_photometric_interpretation(
mut self,
photometric_interpretation: PhotometricInterpretationOption,
) -> Self {
self.photometric_interpretation = photometric_interpretation;
self
}
}

/// Modality LUT function specifier.
Expand Down Expand Up @@ -432,6 +443,23 @@ pub enum BitDepthOption {
Force16Bit,
}

/// Output image photometric interpretation behavior.
///
/// Define how photometric interpretation conversions
/// should be handled when converting to an image.
///
/// See also [`ConvertOptions`].
#[derive(Debug, Default, Copy, Clone, PartialEq)]
#[non_exhaustive]
pub enum PhotometricInterpretationOption {
/// _Default behavior:_
/// invert pixeldata for Monochrome1 photometric interpretation.
#[default]
InvertMonochrome1,
/// Ignore photometric interpretation conversions.
Ignore,
}

/// A blob of decoded pixel data.
///
/// This is the outcome of collecting a DICOM object's imaging-related attributes
Expand Down Expand Up @@ -968,6 +996,7 @@ impl DecodedPixelData<'_> {
modality_lut,
voi_lut,
bit_depth,
photometric_interpretation,
} = options;

let mut image = match self.bits_allocated {
Expand Down Expand Up @@ -1280,7 +1309,9 @@ impl DecodedPixelData<'_> {
_ => InvalidBitsAllocatedSnafu.fail()?,
};
// Convert MONOCHROME1 => MONOCHROME2
if self.photometric_interpretation == PhotometricInterpretation::Monochrome1 {
if *photometric_interpretation == PhotometricInterpretationOption::InvertMonochrome1
&& self.photometric_interpretation == PhotometricInterpretation::Monochrome1
{
image.invert();
}
Ok(image)
Expand Down Expand Up @@ -1438,6 +1469,7 @@ impl DecodedPixelData<'_> {
modality_lut,
voi_lut,
bit_depth: _,
photometric_interpretation: _,
} = options;

if self.samples_per_pixel > 1 && self.planar_configuration != PlanarConfiguration::Standard
Expand Down