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

📄 lcollage_search.c

📁 数字水印技术处理程序集合
💻 C
📖 第 1 页 / 共 2 页
字号:
												
			/* Computation for the least square method */
			som_dc = 0.0;
			var_dc = 0.0;
			for (i=0;i<DIM_MASK;i++){
				tmp = d_reduce[i]*MASQUE[i];
				som_dc += tmp;
				var_dc += tmp*d_reduce[i];
			}
			
			/* Fill the dictionnary with the transformed Domain blocks
         Applies each allowed transformation  to the Domain Block
       */
			for( m=0 ; m < NB_GEOM_TRANS; m++ ){
				(*pt_tfgeo[m])(d_reduce,dim_r,d_dictionnary[m]); 											
				s_o_ss_compute(d_dictionnary[m],r,dim_r,som_dc,som_r,var_dc,var_r,&s,&o,&err_codage);
														
				/* We choose the "best" error
				   the FIRST value is used to init the error
         */

				if (err_codage < (float) seuil){
					if (err_codage >= max_err){
						max_err = err_codage;
						max_xd  = xd;
						max_yd  = yd;
						max_m   = m;
						max_s   = s;
						max_o   = o;
					}
				}
				else{
					if (err_codage < min_err || min_err == -1){
						min_err = err_codage;	
						min_xd  = xd;
						min_yd  = yd;
						min_m   = m;
						min_s   = s;
						min_o   = o;
					}
				}
			}  /* for m */
		}   /* for xd */
	} /* for yd */
	
	if (min_err == -1){
		best_err = max_err;	
		best_xd  = max_xd;
		best_yd  = max_yd;
		best_m   = max_m;
		best_s   = max_s;
		best_o   = max_o;
	}
	else{
		best_err = min_err;	
		best_xd  = min_xd;
		best_yd  = min_yd;
		best_m   = min_m;
		best_s   = min_s;
		best_o   = min_o;
	}

	BlockGet(search_win, IFS_WIN_D, IFS_DIM_D_H,IFS_DIM_D_V,best_xd+IFS_WIN_D*best_yd,d_reduce);								
	/* BlockSubSampling(d,IFS_DIM_D_H,IFS_DIM_D_V,dim_r,d_reduce); */

	(*pt_tfgeo[best_m])(d_reduce,dim_r,d_dictionnary[best_m]); 
		
	for (j = 0; j < dim_r; j++)
		for (i = 0; i < dim_r; i++)
			d_reduce[i+j*dim_r] = (image)(d_dictionnary[best_m][i+j*dim_r]*best_s+best_o);


	/* Free memory */
		
	free(d);
	free(search_win);
	for(m=0;m<NB_GEOM_TRANS;m++) {
		free(d_dictionnary[m]);
	}
	free(d_dictionnary);
	return(best_err);
}



/*--------------------------------------------------------------------------------*
 | This function performs a simple IFS iteration without thresholding.            |
 | It stores the errors in an array in order to build the cumulative histogram    |
 | later.                                                                         |
 *--------------------------------------------------------------------------------*/

void simpleSearchIFS(image* image_orig, int width, int height, image* image_water,
					 image * attracteur, float **hist, long *numSample) {
	int xr,yr;
	const int dim_r = IFS_DIM_R;
	int dim_r2;
				
	block *range;          /* Range block                     */
	block *domain;         /* Domain block reduced to Ri size */
	float min_err, min_err2;

	dim_r2=dim_r*dim_r;

	(*hist) = (float *) calloc(width*height,sizeof(float));

	range = BlockAlloc(dim_r ,dim_r);
	domain = BlockAlloc(dim_r ,dim_r);

	/* Image scanning Range Block per Range Block. For each
     Range Block computation of the value of each pixel and the sume
     of the squared values 
   */
	(*numSample) = 0;
	for(  yr = 0; yr <= height-dim_r; yr += IFS_STEP_R ) {
		for( xr = 0; xr <= width-dim_r; xr += IFS_STEP_R ) {
			/* Range block extraction  */
			BlockGet(image_water, width, dim_r, dim_r, xr+yr*width, range);

			/* Domain block association */
			min_err = super_collage_spa(range, dim_r, xr, yr, 0,0, image_orig,
										width, height, domain, NO_THRESHOLD);
			if (min_err > dim_r2) {
				min_err2=super_collage_spa(range, dim_r, xr, yr, 0.75, 0.75, image_orig,
										   width, height, domain, NO_THRESHOLD);
				if (min_err2 > min_err) {
					min_err=super_collage_spa(range, dim_r, xr, yr, 0,0, image_orig,
											  width, height, domain, NO_THRESHOLD);
				}
				else
					min_err=min_err2;
			}

			/* Memorize the error */
			(*hist)[*numSample] = min_err;
			(*numSample)++;
		} /* for xr */
	} /* for yr */

	/* Free memory */
	free(range);
	free(domain);
}


/*--------------------------------------------------------------------------------*
 | This function performs an IFS iteration with thresholding and collate the      |
 | different parts of the attacked image.                                         |
 *--------------------------------------------------------------------------------*/

void collageSearchIFS(image* image_orig, int width, int height,
			 		  image* image_water, image * attracteur, int seuil) {
	int xr,yr;
	int i;
	const int dim_r = IFS_DIM_R;
	int dim_r2;
				
	block *range;          /* Range block                     */
	block *domain;         /* Domain block reduced to Ri size */
	float min_err, min_err2;

	double *image_tmp;
	double *masque_global;
	double *block_mask;
	
	dim_r2=dim_r*dim_r;

	image_tmp = (double *) calloc(width*height,sizeof(double));
	masque_global = (double *) calloc(width*height,sizeof(double));
	block_mask = (double *) calloc(dim_r*dim_r,sizeof(double));

	range = BlockAlloc(dim_r ,dim_r);
	domain = BlockAlloc(dim_r ,dim_r);

	/* Image scanning Range Block per Range Block. For each
     Range Block computation of the value of each pixel and the sume
     of the squared values 
   */
	for(  yr = 0; yr <= height-dim_r; yr += IFS_STEP_R ) {
		for( xr = 0; xr <= width-dim_r; xr += IFS_STEP_R ) {
			/* Range block extraction  */
			BlockGet(image_water, width, dim_r, dim_r, xr+yr*width, range);

			/* Domain block association */
			min_err = super_collage_spa(range, dim_r, xr, yr, 0,0, image_orig,
										width, height, domain, seuil);
			if (min_err > dim_r2) {
				min_err2=super_collage_spa(range, dim_r, xr, yr, 0.75, 0.75, image_orig,
										   width, height, domain, seuil);
				if (min_err2 > min_err) {
					min_err=super_collage_spa(range, dim_r, xr, yr, 0,0, image_orig,
											  width, height,  domain, seuil);
				}
				else
					min_err=min_err2;
			}

			/* Block copy */
			BlockMasque(domain, dim_r, block_mask);
			BlockAdd(block_mask, width, dim_r, xr+yr*width, image_tmp);						
			BlockAddMasque(masque_global, width, dim_r, xr+yr*width);
		} /* for xr */
	} /* for yr */

	/* Free memory */
	free(range);
	free(domain);
	free(block_mask);

	/* Normalisation after masking */
	for (i =0; i < width*height; i++){
		if (masque_global[i]<1)
			attracteur[i] = (block) ( (1-masque_global[i])*((double)image_water[i]) + image_tmp[i] + .5);
		else
			attracteur[i] = (block) ( image_tmp[i]/masque_global[i] + .5);
	}
				
	/* Free memory */
	free(masque_global);
	free(image_tmp);
}


/*--------------------------------------------------------------------------------*
 | This function builds the cumulative histogram of an array given in input and   |
 | returns an adaptative threshold.                                               |
 *--------------------------------------------------------------------------------*/

int _compare( const void *arg1, const void *arg2 )
{
  float v1 = *(float *) arg1, v2 = *(float *)arg2;
  if (v1 < v2) return -1;
  if (v2 < v1) return 1;
  return 0;
}


int findAdaptativeThreshold(float *array, long numSample, int percent){
	long index;
	int threshold;

  qsort(array, numSample, sizeof(float),_compare);
	index = (long)(numSample*percent/100) + 1;
	threshold = (int)(array[index]) + 1;

	return threshold;
}

⌨️ 快捷键说明

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