Reading jpg images for Kaggle challenge

How can I read jpg images in Julia.

Has anyone performed any work on the following dataset: (Chest X-Ray (Pneumonia,Covid-19,Tuberculosis) | Kaggle)

I suppose this is it, with docs how: GitHub - JuliaIO/JpegTurbo.jl: Julia interface to libjpeg-turbo

It’s the fastest option/backend (also faster then MATLAB and Python/OpenCV): benchmark results against other backends · Issue #15 · JuliaIO/JpegTurbo.jl · GitHub

In case you looked no further than Julia’s docs, then that’s usually a mistake, it provides e.g. LinearAlgebra and some other math, but look at for most other stuff, also googling e.g. JPEG Julia would have worked.

FYI: This is probably the first package for JPEG/image decoding/encoding, and supports all kinds of formats including PNG you need: GitHub - JuliaIO/ImageMagick.jl: Thin Wrapper for the library ImageMagick

I doubt you find pure Julia code for JPEG (unlike e.g. available for the simpler GIF format), but the non-pure dependencies shouldn’t be any problem.

There might be one or more packages for this, be aware of FileIO.jl and Images.jl, but I think this is all you need to know.

1 Like


Packages using GDAL can read georeferenced jpeg2000 and GeoTIFF, which those other packages cannot.

1 Like

Thanks, good to know, JPEG2000 is a completely different file format, though people might not realize, so I wasn’t answering for that, since not asked (nor did I now locate it used in the dataset, only JPEG and PNG). TIFF is also completely different (a lossless format, and not the best one, PNG was best, some other even better), and GeoTIFF seems to only apply to that format. Maybe something similar applies for JPEG[2000].

JPEG XL is likely the best JPEG variant (but not for the web, since Google Chrome deprecated it), even best lossless compressed format of all. HEIF is another one, and AVIF maybe best for the web supported by vast majority. The latter (and many more e.g JPEG2000 and PNG and WebP, also video and audio formats) is supported by FileTypes.jl and yet another “jxr”, seemingly the other JPEG variant JPEG XR, but not latest XL.

I can’t locate AVIF support for Julia so this may need to be wrapped:

I’m unclear which language or library supports AVIF best, maybe rather Rust (an option to be wrapped or just called):

Python also supports it and has libraries for it available, and more, and it’s easy to use all of them with PythonCall.jl.

Absolute most compression is likely to be with neural-network based methods, e.g. HiFiC (and it needs to be wrapped for Julia):

And even it can be improved upon (e.g. down to “𝐻-𝑅𝑂𝐼: 0.2275𝑏𝑝𝑝” (their example); is possible; even without it down to 0.139bbp possible with good quality, I guess depending on the image):

Further, we propose adaptive quantization by non-linear mapping within the channel dimension to constrain the bit rate while maintaining the visual quality. Exhaustive experiments demonstrate that our methods achieve better visual quality on small faces and text with lower bit rates, e.g., 0.7X bits of HiFiC and 0.5X bits of BPG.