...
OpenJPEG is an open-source JPEG 2000 codec written in C. There is no GUI. This command-line tool is easy to run and maintain using a command-line friendly OS like Linux, so I recommend installing Linux on your Windows 10 1X machine, taking advantage of W10's Windows Subsystem for Linux feature.
...
The process of compiling Grok is so fussy that, as of March 2023January 2024, we recommend:
...
sudo apt-get install libgrokj2k1 grokj2k-tools libgrokj2k1-dev libgrokj2k1-doc
5. Test your installation
...
jpylyzer *.jp2 | grep '<isValid format="jp2">True</isValid>'
...
Encoding JP2 files
Command: opj_compress
...
, OpenJPEG
Switches, partial list:
-i <inputFile.ext>
-p RLCP
(progression order)-t 1024,1024
(tile size, width,height)-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>
-r <compression ratio>
-OutFor [J2K|J2C|JP2]
Output format used to compress the images read from the directory specified with
-ImgDir
. Required when-ImgDir
option is used. Supported formats areJ2K
,J2C
, andJP2
.-InFor [pbm|pgm|ppm|pnm|pam|pgx|png|bmp|tif|raw|rawl|jpg]
Input format. Will override file tag.
Selected Grok-specific switches
(See: Options for complete list)
-logfile [output file name]
Log to file. File name will be set to
output file name
-num_threads [number of threads]
Number of threads used for T1 compression. Default is total number of logical cores.
-Comment [comment]
Add
<comment>
in comment marker segment(s). Multiple comments (up to a total of 256) can be specified, separated by the|
character. For example:-C "This is my first comment|This is my second
will storeThis is my first comment
in the first comment marker segment, andThis is my second
in a second comment marker.
-Q, -CaptureRes [capture resolution X,capture resolution Y]
Capture resolution in pixels/metre, in double precision.
...
Command: grk_compress
, Grok
- Switches, partial list:
-i <inputFile.ext>
-p RLCP
(progression order)-t 1024,1024
(tile size, [width,height])-EPH
(End of Packet Header marker)-SOP
(Start of Packet)-batch_src <input dir>
(cannot be used with -i switch)-out_dir <output dir>
(required withbatch_src
is used)-o <outputFile.ext>
-I
(specifies lossy encoding)-q <quality in db>
-r <compression ratio>
-out_fmt [J2K|J2C|JP2]
-V
(transfer Exif tags)-logfile <output file name>
-num_threads <number of threads>
-comment <comment>
Lossless example
opj_compress -i in.tif -o out_lossless.jp2 -p RLCP -t 1024,1024 -EPH -SOP
grk_compress -i in.tif -o grk_out_lossless.jp2 -p RLCP -t 1024,1024 -EPH -SOP
...
grk_decompress -i infile.j2k -o outfile.png
grk_decompress -ImgDir batch_src images/ -OutFor out_fmt tif
—
Encoding entire directories
...
#!/bin/bash
#Grok Image Compression JP2 JPEG2000 codec encoder lossy compression
#https://github.com/GrokImageCompression/grok
find . -type f | grep --extended-regexp ".*\.tif$" | sed -E "s/.tif//g" > tiffNameStem.txt
ls -1 *.tif | wc -l | xargs echo "TIFF count: "
while read line
do
grk_compress -i $line".tif" -o $line"_lossy.jp2" -p RLCP -t 1024,1024 -EPH -SOP -I -q 42
echo "converting "$line".tif"
done < tiffNameStem.txt
echo "
~~~ FIN ~~~
"
ls -1 *.jp2 | wc -l | xargs echo "JP2 count: "
...
end