All Projects → aaalgo → ljpeg

aaalgo / ljpeg

Licence: BSD-2-Clause license
No description, website, or topics provided.

Programming Languages

c
50402 projects - #5 most used programming language
Roff
2310 projects
Lex
420 projects
objective c
16641 projects - #2 most used programming language
python
139335 projects - #7 most used programming language
Makefile
30231 projects
q
29 projects

Usage:

  1. Install flex with apt-get install flex. Building without flex will fail and pollute the codebase.

  2. In your python project

    git clone https://github.com/aaalgo/ljpeg.git
    
    

    Or if you are using git already:

    git submodule add https://github.com/aaalgo/ljpeg.git
    
    
  3. Produce the jpeg binary.

    cd jpegdir; make
    
    

A precompiled binary of jpeg is included. In case this step does not work do this:

cd jpegdir;
cp jpeg_static jpeg
  1. In your python code:

    from ljpeg import ljpeg
    
    x = ljpeg.read(path)
    

    The loaded is a matrix of type uint16. Typically you want to convert that to float for subsequent processing.

    x = ljpeg.read(path).astype('float')
    

    The LJPEG format sometimes has wrong values for width and height (transposed). One has to read the correct values of width and height from the associating .ics file. Below is a sample snippet for this purpose:

        W = None
        H = None
        # find the shape of image
        for l in open(ics, 'r'):
    	l = l.strip().split(' ')
    	if len(l) < 7:
    	    continue
    	if l[0] == name:
    	    W = int(l[4])
    	    H = int(l[2])
    	    bps = int(l[6])
    	    if bps != 12:
    		logging.warn('BPS != 12: %s' % path)
    	    break
    
        assert W != None
        assert H != None
    
        if W != image.shape[1]:
    	logging.warn('reshape: %s' % path)
    	image = image.reshape((H, W))
    
  2. Using ljpeg.py standalone:

    • Convert to TIFF (requires the .ics file in the same directory as LJPEG)
    ./ljpeg.py cases/benigns/benign_01/case0029/C_0029_1.LEFT_CC.LJPEG output.tiff
    
    • Convert to TIFF and verify that no information has been lost
    ./ljpeg.py cases/benigns/benign_01/case0029/C_0029_1.LEFT_CC.LJPEG output.tiff --verify
    
    • Convert to jpeg for visualization with down-sizing scale=0.3 (16-bit TIFF is not good for direct visualization)
    ./ljpeg.py cases/benigns/benign_01/case0029/C_0029_1.LEFT_CC.LJPEG output.jpg --visual --scale 0.3
    

    Note that output file can be any format that's supported by OpenCV (which includes all common types). Most file formats only support 8-bit images, so directly saving into such file formats will cause problems. Add "--visual" to normalize color into 8-bit before saving to such file formats.

The Stanford ljpeg code is in public domain and is therefore OK to be included here. I did minor modification to make the code compile under modern Linux.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].