-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[toimage]: bulk conversion working #397
[toimage]: bulk conversion working #397
Conversation
Thank you for working on this. As I suspect that we might need some time to review and I was about to bring forward a new release of DICOM-rs, I propose that this is worked on after 0.6.0 is out. This should not stop me from publishing this enhancement in a subsequent minor release anyway. |
Oh yeah sure, I think you're right ! I'll check in back here when the 0.6.0 is out. |
DICOM WG4 has a data set with some example files, and the pydicom test files also have some files which are multi-frame. Running In practice, I can't be sure which behavior is more suitable, but we can either a) pick the first frame only, or b) print all frames into separate files with an extension to the file name, e.g.
Generally, we would go in the opposite direction from here: given this
I admit that this was not made clear in the original issue, but I would prefer that the functionality to convert a single image is retained. It is OK if the code ends up with a bit of redundancy.
That should be fine. At least adding support for extra image formats is as simple as updating |
6bd996a
to
5bbbcf2
Compare
Thanks for your guidance @Enet4 ! I made good progress on this PR, but I have an issue and I'm not sure what is the best way to handle it: To select the image format, it's only necessary to set the extension of the PathBuf to the target extension. So far, I took the original file name and set the extension but I realized there is an issue with filenames that don't include an extension and include a "." which is unfortunately pretty common. For example given a file f with a filename of "1.2.276.0.123":
Below is a code snippet to illustrate:
As for the workaround, here are the propositions I though of:
If someone has an other suggestion as well or any opinion on the best one it would be great. Thanks |
I would detect |
f7f18ab
to
3c62392
Compare
Hello, This should be good.
Please tell me if any other change should be made, I'll gladly oblige. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so I had a chance to test this in practice, and I found these concerns:
- I tried to do this, but it still requested
out_file_name
even though I was making multiple files.Adding the option with bogus data (λ dicom-toimage.exe -o mydata-images/ mydata/ error: the following required arguments were not provided: --out-file-name <OUT_FILE_NAME> Usage: dicom-toimage.exe --out-file-name <OUT_FILE_NAME> --out-dir <OUT_DIR> <FILES>...
-O 89u3tuh389
) would work, although it was not doing anything in practice. - To maintain backwards compatibility, I propose that
-o
continues to be used for the output file name, and-d
is used for the output directory, so that the examples below work.dicom-toimage myfile.dcm -o myimage.png dicom-toimage myfiles/ -d myimages/
- By replacing
frame_number
withall_frames
, We have lost the capability to select a specific frame to output. Here is an idea: we can make a hybrid of the two into someting likeframes
. If the option's value is"all"
, then the behavior is to write all frames. Otherwise, it is treated as a single integer of the frame number.
At least the first and second concerns should be handled here before merging. The third point is a bit of extra work, so maybe it can be worked on separately. Let me know if you need further assistance.
Hey, Thanks for the testing and feedbacks! I'm currently abroad but I'll make sure to make the modifications as soon as I'm back and have a little time. (likely during a weekend of September). |
Hey hello, @Enet4 I am having trouble resolving conflicts in a clean manner. So I plan on starting from a new PR directly from master currents version of the I just have a quick question. I see that on master's version of main, you have extended the errors and also attributed some specific exit codes. Is there a specification on how exit codes should be attributed or should I just decrease as I add more errors (and group the one that share the same source as I think this is what you've done ? Thanks ! Pierre |
Hello @PierreBou91!
It is fine either way. It should also be possible to keep the pull request by hard-resetting the branch and doing a forced push. As for the exit code, it was primarily to differentiate between different kinds of errors, but none of it is intended to follow a stable guideline, so feel free to rearrange them as needed. |
b54b8b8
to
b714dcc
Compare
I hard reset and force-pushed as advised and reimplemented the bulk conversion. User can now pass a path to a file, multiple files or a folder (possibly recursively with I have not reimplemented the frame selection for multiframe dicoms because I'm not sure yet how to do it with the Please tell me if you see any improvements to be made. I also intent on doing an improved error handling for the |
7e71581
to
aedd300
Compare
- should pass one or more files, otherwise it's an error
and update README accordingly
- tweak phrasing and expand error conditions - adjust doctests to be more idiomatic
- add `promiscuous`, implemented by Enet4#500 - adjust documentation of other arguments
- rstest 0.19 - cargo update
- update description - set Edition to 2021 - cargo update
- updates ureq to 2.9.7
As per #343 I have implemented the possibility to convert multiple dicoms to a folder of images.
For consistency, I have copied a lot of the logic from the
dicom-storescu
but I don't think it's worth extracting it yet.Here are my questions/concerns about this commit and I need some guidance:
1. Not tested on multiframe dicom:
I am very unfamiliar with multiframe dicoms and I don't really know where to find or create proper ones. I was not able to test this commit with multiframe dicoms.
The basic functionality should be preserved but even though, I'm not certain that this is the expected behavior (convert the nth frame of every multiframe dicom in the input).
This is by far my biggest concern for this commit because there might be regressions and I don't know of an acceptable way to handle this since the use case (multiframe to image) is unclear to me.
2.
Error
enum with onlyError::Other
variant:Initially I copied the
Error
enum fromdicom-storescu
required in thecheck_file
function return type that I also imported. But sinceError::Other
is the only variant, maybe should it just be removed altogether ?3.
output
flag was replaced byout-dir
:This has several consequences:
I just went to the simplest implementation that matched the specs in #343. If the mentioned consequences are not acceptable, I can try and find some ways to fix them.
4. The
format
flag currently takes a String:It works as is but since the image crate is exposing an
image
::ImageFormat
enum, this can be a good base for clap's checking and suggestions.I refrained from doing it because I didn't know if every image format should be allowed or any other restriction I don't know about.
Overall this commit is far from perfect but I still opened this PR since I already find it more convenient than DCMTK's equivalent binary.