pub fn to_ndarray<T>(&self) -> Result<Array<T, IxDyn>>
    where
        T: NumCast,
        T: Send,
    {
        // Array size is Rows x Cols x SamplesPerPixel (1 for grayscale, 3 for RGB)
        let shape = IxDyn(&[
            self.rows as usize,
            self.cols as usize,
            self.samples_per_pixel as usize,
        ]);

        match self.bits_allocated {
            8 => {
                // 1-channel Grayscale image
                let converted: Result<Vec<T>, _> = self
                    .data
                    .par_iter()
                    .map(|v| T::from(*v).ok_or(snafu::NoneError))
                    .collect();
                let converted = converted.context(InvalidDataType)?;
                let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                Ok(ndarray)
            }
            16 => match self.pixel_representation {
                // Unsigned 16 bit representation
                0 => {
                    let mut dest = vec![0; self.data.len() / 2];
                    NativeEndian::read_u16_into(&self.data, &mut dest);

                    let converted: Result<Vec<T>, _> = dest
                        .par_iter()
                        .map(|v| T::from(*v).ok_or(snafu::NoneError))
                        .collect();
                    let converted = converted.context(InvalidDataType)?;
                    let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                    Ok(ndarray)
                }
                // Signed 16 bit 2s complement representation
                1 => {
                    let mut signed_buffer = vec![0; self.data.len() / 2];
                    NativeEndian::read_i16_into(&self.data, &mut signed_buffer);

                    let converted: Result<Vec<T>, _> = signed_buffer
                        .par_iter()
                        .map(|v| T::from(*v).ok_or(snafu::NoneError))
                        .collect();
                    let converted = converted.context(InvalidDataType)?;
                    let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                    Ok(ndarray)
                }
                _ => InvalidPixelRepresentation.fail()?,
            },
            _ => InvalidBitsAllocated.fail()?,
        }
    }
/// Convert decoded pixel data into an ndarray of a given type T.
/// The pixel data type is extracted from the bits_allocated and
/// pixel_representation, and automatically converted to the requested type T.
Convert decoded pixel data into an ndarray of a given type T.
The pixel data type is extracted from the bits_allocated and
pixel_representation, and automatically converted to the requested type T.
Convert decoded pixel data into an ndarray of a given type T . The pixel data type is extracted from the bits_allocated and pixel_representation and automatically converted to the requested type T .
pub fn to_ndarray<T>(&self) -> Result<Array<T, IxDyn>>
    where
        T: NumCast,
        T: Send,
    {
        // Array size is Rows x Cols x SamplesPerPixel (1 for grayscale, 3 for RGB)
        let shape = IxDyn(&[
            self.rows as usize,
            self.cols as usize,
            self.samples_per_pixel as usize,
        ]);
        match self.bits_allocated {
            8 => {
                // 1-channel Grayscale image
                let converted: Result<Vec<T>, _> = self
                    .data
                    .par_iter()
                    .map(|v| T::from(*v).ok_or(snafu::NoneError))
                    .collect();
                let converted = converted.context(InvalidDataType)?;
                let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                Ok(ndarray)
            }
            16 => match self.pixel_representation {
                // Unsigned 16 bit representation
                0 => {
                    let mut dest = vec![0; self.data.len() / 2];
                    NativeEndian::read_u16_into(&self.data, &mut dest);
                    let converted: Result<Vec<T>, _> = dest
                        .par_iter()
                        .map(|v| T::from(*v).ok_or(snafu::NoneError))
                        .collect();
                    let converted = converted.context(InvalidDataType)?;
                    let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                    Ok(ndarray)
                }
                // Signed 16 bit 2s complement representation
                1 => {
                    let mut signed_buffer = vec![0; self.data.len() / 2];
                    NativeEndian::read_i16_into(&self.data, &mut signed_buffer);
                    let converted: Result<Vec<T>, _> = signed_buffer
                        .par_iter()
                        .map(|v| T::from(*v).ok_or(snafu::NoneError))
                        .collect();
                    let converted = converted.context(InvalidDataType)?;
                    let ndarray = Array::from_shape_vec(shape, converted).context(ShapeError)?;
                    Ok(ndarray)
                }
                _ => InvalidPixelRepresentation.fail()?,
            },
            _ => InvalidBitsAllocated.fail()?,
        }
    }
pub fn to_ndarray < T > ( & self ) -> Result < Array < T , IxDyn > > where T : NumCast , T : Send , { // Array size is Rows x Cols x SamplesPerPixel (1 for grayscale, 3 for RGB) let shape = IxDyn ( & [ self . rows as usize , self . cols as usize , self . samples_per_pixel as usize , ] ) ; match self . bits_allocated { 8 => { // 1-channel Grayscale image let converted : Result < Vec < T > , _ > = self . data . par_iter ( ) . map ( | v | T :: from ( * v ) . ok_or ( snafu :: NoneError ) ) . collect ( ) ; let converted = converted . context ( InvalidDataType ) ? ; let ndarray = Array :: from_shape_vec ( shape , converted ) . context ( ShapeError ) ? ; Ok ( ndarray ) } 16 => match self . pixel_representation { // Unsigned 16 bit representation 0 => { let mut dest = vec ! [ 0 self data len ( ) 2 ] ; NativeEndian :: read_u16_into ( & self . data , & mut dest ) ; let converted : Result < Vec < T > , _ > = dest . par_iter ( ) . map ( | v | T :: from ( * v ) . ok_or ( snafu :: NoneError ) ) . collect ( ) ; let converted = converted . context ( InvalidDataType ) ? ; let ndarray = Array :: from_shape_vec ( shape , converted ) . context ( ShapeError ) ? ; Ok ( ndarray ) } // Signed 16 bit 2s complement representation 1 => { let mut signed_buffer = vec ! [ 0 self data len ( ) 2 ] ; NativeEndian :: read_i16_into ( & self . data , & mut signed_buffer ) ; let converted : Result < Vec < T > , _ > = signed_buffer . par_iter ( ) . map ( | v | T :: from ( * v ) . ok_or ( snafu :: NoneError ) ) . collect ( ) ; let converted = converted . context ( InvalidDataType ) ? ; let ndarray = Array :: from_shape_vec ( shape , converted ) . context ( ShapeError ) ? ; Ok ( ndarray ) } _ => InvalidPixelRepresentation . fail ( ) ? , } , _ => InvalidBitsAllocated . fail ( ) ? , } }
Convert decoded pixel data into an ndarray of a given type T.
The pixel data type is extracted from the bits_allocated and
pixel_representation, and automatically converted to the requested type T.
Convert decoded pixel data into an ndarray of a given type T . The pixel data type is extracted from the bits_allocated and pixel_representation and automatically converted to the requested type T .
&self
&self