⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wm_bruyn_e.c

📁 包含了多个matlab编程在图像中加入水印的处理代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "wm.h"#include "signature.h"#include "coord.h"#include "gray.h"#include "sort.h"#include "bruyn_common.h"#include "pgm.h"char *progname;// prints out program's parametersvoid usage(void) {  fprintf(stderr, "usage: %s [-b n] [-h] [-k] [-n n] [-o file] [-pP n] [-q n] [-tT n] [-v n] -s file file\n", progname);  fprintf(stderr, "\t-b n\t\tblock size\n");  fprintf(stderr, "\t-h\t\tprint usage\n");  fprintf(stderr, "\t-k\t\tdisable block skipping\n");  fprintf(stderr, "\t-n n\t\tnumber of signature bits to embed\n");  fprintf(stderr, "\t-o file\t\toutput (watermarked) file\n");  fprintf(stderr, "\t-p n\t\tpattern type for zone 1\n");  fprintf(stderr, "\t-P n\t\tpattern type for zone 2\n");  fprintf(stderr, "\t-q n\t\tsignature strength\n");  fprintf(stderr, "\t-s file\t\tsignature to embed in input image\n");  fprintf(stderr, "\t-t n\t\tthreshold for noise\n");  fprintf(stderr, "\t-T n\t\tthreshold for slope\n");  fprintf(stderr, "\t-v n\t\tverbosity level\n");  exit(0);}int main(int argc, char *argv[]) {  FILE *in = stdin;  FILE *out = stdout;  FILE *sig = NULL;  gray** image;  gray **block;  gray **zone;  gray **category1, **category2;  gray maxval;  double *slope;  int rows, cols, colors, format;  int c;  int i, j;  int r;  int n;  int col, row;  int bwidth, bheight;  int n_block;  int skipping = 0;  char signature_name[MAXPATHLEN];  char input_name[MAXPATHLEN] = "(stdin)";  char output_name[MAXPATHLEN] = "(stdout)";  double quality = 0.0;  double threshold_noise = 0.0;  double threshold_slope = 0.0;  int pattern1 = 0;  int pattern2 = 0;  int blocksize = 0;  int seed;  int verbose = 0;  struct coords *coords;  progname = argv[0];  pgm_init(&argc, argv); wm_init();  // parse command line and set options  while ((c = getopt(argc, argv, "b:h?n:o:p:P:q:s:t:T:v:k")) != EOF) {    switch (c) {      case 'k':          skipping = 1;        break;      case 'h':      case '?':        usage();        break;      case 'n':        nbit_signature = atoi(optarg);        if (nbit_signature <= 0 || nbit_signature > NBITSIGNATURE) {          fprintf(stderr, "%s: invalid signature length %d\n", progname, nbit_signature);          exit(1);        }        break;      case 'o':        if ((out = fopen(optarg, "wb")) == NULL) {          fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);          exit(1);        }        strcpy(output_name, optarg);        break;      case 'p':        pattern1 = atoi(optarg);        if (pattern1 <= 0 || pattern1 > NPATTERN) {          fprintf(stderr, "%s: pattern type out of range\n", progname);          exit(1);        }        break;      case 'P':        pattern2 = atoi(optarg);        if (pattern2 <= 0 || pattern2 > 3) {          fprintf(stderr, "%s: pattern type out of range\n", progname);          exit(1);        }        break;      case 'q':        quality = atof(optarg);        if (quality <= 0) {          fprintf(stderr, "%s: quality factor %f out of range\n", progname, quality);        }        break;      case 's':        if ((sig = fopen(optarg, "r")) == NULL) {          fprintf(stderr, "%s: unable to open signature file %s\n", progname, optarg);          exit(1);        }        strcpy(signature_name, optarg);        break;      case 't':        threshold_noise = atof(optarg);        if (threshold_noise <= 0) {          fprintf(stderr, "%s: noise threshold %f out of range\n", progname, threshold_noise);        }        break;      case 'T':        threshold_slope = atof(optarg);        if (threshold_slope <= 0) {          fprintf(stderr, "%s: slope threshold %f out of range\n", progname, threshold_slope);        }        break;      case 'v':        verbose = atoi(optarg);        if (verbose < 0) {          fprintf(stderr, "%s: verbosity level %d out of range\n",progname, verbose);          exit(1);        }        break;    }  }  argc -= optind;  argv += optind;  if (argc > 1) {    usage();    exit(1);  }  // open input image file or read from stdin  if (argc == 1 && *argv[0] != '-')    if ((in = fopen(argv[0], "rb")) == NULL) {      fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);      exit(1);    }    else      strcpy(input_name, argv[0]);  // read signature file and set options  // command line options override signature file options  if (sig) {    char line[128];    fgets(line, sizeof(line), sig);    if (strspn(line, "BRSG") >= 4) {      if (nbit_signature == 0)        fscanf(sig, "%d\n", &nbit_signature);      else        fscanf(sig, "%*d\n");      if (skipping == 0)        fscanf(sig, "%d\n", &skipping);      else        fscanf(sig, "%*d\n");      if (pattern1 == 0)        fscanf(sig, "%d\n", &pattern1);      else        fscanf(sig, "%*d\n");      if (pattern2 == 0)        fscanf(sig, "%d\n", &pattern2);      else        fscanf(sig, "%*d\n");      if (quality == 0.0)        fscanf(sig, "%lf\n", &quality);      else        fscanf(sig, "%*lf\n");      if (threshold_noise == 0.0)        fscanf(sig, "%lf\n", &threshold_noise);      else        fscanf(sig, "%*lf\n");      if (threshold_slope == 0.0)        fscanf(sig, "%lf\n", &threshold_slope);      else        fscanf(sig, "%*lf\n");      if (blocksize == 0)        fscanf(sig, "%d\n", &blocksize);      else        fscanf(sig, "%*d\n");      fscanf(sig, "%d\n", &seed);      srandom(seed);      n_signature = NBITSTOBYTES(nbit_signature);      fread(signature, sizeof(char), n_signature, sig);      fscanf(sig, "\n");    }    else {      fprintf(stderr, "%s: invalid signature file %s\n", progname, signature_name);      exit(1);    }    fclose(sig);  }  else {    fprintf(stderr, "%s: signature file not specified, use -s file option\n", progname);    exit(1);  }  if (pattern1 <= 0 || pattern2 <= 0 || pattern1 > NPATTERN || pattern2 > NPATTERN) {    fprintf(stderr, "%s: invalid pattern type specified\n");    exit(1);  }  // read dimensions of input image file  pgm_readpgminit(in, &cols, &rows, &maxval, &format);  // see if we can embed all signature bits  // we want at least half of the blocks untouched  if (((rows / blocksize) * (cols / blocksize)) < nbit_signature / 2) {    fprintf(stderr, "%s: image not large enough to embed %d bits of signature\n", progname, nbit_signature);    exit(1);  }  n_block = blocksize * blocksize;  // allocate structure to remember which blocks we already touched,  // allow plenty of room to skip over blocks  if ((coords = alloc_coords(nbit_signature * 2)) == NULL) {    fprintf(stderr, "%s: unable to allocate memory\n", progname);    exit(1);  }  // read in input image file  image = pgm_allocarray(cols, rows);  for (row = 0; row < rows; row++)    pgm_readpgmrow(in, image[row], cols, maxval, format);  fclose(in);  row = 0;  col = 0;  // allocate memory for one block  block = alloc_grays(blocksize, blocksize);  // allocate memory for zone classification  zone = alloc_grays(blocksize, blocksize);  // allocate memory for category classification  category1 = alloc_grays(blocksize, blocksize);  category2 = alloc_grays(blocksize, blocksize);  // set up category classification array according to   // pattern type parameter  for (i = 0; i < blocksize; i++)    for (j = 0; j < blocksize; j++) {      category1[j][i] = lookup_pattern(pattern1, i, j);      category2[j][i] = lookup_pattern(pattern2, i, j);    }  // allocate memory for slope calculation  slope = malloc(sizeof(double) * n_block);  // embed all the signature bits, one by one  n = 0;  while (n < nbit_signature) {    int xb;    int yb;    int blocktype;    double smax;    int alpha, beta_minus, beta_plus;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -