Beispiel #1
0
void dct_image_tst()
{
  int i, j ;

  static float im1[3] = { 1, 2, 3 } ; 
  static float im2[3] = { 4, 5, 6 } ; 
  static float im3[3] = { 7, 8, 9 } ; 
  static float *im[] = { im1, im2, im3 } ;

  static float jm1[3] = { 1, 2, 3 } ; 
  static float jm2[3] = { 4, 5, 6 } ; 
  static float jm3[3] = { 7, 8, 9 } ; 
  static float *jm[] = { jm1, jm2, jm3 } ;

  static float ir1[3] = {15      ,-2.44949,0} ;
  static float ir2[3] = {-7.34847,0       ,0} ;
  static float ir3[3] = {0       ,0       ,0} ;
  static float *ir[] = { ir1, ir2, ir3 } ;

  dct_image(0, 3, im) ;

  for(j=0; j<3; j++)
    for(i=0; i<3; i++)
      if ( fabs(im[j][i] - ir[j][i]) > 1e-4 )
	{
	  eprintf("[%d][%d] = %g au lieu de %g\n", j, i, im[j][i], ir[j][i]) ;
	}

  dct_image(1, 3, ir) ;
  for(j=0; j<3; j++)
    for(i=0; i<3; i++)
      if ( fabs(jm[j][i] - ir[j][i]) > 1e-4 )
	{
	  eprintf("*[%d][%d] = %g au lieu de %g\n", j, i, ir[j][i], jm[j][i]) ;
	}
}
Beispiel #2
0
void DctEmbedWatermark(const cv::Mat& image, cv::Mat& output, long frame_num)
{
	output=image.clone();
	imwrite("./res/oringin.bmp", image);
	cv::Mat watermark = cv::imread("./res/name.bmp");
	int image_height = image.rows;
	int image_width = image.cols;
	int watermark_height = watermark.rows;
	int watermark_width = watermark.cols;
	double step_height = (double)image_height / watermark_height;
	double step_width = (double)image_width / watermark_width;
	int block_height = floor(step_height);
	int block_width = floor(step_width);
	printf("block_height%d\n",block_height); 
	printf("block_width%d\n", block_width);
	// Make sure the both image dimensions are a multiple of 2
	if (block_height % 2 == 0)
		block_height = block_height;
	else
		block_height = block_height - 1;
	if (block_width % 2 == 0)
		block_width = block_width;
	else
		block_width = block_width - 1;
	// Grayscale image is 8bits per pixel,
	// but dct() method wants float values!
	cv::Mat dct_image = cv::Mat(image.rows, image.cols, CV_64F);
	image.convertTo(dct_image, CV_64F);
	int index = 0;
	for (int i = 0; i<watermark_height; i++)
		for (int j = 0; j < watermark_width; j++)//watermark_height*watermark_widthµÄ´óÑ­»·
		{
			cv::Rect rect(floor(j*step_width), floor(i*step_height), block_width, block_height);
			printf("x%f  y%f\n", i*step_height, j*step_width);
			cv::Mat image_roi;
			// Let's do the DCT now: image => frequencies
			cv::dct(dct_image(rect), image_roi);
			image_roi.at<double>(1, 0) = 0.0;
			cv::Mat image_out(image_roi.size(), image_roi.type());
			cv::idct(image_roi, image_out);
			image_out.copyTo(output(rect));
		}
	// Save a visualization of the DCT coefficients
	imwrite("./res/dct.bmp", dct_image);
	output.convertTo(output, CV_8UC1);
	imshow("out", output);
	imwrite("./res/output.bmp", output);
}
Beispiel #3
0
/*
 * Décompression image
 * On récupère la DCT de chaque fichier, on fait l'inverse et
 * on insère dans l'image qui est déjà allouée
 */
void decompresse_image(int nbe, struct image *entree, FILE *f)
 {
  static float **tmp = NULL ;
  int i, j, k ;

  if ( tmp == NULL )
    {
      tmp = allocation_matrice_carree_float(nbe) ;
    }

  for(j=0;j<entree->hauteur;j+=nbe)
    for(i=0;i<entree->largeur;i+=nbe)
      {
	for(k=0; k<nbe; k++)
	  assert(fread(tmp[k], sizeof(**tmp), nbe, f) == nbe) ;
	dct_image(1, nbe, tmp) ;
	insert_matrice(j, i, nbe, tmp, entree) ;
      }
 }