Code Monkey home page Code Monkey logo

Comments (4)

chrisbll971 avatar chrisbll971 commented on July 24, 2024 1

This worked. Thanks so much and the library is great.

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

Thank you for reporting. You are right that the Fragments API bears a few limitations right now, but apparently it can also be misleading. Creating Fragments should only be necessary if you have a very large frame that needs to be split into fragments. In your case, if you have a list of frames and intend to fit exactly one frame in each fragment, I would recommend skipping that API altogether.

let mut all_fragments: Vec<_> = frames.iter().enumerate().map(|(ix, frame)| {
    println!("Adding frame {} with len {}", ix, frame.len());
    frame.to_vec()
}).collect();

file.put(DataElement::new(
   tags::PIXEL_DATA,
   VR::OB,
   PixelSequence::<InMemDicomObject, InMemFragment>(all_fragments.into()),
));

You might encounter two other issues:

  1. The accumulation of all frame lengths in total_frame_len could also panic. This is generally not necessary unless you wish to provide Encapsulated Pixel Data Value Total Length (7FE0,0003). If you skip it or make it a u64, it should no longer overflow.

  2. One other problem is that pushing all frames into a DICOM object will require all frames to be in memory. The future of the project may hold nicer ways to write DICOM data sequentially.

from dicom-rs.

chrisbll971 avatar chrisbll971 commented on July 24, 2024

Ok awesome and good to know. In the example above do you happen to know if I will need to write the pixel data with a different approach as well? On my end it is showing that the From<> trait isn't implemented for converting a Vec<Vec> into a PixelSequence.

let mut all_fragments: Vec<_> = frames.iter().enumerate().map(|(ix, frame)| {
    println!("Adding frame {} with len {}", ix, frame.len());
    frame.to_vec()
}).collect();

file.put(DataElement::new(
   tags::PIXEL_DATA,
   VR::OB,
   PixelSequence::<InMemDicomObject, InMemFragment>(all_fragments.into()),
));

the trait bound `PixelFragmentSequence<Vec<u8>>: From<Vec<Vec<u8>>>` is not satisfied

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

Hmm right. You can try PixelFragmentSequence::new_fragments instead. It makes it clear that it keeps the basic offset table empty, which is probably why I withdrew the idea of implementing From<_> for this case.

file.put(DataElement::new(
   tags::PIXEL_DATA,
   VR::OB,
   PixelFragmentSequence::new_fragments(all_fragments.into()),
));

from dicom-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.