/ljpeg3

Primary LanguageCMIT LicenseMIT

ljpeg3

Open ljpeg files as NumPy arrays

This is a wrapper around the Stanford ljpeg code, which is public domain and also included. It's loosely based on @aaalgo/ljpeg, updated for Python 3 and slightly refactored.

You probably would want to use it to open images from the DDSM Mammography Database, as they had the genius idea of using this near-extinct image format.

Installation

You should have NumPy installed:

pip3 install numpy

Clone this repository:

git clone https://github.com/olieidel/ljpeg3.git

Build the ljpeg stuff. Some warnings may appear, ignore them and hope for the best. I have no idea how to fix the C code if it doesn't work for you.

cd ljpeg3/jpegdir
make

Usage

In your python project, add ljpeg3 to your path and import it:

import sys
sys.path.append('/path_to/ljpeg3')
from ljpeg3 import ljpeg

Read a .ljpeg file. There should also be an .ics file in the same directory.

im = ljpeg.read('path_to/some_file.ljpeg')

Use NumPy for further processing. Good luck!

Notes

In most cases, the height and width information from the ljpeg file is swapped and the ics file is needed to correct it. Oh, and swapped height und width is not equivalent to simply transposing the matrix.. :)

If you don't have an .ics file and your image looks weird, try this:

im = ljpeg.read('path_to/some_file.ljpeg')
im = im.reshape((im.shape[1], im.shape[0]))  # swaps width and height

# im = im.T <-- this won't work

License

MIT