首页 >> 大全

Matlab调用Java版JPEG2000图像压缩工具:jj2000-4.1

2023-12-18 大全 43 作者:考证青年

调用Java版图像压缩工具:-4.1

0. 简介 0.1. JPEG与

大家知道JPEG是基于离散余弦变换(DCT)的图像压缩标准,而是基于小波变换(DWT)的图像压缩标准,当然不同的还有编码算法。JPEG与及其扩展 由 Joint Group 组织创建和维护, 更多信息参见维基百科:,或者JPEG官网: ,里面提供了C++、C、Java等语言的实现,请根据需要自行下载。

0.2. 简介

实现的是标准中的part1部分,纯由Java语言写成,项目官网:,但该网址本人试图访问多次,未果;在JPEG官网也提供了下载链接:,不过版本号是5.1,此外 Code明年将关闭服务,本人将其导出到了,下载链接点我。对于文章使用的版本下载,待会介绍。

1. 工具

硬件:PC机

软件:、、Java虚拟机、-4.1

Note:软件工具下载链接请百度或谷歌,当然,、-4.1、以及基于-5.1修改的的-,也可以点此下载。

是 写的一个调用-4.1.jar工具包的 GUI 程序,为方便使用,本人进行了一定的修改。

2. 步骤与方法 2.0 安装软件工具

没有安装 和 Java虚拟机的,请自行安装。Java虚拟机根据自己需要选择,有: JVM,Sun‘s Java等等,’其环境变量的配置,见2.1软件配置。

和-4.1无需安装,解压即可。

2.1 软件配置 2.1.1 Java虚拟机的环境变量配置

按照提示安装好Java虚拟机后,还需要配置环境变量,按照下述流程打开环境变量设置页:

控制面板( Panel)——>系统()——> 高级系统设置( )——> 高级()——> 环境变量( )

图像压缩的matlab代码_matlabjpeg压缩_

图2-1 环境变量设置界面

如上图所示,包含两类环境变量:用户环境变量 和 系统环境变量。我们需要在用户环境变量中添加 环境变量,在系统变量里添加 环境变量 和 新建(如果没有的话)或修改(如果有的话)PATH环境变量。它们的值如下面绿色部分:

=(是Java的安装路径,如E:\ Files\Java\jdk1.7.0_51)

PATH=.;%%\bin(等同于E:\ Files\Java\jdk1.7.0_51\bin)

=.;%%\lib\dt.jar;%%\lib\tools.jar;

下面,给出图解

参照上图2-1,点击“用户变量(User for ...)” 区域的“新建(New)”,在弹出窗口中,按下图输入, 点击OK,创建环境变量,注意你的JAVA安装路径。

图像压缩的matlab代码__matlabjpeg压缩

图2-2 环境变量

参照上图2-1,点击“系统环境变量( )” 区域的“新建(New)”,在弹出窗口中,输入环境变量名,及其对应的值,点击OK创建。

参照上图2-1,找到“系统环境变量( )” 区域PATH环境变量,点击“编辑(Edit)”,在变量值前端输入PATH的值,如下图2-3所示:

图像压缩的matlab代码_matlabjpeg压缩_

图2-3 给Path环境变量添加值

这样环境变量就配置好了。

测试:为了测试环境变量配置是否成功,在运行里输入cmd,打开DOS窗口,输入:Java -,若输出下图所示信息,则表明配置成功。

图像压缩的matlab代码__matlabjpeg压缩

图2-4 Java 的环境变量配置成功

2.1.2 -4.1.jar工具包的环境变量配置

在-4.1文件夹中找到-4.1.jar(没有的话自行编译),并将其复制到要存放的路径下。

-4.1.jar是一个Java类包,为了能够在任意路径下自由调用,将其路径添加进上面建立的环境变量里去。假设-4.1.jar的路径是:

D:\\\DIP\\\-4.1.jar,那么,就把它添加进环境变量的值里面,用; 隔开,这样就添加好了。

测试:为了测试环境变量配置是否成功,在运行里输入cmd,打开DOS窗口,输入:Java -u,若输出下图所示信息,则表明配置成功,此命令是查看 的使用帮助。

matlabjpeg压缩_图像压缩的matlab代码_

图2-5 参数选项

2.-4.1.jar 的使用 找到中的 文件,使用写字板打开,在里面可以找到,-4.1工具的调用方法。下面进行简要介绍:

下,使用命令添加环境变量:set =/-4.1.jar;%%,其中,,为-4.1.jar所在文件夹路径。

本文使用的是Sun的JDK,编解码命令如下,其它虚拟机请参见 文件。

2.2.1 DOS下执行编解码

下,编码命令:

java

解码命令:

图像压缩的matlab代码_matlabjpeg压缩_

java

其中,,为可选参数,使用Java -u可以查看具体参数选项,如-i 是输入文件参数,-o 是输出文件参数,-rate用以指定压缩比。

如下命令,以“pict.pgm”文件为输入,进行8倍的压缩编码,输出文件为“.j2k”。

Java JJ2KEncoder -i pict.pgm -o pict_JJ2.j2k -rate 1

2.2.2 下通过DOS执行 如果在下调用,可以使用自带的 dos 函数,将命令加载到DOS运行,格式如下,其中,为命令字符串。

[s,w] = dos(cmdstr)

2.2.3 下直接执行Java命令

如果想直接在中使用Java命令,需要在Java命令前加感叹号! ,如在命令窗口,输入:!Java -,则输出,下图所示信息:

图2-6 在中查看 Java 版本信息

同样,如果想运行 命令,可以使用:

!Java JJ2KEncoder -i pict.pgm -o pict_JJ2.j2k -rate 1

2.2. 运行结果示例 实现了在下的调用,请参考之,下面给出本人修改后的一个运行结果图。

matlabjpeg压缩__图像压缩的matlab代码

图2-7 运行结果示例

图中实现的是 16 倍的压缩,PSNR在23.0dB,还是很高的!

3. Note

1. 如果出现调用不成功,而在DOS下调用成功的情况,请注销或重启系统。

2. 在dos下 输入:Java -u >>C:\help.txt,可以将结果输出到help.txt文件。

4. 附录 4.1 参数选项

Usage:JJ2KEncoder args...The exit code of the encoder is non-zero if an error occurs.Note: Many encoder modules accept tile-component specific parameters. Theseparameters must be provided according to the pattern:"[] " (repeated as many time as needed). respect the following policy according to the degreeof priority:(1) t c : Tile-component specification.(2) t : Tile specification.(3) c : Component specification(4)  : Default specification.Where the priorities of the specifications are:(1) > (2) > (3) > (4), ('>' means "overrides"): ',' separates indexes, '-' separates bounds of indexes list. (ex:0,2-4 means indexes 0,2,3 and  4).The following arguments are recognized:-u [on|off] (default = off)Prints usage information. If specified all other arguments (except 'v')are ignored-v [on|off] (default = off)Prints version and copyright information.-verbose (default = on)Prints information about the obtained bit stream.-o Mandatory argument. This option specifies the name of the output fileto which the codestream will be written.-i  [ [ ... ]]Mandatory argument. This option specifies the name of the input imagefiles. Supported formats are PGM (raw), PPM (raw) and PGX, which is asimple extension of the PGM file format for single component datasupporting arbitrary bitdepths. If the extension is '.pgm', PGM-rawfile format is assumed, if the extension is '.ppm', PPM-raw file formatis assumed, otherwise PGX file format is assumed. PGM and PPM files areassumed to be 8 bits deep. A multi-component image can be specified byeither specifying several PPM and/or PGX files, or by specifying onePPM file.-lossless [on|off] (default = off)Specifies a lossless compression for the encoder. This options isequivalent to use reversible quantization ('-Qtype reversible') and 5x3wavelet filters pair ('-Ffilters w5x3'). Note that this option cannotbe used with '-rate'. When this option is off, the quantization typeand the filters pair is defined by '-Qtype' and '-Ffilters'respectively.-rate  (default = 100)This is the output bitrate in bits per pixel.-tref   (default = 0 0)Sets the origin of the tile partitioning on the reference grid, withrespect to the canvas origin. The value of 'x' ('y') specified can notbe larger than the 'x' one specified in the ref option.-ref   (default = 0 0)Sets the origin of the image in the canvas system. It sets thecoordinate of the top-left corner of the image reference grid, withrespect to the canvas origin-tiles   (default = 0 0)This option specifies the maximum tile dimensions to use. If bothdimensions are 0 then no tiling is used.-tile_parts  (default = 0)This option specifies the maximum number of packets to have in onetile-part. 0 means include all packets in first tile-part of each tile-pfile Loads the arguments from the specified file. Arguments that arespecified on the command line override the ones from the file.The arguments file is a simple text file with one argument per line ofthe following form:=If the argument is of boolean type (i.e. its presence turns a featureon), then the 'on' value turns it on, while the 'off' value turns itoff. The argument name does not include the '-' or '+' character. Longlines can be broken into several lines by terminating them with ''.Lines starting with '#' are considered as comments. This option is notrecursive: any 'pfile' argument appearing in the file is ignored.-pph_main [on|off] (default = off)Packs the packet headers in the main header.-pph_tile [on|off] (default = off)Packs the packet headers in the tile headers.-file_format [on|off] (default = off)Puts the JPEG 2000 codestream in a JP2 file format wrapper.-disable_jp2_extension [on|off] (default = off)JJ2000 automatically adds .jp2 extension when using'file_format'option. This option disables it when on.-debug (default = off)Print debugging messages when an error is encountered.-Mct [] [on|off] ...Specifies to use component transformation with some tiles.  If thewavelet transform is reversible (w5x3 filter), the Reversible ComponentTransformation (RCT) is applied. If not (w9x7 filter), the IrreversibleComponent Transformation (ICT) is used.-Ffilters []  [ []  ...]Specifies which filters to use for specified tile-component.: see general note: ',' separates horizontal and vertical filters, ':' separatesdecomposition levels filters. JPEG 2000 part I only supports w5x3 andw9x7 filters.-Wwt [full] (default = full)Specifies the wavelet transform to be used. Possible value is: 'full'(full page). The value 'full' performs a normal DWT.-Wlev  (default = 5)Specifies the number of wavelet decomposition levels to apply to theimage. If 0 no wavelet transform is performed. All components and alltiles have the same number of decomposition levels.-Qguard_bits []  [ [] ...] (default = 2)The number of bits used for each tile-component in the quantizer toavoid overflow (gb).-Qstep []  [ []  ...](default = 0.0078125)This option specifies the base normalized quantization step size (bnss)for tile-components. It is normalized to a dynamic range of 1 in theimage domain. This parameter is ignored in reversible coding.-Qtype []  [ []  ...]Specifies which quantization type to use for specified tile-component.By default (if '-lossless is not specified'), the quantization stepsize is 'expounded'. : see general note.: Supported quantization types specification are : 'reversible' (noquantization), 'derived' (derived quantization step size) and'expounded'.Example: -Qtype reversible or -Qtype t2,4-8 c2 reversible t9 derived.-Rno_rect [on|off] (default = off)This argument makes sure that the ROI mask generation is not done usingthe fast ROI mask generation for rectangular ROIs regardless of whetherthe specified ROIs are rectangular or not-Rstart_level  (default = -1)This argument forces the lowest  resolution levels to belong tothe ROI. By doing this, it is possible to avoid only gettinginformation for the ROI at an early stage of transmission. = 0means the lowest resolution level belongs to the ROI, 1 means the twolowest etc. (-1 deactivates the option)-Ralign [on|off] (default = off)By specifying this argument, the ROI mask will be limited to coveringonly entire code-blocks. The ROI coding can then be performed withoutany actual scaling of the coefficients but by instead scaling thedistortion estimates.-Rroi [] R     or [] C    or [] ASpecifies ROIs shape and location. The shape can be either rectangular'R', or circular 'C' or arbitrary 'A'. Each new occurrence of an 'R', a'C' or an 'A' is a new ROI. For circular and rectangular ROIs, allvalues are given as their pixel values relative to the canvas origin.Arbitrary shapes must be included in a PGM file where non 0 valuescorrespond to ROI coefficients. The PGM file must have the size as theimage. The component idx specifies which components contain the ROI.The component index is specified as described by points 3 and 4 in thegeneral comment on tile-component idx. If this option is used, thecodestream is layer progressive by default unless it is overridden bythe 'Aptype' option.-Cpp []   [ ] [ [] ...]Specifies precinct partition dimensions for tile-component. The firsttwo values apply to the highest resolution and the following ones (ifany) apply to the remaining resolutions in decreasing order. If lessvalues than the number of decomposition levels are specified, then thelast two values are used for the remaining resolutions.-Clen_calc [] near_opt|lazy_good|lazy[[] ...] (default = near_opt)Specifies the algorithm to use in calculating the necessary MQ lengthfor each decoding pass. The best one is 'near_opt', which performs arather sophisticated calculation and provides the best results. The'lazy_good' and 'lazy' are very simple algorithms that provide ratherconservative results, 'lazy_good' one being slightly better. Do notchange this option unless you want to experiment the effect ofdifferent length calculation algorithms.-Cterm [] near_opt|easy|predict|full[[] near_opt|easy|predict|full ...] (default =near_opt)Specifies the algorithm used to terminate the MQ codeword. The mostefficient one is 'near_opt', which delivers a codeword which in almostall cases is the shortest possible. The 'easy' is a simpler algorithmthat delivers a codeword length that is close to the previous one (inaverage 1 bit longer). The 'predict' is almost the same as the 'easy'but it leaves error resilient information on the spare leastsignificant bits (in average 3.5 bits), which can be used by a decoderto detect errors. The 'full' algorithm performs a full flush of the MQcoder and is highly inefficient.It is important to use a good termination policy since the MQ codewordcan be terminated quite often, specially if the 'Cbypass' or'Creg_term' options are enabled (in the normal case it would beterminated once per code-block, while if 'Creg_term' is specified itwill be done almost 3 times per bit-plane in each code-block).-Cseg_symbol [] on|off[ [] on|off...] (default = off)Inserts an error resilience segmentation symbol in the MQ codeword atthe end of each bit-plane (cleanup pass). Decoders can use thisinformation to detect and conceal errors.'on' enables, 'off' disablesit.-Ccausal [] on|off[ [] on|off...] (default = off)Uses vertically stripe causal context formation. If this is enabled thecontext formation process in one stripe is independant of the nextstripe (i.e. the one below it). 'on' enables, 'off' disables it.-Creg_term [] on|off[ [] on|off...] (default = off)If this is enabled the codeword (raw or MQ) is terminated on a byteboundary after each coding pass. In this case it is important to use anefficient termination algorithm, see the 'Cterm' option. 'on' enables,'off' disables it.-CresetMQ [] on|off[ [] on|off...] (default = off)If this is enabled the probability estimates of the MQ coder are resetafter each arithmetically coded (i.e. non-lazy) coding pass. 'on'enables, 'off' disables it.-Cbypass [] on|off[ [] on|off...] (default = off)Uses the lazy coding mode with the entropy coder. This will bypass theMQ coder for some of the coding passes, where the distribution is oftenclose to uniform. Since the MQ codeword will be terminated at leastonce per lazy pass, it is important to use an efficient terminationalgorithm, see the 'Cterm' option.'on' enables, 'off' disables it.-Cblksiz []   [[] ] (default = 64 64)Specifies the maximum code-block size to use for tile-component. Themaximum width and height is 1024, however the surface area (i.e. widthx height) must not exceed 4096. The minimum width and height is 4.-Alayers  [+] [] [...]] (default = 0.015+20 2.0 +10)Explicitly specifies the codestream layer formation parameters. The parameter specifies the bitrate to which the first layer shouldbe optimized. The  parameter, if present, specifies the numberof extra layers that should be added for scalability. These extralayers are not optimized. Any extra  and  parameters addmore layers, in the same way. An additional layer is always added atthe end, which is optimized to the overall target bitrate of the bitstream. Any layers (optimized or not) whose target bitrate is higherthat the overall target bitrate are silently ignored. The bitrates ofthe extra layers that are added through the  parameter areapproximately log-spaced between the other target bitrates. If several [+] constructs appear the  parameters must appearin increasing order. The rate allocation algorithm ensures that allcoded layers have a minimal reasonable size, if not these layers aresilently ignored.-Aptype [] res|layer|res-pos|pos-comp|comp-pos [res_startcomp_start layer_end res_end comp_end prog] [[res_start comp_startly_end res_end comp_end prog] ...] [[] ...]Specifies which type of progression should be used when generating thecodestream. The 'res' value generates a resolution progressivecodestream with the number of layers specified by 'Alayers' option. The'layer' value generates a layer progressive codestream with multiplelayers. In any case the rate-allocation algorithm optimizes for bestquality in each layer. The quality measure is mean squared error (MSE)or a weighted version of it (WMSE). If no progression type is specifiedor imposed by other modules, the default value is 'layer'.It is also possible to describe progression order changes. In thiscase, 'res_start' is the index (from 0) of the first resolution level,'comp_start' is the index (from 0) of the first component, 'ly_end' isthe index (from 0) of the first layer not included, 'res_end' is theindex (from 0) of the first resolution level not included, 'comp_end'is index (from 0) of the first component not included and 'prog' is theprogression type to be used for the rest of the tile/image. Severalprogression order changes can be specified, one after the other.-Peph [] on|off[ [] on|off ...] (default = off)Specifies whether end of packet header (EPH) markers should be  used.'on' enables, 'off' disables it.-Psop [] on|off[ [] on|off ...] (default = off)Specifies whether start of packet (SOP) markers should be used. 'on'enables, 'off' disables it.Send bug reports to: jj2000-bugs@ltssg3.epfl.ch

4.2 参数选项

Usage:JJ2KDecoder args...The exit code of the decoder is non-zero if an error occurs.The following arguments are recongnized:-Cer [on|off] (default = on)Specifies if error detection should be performed by the entropy decoderengine. If errors are detected they will be concealed and the resultingdistortion will be less important. Note that errors can only bedetected if the encoder that generated the data included errorresilience information.-Cverber [on|off] (default = on)Specifies if the entropy decoder should be verbose about detectederrors. If 'on' a message is printed whenever an error is detected.-Rno_roiThis argument makes sure that the no ROI de-scaling is performed.Decompression is done like there is no ROI in the image-cdstr_info (default = off)Display information about the codestream. This information is:- Marker segments value in main and tile-part headers,- Tile-part length and position within the code-stream.-debug (default = off)Print debugging messages when an error is encountered.-parsing (default = on)Enable or not the parsing mode when decoding rate is specified('-nbytes' or '-rate' options). If it is false, the codestream isdecoded as if it were truncated to the given rate. If it is true, thedecoder creates, truncates and decodes a virtual layer progressivecodestream with the same truncation points in each code-block.-nbytes  (default = -1)Specifies the decoding rate in bytes. The codestream is either parsed(default) or truncated depending the command line option '-parsing'. Tospecify the decoding rate in bits per pixel, use '-rate' optionsinstead.-rate  (default = 100)Specifies the decoding rate in bits per pixel (bpp) where the number ofpixels is related to the image's original size (Note: this number isnot affected by the '-res' option). The codestream is either parsed(default) or truncated depending the command line option '-parsing'. Tospecify the decoding rate in bytes, use '-nbytes' options instead.-o This is the name of the file to which the decompressed image iswritten. If no output filename is given, the image is displayed on thescreen. Output file format is PGX by default. If the extension is'.pgm' then a PGM file is written as output, however this is onlypermitted if the component bitdepth does not exceed 8. If the extensionis '.ppm' then a PPM file is written, however this is only permitted ifthere are 3 components and none of them has a bitdepth of more than 8.If there is more than 1 component, suffices '-1', '-2', '-3', ... areadded to the file name, just before the extension, except for PPM fileswhere all three components are written to the same file.-i The file containing the JPEG 2000 compressed data. This can be either aJPEG 2000 codestream or a JP2 file containing a JPEG 2000 codestream.In the latter case the first codestream in the file will be decoded. Ifan URL is specified (e.g., http://...) the data will be downloaded andcached in memory before decoding. This is intended for easy use inapplets, but it is not a very efficient way of decoding network serveddata.-res Specifies the resolution level wanted for the decoded image (0 meansthe lowest available resolution, the last resolution  level gives animage with original dimension). If given index is greater than thenumber of available resolution levels of the compressed image, thedecoded image has the lowest available resolution (among alltile-components). Note that this option affects only the inversewavelet transform and not the number  of bytes read by the codestreamparser: this number of bytes depends only on options '-nbytes' or'-rate'.-pfile Loads the arguments from the specified file. Arguments that arespecified on the command line override the ones from the file.The arguments file is a simple text file with one argument per line ofthe following form:=If the argument is of boolean type (i.e. its presence turns a featureon), then the 'on' value turns it on, while the 'off' value turns itoff. The argument name does not include the '-' or '+' character. Longlines can be broken into several lines by terminating them with '\'.Lines starting with '#' are considered as comments. This option is notrecursive: any 'pfile' argument appearing in the file is ignored.-verbose [on|off] (default = on)Prints information about the decoded codestream-v [on|off] (default = off)Prints version and copyright information-u [on|off] (default = off)Prints usage information. If specified all other arguments (except 'v')are ignoredSend bug reports to: jj2000-bugs@ltssg3.epfl.ch

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了