Closed codinkai closed 3 months ago
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"
I suspect that there is some trait version mismatch. Can you try importing open_file
like this instead?
use dicom_object::open_file;
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
If anything, there may be something going on at the Cargo.lock. Here are a few more steps to try and resolve the situation:
cargo tree -d
to see if there are duplicate dependencies. Run cargo update
and inspect the dependency tree again.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.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.
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.
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"] }
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.
Thank you for your support. It is a great library anyway. I will close this ticket now.
Your feedback is appreciated! I have provided said re-exports in #469, to be delivered in the next version.
Hi,
i am trying to run the example from https://docs.rs/dicom-pixeldata/latest/dicom_pixeldata/index.html
This is the code I run:
When I run
cargo build
, I get the following error:What am I doing wrong?