Skip to content

Instantly share code, notes, and snippets.

@comstock
Last active November 1, 2018 19:10
Show Gist options
  • Select an option

  • Save comstock/b8abed5b0e75a4b2f531f0489231ccbb to your computer and use it in GitHub Desktop.

Select an option

Save comstock/b8abed5b0e75a4b2f531f0489231ccbb to your computer and use it in GitHub Desktop.
OpenJPEG, JPEG200 lossy compression encoding example with quality set to 42 decibels
opj_compress -i <input.tif> -o <output.jp2> -p RLCP -t 1024,1024 -EPH -SOP -OutFor jp2 -I -q 42
@comstock
Copy link
Copy Markdown
Author

comstock commented Mar 15, 2018

OpenJPEG Notes for encoding JPEG2000 files

Encoding

  • Command: opj_compress
  • Switches:
    • -i <inputFile.ext>
    • -p RLCP (progression order)
    • -t 1024,1024 (tile size)
    • -EPH (End of Packet Header marker)
    • -SOP (Start of Packet)
    • -ImgDir <image dir> (cannot be used with -i switch)
    • -OutFor <ext> (extension for output files)
    • -o <outputFile.ext>
    • -I (specifies lossy encoding)
    • -q <quality in dB>,<quality in dB>,...
    • -r <compression ratio>,<compression ratio>,...
  • Valid input file types:

    *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga

Lossless example

opj_compress -i D9_NS.tif -o D9_NS.jp2 -p RLCP -t 1024,1024 -EPH -SOP -OutFor jp2

Lossy example

  • opj_compress -i D9_NS.tif -o D9_NS.jp2 -p RLCP -t 1024,1024 -EPH -SOP -OutFor jp2 -I -q 42
  • opj_compress -i D9_NS.tif -o D9_NS.jp2 -p RLCP -t 1024,1024 -EPH -SOP -OutFor jp2 -r 10

decompress: converting JP2 files to other formats

opj_decompress -i infile.j2k -o outfile.png

opj_decompress -ImgDir images/ -OutFor tif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment