Code Monkey home page Code Monkey logo

Comments (10)

codinkai avatar codinkai commented on July 24, 2024

I get this error for the second example:

error[E0599]: no method named `to_ndarray` found for struct `DecodedPixelData` in the current scope
  --> src/main.rs:17:30
   |
17 |     let ndarray = pixel_data.to_ndarray::<u16>()?;
   |                              ^^^^^^^^^^ method not found in `DecodedPixelData<'_>`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `hello_cargo` (bin "hello_cargo") due to 1 previous error

These are my dependencies in Cargo.toml:

[dependencies]
dicom = "0.6.3"
dicom-object = "0.6.3"
dicom-pixeldata = "0.2.2"
ndarray = "0.15.6"

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

I suspect that there is some trait version mismatch. Can you try importing open_file like this instead?

use dicom_object::open_file;

from dicom-rs.

codinkai avatar codinkai commented on July 24, 2024

Thank you for your quick response. Unfortunately, this did not solve the problem.

I have changed the code to:

fn main() -> Result<(), Box<dyn std::error::Error>> {
    //use dicom::object::open_file;
    use dicom_object::open_file;
    use std::env;

    let args: Vec<String> = env::args().collect();
    if args.len() < 2 {
        return Err("Usage: program_name <DICOM file path>".into());
    }
    let file_path = &args[1];

    let obj = open_file(file_path)?;

    use dicom_pixeldata::PixelDecoder;
    let image = obj.decode_pixel_data()?;
    let dynamic_image = image.to_dynamic_image(0)?;
    dynamic_image.save("out.png")?;

    Ok(())
}

with this Cargo.toml

[dependencies]
dicom = "0.6.3"
dicom-object = "0.6.3"
dicom-pixeldata = "0.2.2"

cargo run results in the same error. I have also tried to run cargo clean before compiling the code.

My OS information are:

System Version: macOS 14.4
Kernel Version: Darwin 23.4.0

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

If anything, there may be something going on at the Cargo.lock. Here are a few more steps to try and resolve the situation:

  1. Run cargo tree -d to see if there are duplicate dependencies. Run cargo update and inspect the dependency tree again.
  2. If after this it still won't compile, then I would recommend removing the parent dicom crate and picking the specific crates that you need. This is the rule of thumb that I personally follow: when picking specific dicom-* crates, remove the parent crate.

from dicom-rs.

codinkai avatar codinkai commented on July 24, 2024

I have solved the issue. The method "to_dynamic_image" is part of the image feature of pixeldata, which seems to be not enabled by default.

It works with this dependencies:

[dependencies]
dicom-object = "0.6.3"
dicom-pixeldata = { version = "0.2.2", features = ["image"] }

I have also tried it with the dependencies dicom = "0.6.3" with use dicom::object::open_file;and use dicom::pixeldata::PixelDecoder;. I assume that the feature "image" is not activated in there.

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

Oh yes, I must have overlooked that detail in your Cargo.toml. Converting to an image object requires the image feature, since that brings an extra set of dependencies. This is mentioned in the root crate documentation.

I'm afraid that this is by design, so there isn't much one can do here, other than improve the way that documentation is generated to clarify the features required for those methods to exist.

from dicom-rs.

codinkai avatar codinkai commented on July 24, 2024

No worries. Thank you for your support.

How can I enable the feature in the root crate?

I have tried this, but it does not work.

[dependencies]
dicom = { version = "0.6.3", features = ["image"] }

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

For that to work, dicom itself needs to re-export the Cargo feature into its own feature table. While this parent crate was designed to facilitate simple use cases, it is true that it has some shortcomings such as this one.

If anything, one can add more Cargo features to dicom. I agree that adding image and ndarray could be useful.

from dicom-rs.

codinkai avatar codinkai commented on July 24, 2024

Thank you for your support. It is a great library anyway. I will close this ticket now.

from dicom-rs.

Enet4 avatar Enet4 commented on July 24, 2024

Your feedback is appreciated! I have provided said re-exports in #469, to be delivered in the next version.

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.