imgcmp.c
来自「SumatraPDF是一款小型开源的pdf阅读工具。虽然玲珑小巧(只有800多K」· C语言 代码 · 共 578 行 · 第 1/2 页
C
578 行
/*
* Copyright (c) 2001-2003 Michael David Adams.
* All rights reserved.
*/
/* __START_OF_JASPER_LICENSE__
*
* JasPer License Version 2.0
*
* Copyright (c) 1999-2000 Image Power, Inc.
* Copyright (c) 1999-2000 The University of British Columbia
* Copyright (c) 2001-2003 Michael David Adams
*
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person (the
* "User") obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge,
* publish, distribute, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* 1. The above copyright notices and this permission notice (which
* includes the disclaimer below) shall be included in all copies or
* substantial portions of the Software.
*
* 2. The name of a copyright holder shall not be used to endorse or
* promote products derived from the Software without specific prior
* written permission.
*
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
* LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
* THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
* "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
* INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
* FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
* PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
* THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
* EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
* BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
* PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
* GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
* ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
* IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
* SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
* SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
* THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
* PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
* RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
* EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
*
* __END_OF_JASPER_LICENSE__
*/
/*
* Image Comparison Program
*
* $Id$
*/
/******************************************************************************\
* Includes.
\******************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <assert.h>
#include <jasper/jasper.h>
/******************************************************************************\
*
\******************************************************************************/
typedef enum {
OPT_HELP,
OPT_VERSION,
OPT_VERBOSE,
OPT_ORIG,
OPT_RECON,
OPT_METRIC,
OPT_MAXONLY,
OPT_MINONLY,
OPT_DIFFIMAGE
} optid_t;
typedef enum {
metricid_none = 0,
metricid_equal,
metricid_psnr,
metricid_mse,
metricid_rmse,
metricid_pae,
metricid_mae
} metricid_t;
/******************************************************************************\
*
\******************************************************************************/
double getdistortion(jas_matrix_t *orig, jas_matrix_t *recon, int depth, int metric);
double pae(jas_matrix_t *x, jas_matrix_t *y);
double msen(jas_matrix_t *x, jas_matrix_t *y, int n);
double psnr(jas_matrix_t *x, jas_matrix_t *y, int depth);
jas_image_t *makediffimage(jas_matrix_t *origdata, jas_matrix_t *recondata);
void usage(void);
void cmdinfo(void);
/******************************************************************************\
*
\******************************************************************************/
static jas_taginfo_t metrictab[] = {
{metricid_mse, "mse"},
{metricid_pae, "pae"},
{metricid_rmse, "rmse"},
{metricid_psnr, "psnr"},
{metricid_mae, "mae"},
{metricid_equal, "equal"},
{-1, 0}
};
static jas_opt_t opts[] = {
{OPT_HELP, "help", 0},
{OPT_VERSION, "version", 0},
{OPT_VERBOSE, "verbose", 0},
{OPT_ORIG, "f", JAS_OPT_HASARG},
{OPT_RECON, "F", JAS_OPT_HASARG},
{OPT_METRIC, "m", JAS_OPT_HASARG},
{OPT_MAXONLY, "max", 0},
{OPT_MINONLY, "min", 0},
{OPT_DIFFIMAGE, "d", JAS_OPT_HASARG},
{-1, 0, 0}
};
static char *cmdname = 0;
/******************************************************************************\
* Main program.
\******************************************************************************/
int main(int argc, char **argv)
{
char *origpath;
char *reconpath;
int verbose;
char *metricname;
int metric;
int id;
jas_image_t *origimage;
jas_image_t *reconimage;
jas_matrix_t *origdata;
jas_matrix_t *recondata;
jas_image_t *diffimage;
jas_stream_t *diffstream;
int width;
int height;
int depth;
int numcomps;
double d;
double maxdist;
double mindist;
int compno;
jas_stream_t *origstream;
jas_stream_t *reconstream;
char *diffpath;
int maxonly;
int minonly;
int fmtid;
verbose = 0;
origpath = 0;
reconpath = 0;
metricname = 0;
metric = metricid_none;
diffpath = 0;
maxonly = 0;
minonly = 0;
if (jas_init()) {
abort();
}
cmdname = argv[0];
/* Parse the command line options. */
while ((id = jas_getopt(argc, argv, opts)) >= 0) {
switch (id) {
case OPT_MAXONLY:
maxonly = 1;
break;
case OPT_MINONLY:
minonly = 1;
break;
case OPT_METRIC:
metricname = jas_optarg;
break;
case OPT_ORIG:
origpath = jas_optarg;
break;
case OPT_RECON:
reconpath = jas_optarg;
break;
case OPT_VERBOSE:
verbose = 1;
break;
case OPT_DIFFIMAGE:
diffpath = jas_optarg;
break;
case OPT_VERSION:
printf("%s\n", JAS_VERSION);
exit(EXIT_SUCCESS);
break;
case OPT_HELP:
default:
usage();
break;
}
}
if (verbose) {
cmdinfo();
}
/* Ensure that files are given for both the original and reconstructed
images. */
if (!origpath || !reconpath) {
usage();
}
/* If a metric was specified, process it. */
if (metricname) {
if ((metric = (jas_taginfo_nonull(jas_taginfos_lookup(metrictab,
metricname))->id)) < 0) {
usage();
}
}
/* Open the original image file. */
if (!(origstream = jas_stream_fopen(origpath, "rb"))) {
jas_eprintf("cannot open %s\n", origpath);
return EXIT_FAILURE;
}
/* Open the reconstructed image file. */
if (!(reconstream = jas_stream_fopen(reconpath, "rb"))) {
jas_eprintf("cannot open %s\n", reconpath);
return EXIT_FAILURE;
}
/* Decode the original image. */
if (!(origimage = jas_image_decode(origstream, -1, 0))) {
jas_eprintf("cannot load original image\n");
return EXIT_FAILURE;
}
/* Decoder the reconstructed image. */
if (!(reconimage = jas_image_decode(reconstream, -1, 0))) {
jas_eprintf("cannot load reconstructed image\n");
return EXIT_FAILURE;
}
/* Close the original image file. */
jas_stream_close(origstream);
/* Close the reconstructed image file. */
jas_stream_close(reconstream);
/* Ensure that both images have the same number of components. */
numcomps = jas_image_numcmpts(origimage);
if (jas_image_numcmpts(reconimage) != numcomps) {
jas_eprintf("number of components differ\n");
return EXIT_FAILURE;
}
/* Compute the difference for each component. */
maxdist = 0;
mindist = FLT_MAX;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?