📄 lcollage_search.c
字号:
/*----------------------------------------------------------------------------
// StirMark Benchmark - lcollage_search.c
//
// Contents: "Collage" within image
//
// Purpose:
//
// Created: C. Rey, G. Do雛r, J.-L. Dugelay and G. Csurka, Eur閏om, January 2002
//
// Modified:
//
// History:
//
// Copyright (c) 2000-2002, Microsoft Research Ltd , Institut National
// de Recherche en Informatique et Automatique (INRIA), Institut Eur閏om
// and the Integrated Publication and Information Systems Institute at
// GMD - Forschungszentrum Informationstechnik GmbH (GMD-IPSI).
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted for non-commercial research and academic
// use only, provided that the following conditions are met:
//
// - Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer. Each
// individual file must retain its own copyright notice.
//
// - Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions, the following disclaimer and the
// list of contributors in the documentation and/or other materials
// provided with the distribution.
//
// - Modification of the program or portion of it is allowed provided
// that the modified files carry prominent notices stating where and
// when they have been changed. If you do modify this program you
// should send to the contributors a general description of the changes
// and send them a copy of your changes at their request. By sending
// any changes to this program to the contributors, you are granting a
// license on such changes under the same terms and conditions as
// provided in this license agreement. However, the contributors are
// under no obligation to accept your changes.
//
// - All non-commercial advertising materials mentioning features or use
// of this software must display the following acknowledgement:
//
// This product includes software developed by Microsoft Research
// Ltd, Institut National de Recherche en Informatique et Automatique
// (INRIA), Institut Eur閏om and the Integrated Publication and
// Information Systems Institute at GMD - Forschungszentrum
// Informationstechnik GmbH (GMD-IPSI).
//
// - Neither name of Microsoft Research Ltd, INRIA, Eur閏om and GMD-IPSI
// nor the names of their contributors may be used to endorse or
// promote products derived from this software without specific prior
// written permission.
//
// - If you use StirMark Benchmark for your research, please cite:
//
// Fabien A. P. Petitcolas, Martin Steinebach, Fr閐閞ic Raynal, Jana
// Dittmann, Caroline Fontaine, Nazim Fat鑣. A public automated
// web-based evaluation service for watermarking schemes: StirMark
// Benchmark. In Ping Wah Wong and Edward J. Delp, editors,
// proceedings of electronic imaging, security and watermarking of
// multimedia contents III, vol. 4314, San Jose, California, U.S.A.,
// 20-26 January 2001. The Society for imaging science and
// technology (I.S.&T.) and the international Society for optical
// engineering (SPIE). ISSN 0277-786X.
//
// and
//
// Fabien A. P. Petitcolas. Watermarking schemes
// evaluation. I.E.E.E. Signal Processing, vol. 17, no. 5,
// pp. 58-64, September 2000.
//
// THIS SOFTWARE IS NOT INTENDED FOR ANY COMMERCIAL APPLICATION AND IS
// PROVIDED BY MICROSOFT RESEARCH LTD, INRIA, EUR蒀OM, GMD-IPSI AND
// CONTRIBUTORS 'AS IS', WITH ALL FAULTS AND ANY EXPRESS OR IMPLIED
// REPRESENTATIONS OR WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED REPRESENTATIONS OR WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE, TITLE OR NONINFRINGEMENT OF INTELLECTUAL
// PROPERTY ARE DISCLAIMED. IN NO EVENT SHALL MICROSOFT RESEARCH LTD,
// INRIA, EUR蒀OM, GMD-IPSI OR THEIR CONTRIBUTORS BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// THE USE OF THIS SOFTWARE FOR CIRCUMVENTING WITHOUT AUTHORITY ANY
// EFFECTIVE TECHNOLOGICAL MEASURES DESIGNED TO PROTECT ANY COPYRIGHTS OR
// ANY RIGHTS RELATED TO COPYRIGHT AS PROVIDED BY LAW OR THE SUI GENERIS
// RIGHT PROVIDED BY SOME COUNTRIES IS STRICTLY PROHIBITED.
//
// $Header: /home/cvs/StirmarkBench/StirMark_Bench/SignalProcessing/SelfSimilarities/lcollage_search.c,v 1.3 2002/04/19 10:23:58 petitcolas Exp $
//----------------------------------------------------------------------------
*/
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "SelfSimilarities.h"
#include "lib_kadv_codec.h"
char s_o_ss_compute(block *red_d_block,block *r_block,int dim_r,
double som_d, double som_r,
double var_d, double var_r,
float *s, float *o, float *error){
double sigmaW = 0.0;
double accu;
double pdr = 0.0;
int i;
/* Sum of the wights of the mask */
for (i=0;i<DIM_MASK;i++)
sigmaW += MASQUE[i];
/* Determinant of the linear system */
accu= sigmaW * var_d - som_d * som_d;
/* If almost null: non stable system */
if( fabs(accu) < 0.01 ){
*s = 0.0;
*o =(float) som_r / (float) sigmaW;
/* Direct computation of the error */
*error = ((float)var_r
+ (*o) * ( (*o)*(float)sigmaW - 2*(float)som_r ))
/ (float)sigmaW;
}
else {
/* Sigma of (XiYi) */
for (i=0;i<DIM_MASK;i++)
pdr += MASQUE[i] * red_d_block[i] * r_block[i];
/* Computation of the parameters of the photometric transformation */
*s = ((float)(sigmaW*pdr) - (float)(som_d*som_r)) / (float) accu;
*o = ((float)som_r - (*s)*(float)som_d) / (float) sigmaW;
/* Direct computation of the error */
*error = ((float)var_r
+ (*s) * ( (*s)*(float)var_d - 2*(float)pdr + 2*(*o)*(float)som_d )
+ (*o) * ( (*o)*(float)sigmaW - 2*(float)som_r ))
/ (float)sigmaW;
}
return 1;
}
float super_collage_spa(block *r, int dim_r, int xr, int yr, float move_rate_x,
float move_rate_y, image *r_image, int w_orig, int h_orig,
block* d_reduce, int seuil){
int xw = 0, yw = 0; /* Coordinates of the top left corner of the sear window */
int i, j; /* Indices */
/* Least square computation variables */
double tmp;
double som_r, var_r;
double som_dc, var_dc;
int move_x, move_y;
/*
*const int dim_r2 = dim_r*dim_r; // Area of a Range Block
*const int dim_r_2 = (int)dim_r/2;
*/
block *d; /* Domain Block */
block **d_dictionnary;
image *search_win;
int xd, yd, m;
float s,o;
float err_codage;
int min_xd = 0, min_yd = 0, min_m = 0;
float min_s = 0.0, min_o = 0.0;
float min_err = -1;
int max_xd = 0, max_yd = 0, max_m = 0;
float max_s = 0.0, max_o = 0.0;
float max_err = -1;
int best_xd, best_yd, best_m;
float best_s, best_o;
float best_err;
d = BlockAlloc(IFS_DIM_D_H,IFS_DIM_D_V);
search_win = BlockAlloc(IFS_WIN_D,IFS_WIN_D);
/* Initialisation of the dictionnary which will contain
the various geometric transformations
*/
d_dictionnary=(block **)malloc (NB_GEOM_TRANS * sizeof(block *));
for(m=0; m < NB_GEOM_TRANS ; m++)
d_dictionnary[m]=(block *)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
*/
som_r = 0.0;
var_r = 0.0;
for (i=0;i<DIM_MASK;i++){
tmp = r[i]*MASQUE[i];
som_r += tmp;
var_r += tmp*r[i];
}
/* Compute the coordonate of the search window */
/* Select search window randomly */
/* xw=rand()%(w_orig-IFS_WIN_D-1); */
/* yw=rand()%(h_orig-IFS_WIN_D-1); */
move_x = (int) (move_rate_x*(float)dim_r);
move_y = (int) (move_rate_y*(float)dim_r);
if (xr <= w_orig/2 && yr <= h_orig/2) {
xw = xr+dim_r - move_x;
yw = yr+dim_r - move_y;
}
else if (xr >= w_orig/2 && yr <= h_orig/2) {
xw = xr - IFS_WIN_D + move_x;
yw = yr + dim_r - move_y;
}
else if (xr <= w_orig/2 && yr >= h_orig/2) {
xw = xr + dim_r - move_x;
yw = yr - IFS_WIN_D + move_y;
}
else if (xr >= w_orig/2 && yr >= h_orig/2){
xw = xr - IFS_WIN_D + move_x;
yw = yr - IFS_WIN_D + move_y;
}
/* Load the search window */
BlockGet(r_image, w_orig, IFS_WIN_D,IFS_WIN_D, xw + w_orig* yw, search_win);
/* Choose best solution in the search window */
for( yd = 0; yd <= IFS_WIN_D-IFS_DIM_D_V; yd += IFS_STEP_D ) {
for( xd = 0; xd <= IFS_WIN_D-IFS_DIM_D_H; xd += IFS_STEP_D ) {
/* Domain block extraction */
BlockGet(search_win, IFS_WIN_D, IFS_DIM_D_H, IFS_DIM_D_V, xd+IFS_WIN_D*yd,d_reduce);
/* Sub Sampling */
/* BlockSubSampling(d,IFS_DIM_D_H,IFS_DIM_D_V, dim_r,d_reduce); */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -