1
/*===========================================================================
2
Copyright (C) 1995-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
19
Correspondence concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/******************************************************************************
34
** Author: Jean-Luc Starck
43
*******************************************************************************
45
** DESCRIPTION creation of an image from a wavelet transform
51
** File_Name_Transform (keyword: IN_A):
52
** File name of the input wavelet transform
54
** File_Name_Imag (keyword: OUT_A):
55
** File name of the output image
57
** Increment (keyword: INPUTI(1)): (default is 1)
58
** we keep one line on Increment
60
** Visualisation Mode (keyword: IN_B): CO or BW (default is CO)
62
** BW = black and white
64
** Threshold value (keyword: INPUTR(1)): (default is 5)
65
** all the wavelet coefficients > Treshold*Sigma_Scale
66
** are set to Treshold*Sigma_Scale
68
** RESULTS : create an image from a wavelet file
69
** ------- the image is a representation of the
70
** wavelet coefficicients with a 3 dimension
72
******************************************************************************/
80
#include <midas_def.h>
84
#include "Def_Wavelet.h"
86
extern float lib_mat_ecart_type();
88
extern void wave_io_read(), wavelet_extract_plan(), io_write_pict_f_to_file();
100
/*****************************************************************************/
102
void ligne (x1,y1,x2,y2,Couleur,Nl,Nc,Tab_Caval)
104
Draw a line in the image Tab_Caval between the two points:
105
I1,J1 and I2,J2. The intensity of the line is defined by Couleur
108
int x1,y1,x2,y2,Nl,Nc;
112
int j,pasx,x,y,dx,dy,cumul;
115
if (x1 < x2) pasx = 1;
117
if (y1 < y2) pasy = 1;
123
Tab_Caval [x1*Nc+y1] = Couleur;
128
for (j = 0; j < dx; j++)
137
Tab_Caval [x*Nc+y] = Couleur;
144
for (j = 0; j < dy; j++)
153
Tab_Caval [x*Nc+y] = Couleur;
158
/*****************************************************************************/
160
void lib_caval_pict (Nl, Nc, Maxy, Maxx, Tab_Img, Tab_Caval, Inc, Mod_Visu)
161
int Nl,Nc,Maxy,Maxx,Inc;
162
float *Tab_Img,*Tab_Caval;
165
int j,Size,Indi,Indj;
166
float i,Seuil,X_Pas,Increment,Nb_Line;
171
float Val,H_Facteur,L_Facteur,u,Interp;
175
Tab_Max = f_vector_alloc (Maxx);
176
for (j = 0; j < Maxx; j++) Tab_Max [j] = 0.;
177
for (j = 0; j < Size; j++) Tab_Caval [j] = 0.;
179
Increment = (float) Inc;
183
Min = Max = Tab_Img[0];
184
for (j = 0; j < Nl*Nc; j++)
186
if (Min > Tab_Img[j]) Min = Tab_Img[j];
187
if (Max < Tab_Img[j]) Max = Tab_Img[j];
189
for (j = 0; j < Nl*Nc; j++) Tab_Img[j] = (Tab_Img[j]-Min) / (Max - Min);
192
/* Color threshold */
195
/* scale parameter realted to the visualisation angle*/
196
H_Facteur = (float) Maxy / 2.;
197
L_Facteur = (float) Maxx / (float) Nc;
198
X_Pas = 1. / L_Facteur;
199
Nb_Line = (float) Nl / ((float) Maxy / 2.);
200
Borne = (Maxy /2. > Nl)? Nl : Maxy / 2.;
202
for (i = 0; i < Borne; i += Increment)
204
/* First point position */
210
printf ("(%f,%d)",Nb_Line,Indi);
212
Val = H_Facteur * Tab_Img [Indi] + i;
213
if (Val > Tab_Max [0]) Tab_Max [0] = Val;
218
for (j = 1; j < Maxx; j ++)
220
/* ordinate position */
222
u = ((float) Nc / (float) Maxx) * (float) j;
225
if ((L_Facteur > 1.) && ((Indj + 1) < Nc))
228
Val = Tab_Img [Indi+Indj];
229
Val = H_Facteur * (Val + (Tab_Img [Indi+Indj+1]
230
- Val) * Interp) + i;
231
if ((Val >= Maxy) || (Val < 0.))
233
printf ("zoom val (%d,%d)=%f ",Indi,Indj,Val);
239
Val = H_Facteur * Tab_Img [Indi+Indj] + i;
240
if ((Val >= Maxy) || (Val < 0.))
242
printf ("calcul val %5.1f:(%d,%d)=%f ",i,Indi,Indj,Val);
247
/* Tab_Max = Z-array: contains the max for each columns */
248
if (Val > Tab_Max [j])
252
/* Y2 = Maxy - 1 - (Tab_Max [j] + 0.5);*/
256
printf ("Y2 < 0 : %d",Y2);
260
if (Tab_Img [Indi+Indj] < Seuil) Couleur = COULEUR_1;
261
else Couleur = COULEUR_2;
263
if ((Couleur == COULEUR_1)
264
&& ((Tab_Caval [Y1*Maxx+X1] == COULEUR_2)
265
|| (Tab_Caval [Y2*Maxx+X2] == COULEUR_2)))
272
Level = Tab_Img [Indi+Indj];
275
printf ("Y1(%d,%5.1f)",j,Tab_Max [j]);
279
if (Mod_Visu == BLACK_WHITE)
283
ligne (Y1,X1,Y2,X2,Level,Maxy,Maxx,Tab_Caval);
291
/* Y1 = Maxy - Tab_Max [j];*/
295
printf ("Y1(%d,%f)",j,Tab_Max [j]);
303
free ((char *)Tab_Max);
306
/*****************************************************************************/
308
static void copy_plan_to_pict(Tab_Caval, Nl1, Nc1, Pict_Caval, Maxy, Maxx, Num_Etap)
309
float *Tab_Caval,*Pict_Caval;
310
int Nl1, Nc1, Maxy, Maxx;
317
Offsx = (Maxx - Nc1) / 2;
318
Offsy = Nl1 * Num_Etap * Maxx;
320
for (i = 0; i < Nl1; i++)
322
for (j = 0; j < Nc1; j++)
324
ind = Offsy + Offsx + i * Maxx + j;
325
Pict_Caval [ind] = Tab_Caval [i * Nc1 + j] * MAXI;
330
/**************************************************************/
336
wave_transf_des Wavelet;
337
float *ImaSynt, *Imag, Sigma;
338
string File_Name_Imag, File_Name_Transform;
339
int Actvals, Maxvals, Felem, Unit, Null;
340
int Stat, Buffer_Int;
344
float Zoom, *Pict_Caval, K_Sigma;
351
/* read the wavelet transform file name */
354
Stat = SCKGETC("IN_A", Felem, Maxvals, &Actvals, File_Name_Transform);
356
/* read the image output file name */
357
Stat = SCKGETC("OUT_A", Felem, Maxvals, &Actvals, File_Name_Imag);
359
/* read the increment */
361
Stat = SCKRDI("INPUTI",Felem, Maxvals, &Actvals, &Buffer_Int, &Unit, &Null);
364
/* read the visualisation mode (Black and White (BW) or Color (CO))*/
366
Stat = SCKGETC("IN_B", Felem, Maxvals, &Actvals, Buffer_Visu);
367
if ( ((Buffer_Visu[0] == 'B') || (Buffer_Visu[0] == 'b'))
368
&& ((Buffer_Visu[1] == 'W') || (Buffer_Visu[1] == 'w'))) Mod_Visu = 0;
370
/* read the threshold value */
372
Stat = SCKRDR("INPUTR", Felem, Maxvals, &Actvals, &K_Sigma, &Unit, &Null);
374
/* read the wavelet */
375
wave_io_read (File_Name_Transform, &Wavelet);
377
Nl = Wavelet.Nbr_Ligne;
378
Nc = Wavelet.Nbr_Col;
379
Zoom = (float) MAXX / (float) Nc;
380
Size_Plan = (float) MAXY / (float) Wavelet.Nbr_Plan;
382
Pict_Caval = f_vector_alloc (Size);
383
ImaSynt = f_vector_alloc (Size);
385
for (i = 0; i < Size; i++) ImaSynt[i] = 0.;
387
for (i = 0; i <Wavelet.Nbr_Plan ; i++)
389
wavelet_extract_plan (&Wavelet, &Imag, &Nl, &Nc, i+1);
390
Sigma = K_Sigma * lib_mat_ecart_type(Imag,Nl,Nc);
393
Nc1 = (((float) Nc * Zoom) > MAXX) ? MAXX : ((float)Nc * Zoom);
394
if (i != Wavelet.Nbr_Plan-1)
395
for (j = 0; j < Nl*Nc; j++)
397
if (Imag [j] > Sigma) Imag [j] = Sigma;
398
if (Imag [j] < - Sigma) Imag [j] = - Sigma;
400
lib_caval_pict (Nl, Nc, Nl1, Nc1, Imag, Pict_Caval, Inc, Mod_Visu);
401
copy_plan_to_pict(Pict_Caval,Nl1,Nc1,ImaSynt,MAXY,MAXX, i);
402
free ((char *) Imag);
405
io_write_pict_f_to_file (File_Name_Imag, ImaSynt, MAXY, MAXX);