-
Notifications
You must be signed in to change notification settings - Fork 5
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
JPEG encoding #57
Comments
Are you writing a standalone implementation or binding to an existing library (and if so, which one)? What JPEG formats are you aiming for? |
I was thinking of a wrapper around existing library which implements JPEG/JPEG2000 (to be honest I am not aware of the differences) encoding + functionality to automate modification of all required dicom tags. There are several python libraries which wraps around C/Java libraries implementing JPEG, I've tried simplejpeg (works with uint8, no grayscale16 support), turbojpeg (dunno the exact issue, but it also failed to encode int16 grayscale numpy arrays), glymur (only supports 3.6,3.7 and this project I am working on is 3.8). |
I would suggest reading up on the differences in the JPEG standards that DICOM uses:
The first two are available online via the ITU, however the J2K standard isn't (you might get lucky and find a PDF by googling 😉). Even the general introductions in Wikipedia or the JPEG group's website is a good start, but if you want to know what bit-depth and options (lossy/lossless, colour spaces, signed/unsigned) are available you'll have to dig through the standards. Then you have to decide which of those various bit-depth/lossy/sign options you want to support and find a backend library that can handle them (and don't forget to check the licensing each library offers). For example, the IJG's libpeg (written in C) can only handle non 8- or 16-bit images after changing a config flag and recompiling, which is pretty impractical if you want to encode both 12-bit for the JPEG Extended transfer syntax and 8-bit for JPEG Baseline (although it can be done, see GDCM). The nice thing about most libraries, though, is that they usually come with an encoding application, which you can look at to figure out how the library is supposed to be used (e.g. the openjpeg library has a J2K convert tool, which includes encoding). You could take a look at the two pylibjpeg plugins to see how to get them working via Cython (and my very amateurish C/C++). Or at Pillow to see how they do it, or at the various wrapper Python libraries as well. |
Thank you for this comprehensive answer, I'll dig into the standards. |
Have you tried the imagecodecs package? It's more geared towards supporting TIFF and CZI files, but it can handle a several "JPEG" formats (JPEG 8 and 12 bit, LJPEG, JPEG LS, JPEG XR, JPEG 2000) via the libjpeg-turbo, liblj92, charls, jxrlib, and openjpeg libraries. |
Thanks, I will give it a try. |
Hello, I am trying to implement jpeg encoding for dicom within a python (without saving on disk, thus gdcmconv is not an option). I tried to use PIL, but unfortunately some of the required (by PIL) libraries has versions conflicts (with versions I use).
It would be great if you can give any starting point on how to add such functionality.
The text was updated successfully, but these errors were encountered: