Bsoft  1.9
Bernard's software package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
img_diffraction.cpp
Go to the documentation of this file.
1 
9 #include "Bimage.h"
10 #include "utilities.h"
11 #include "Matrix.h"
12 
13 // Declaration of global variables
14 extern int verbose; // Level of output to the screen
15 
31 {
32  unsigned long n(0), i;
33  double d(1e30), cc;
34  Bimage* pc, *pr;
35 
36  Vector3<float> shift, oldshift;
37  Vector3<float> start;
38  Vector3<int> size((int)(p->sizeX()*4.0/5), (int)(p->sizeY()*4.0/5), (int)(p->sizeZ()*4.0/5));
39  size = size.max(1);
40  Vector3<double> origin(p->image->origin());
41 
42  if ( origin.x() <= 0 || origin.x() >= p->sizeX() ) origin[0] = p->sizeX()/2;
43  if ( origin.y() <= 0 || origin.y() >= p->sizeY() ) origin[1] = p->sizeY()/2;
44  if ( origin.z() <= 0 || origin.z() >= p->sizeZ() ) origin[2] = p->sizeZ()/2;
45 
46  if ( verbose )
47  cout << "Finding the diffraction origin(s)" << endl;
48 
49  for ( i=0; i<10 && d > 1; i++ ) {
50  start = origin - size/2;
51  pc = p->copy();
52  pc->change_type(Float);
53  pc->origin(origin);
54  pc->edge(1, size, start, 10, FILL_USER, p->average());
55  pc->rescale_to_avg_std(0, 1);
56  if ( pmask ) pc->mask(pmask, 0);
57  pr = pc->rotate(pc->size(), M_PI);
58  shift = pc->find_shift(pr, NULL, p->sampling().x()*10, p->sampling().x()*1000, p->sizeX()/4.0, 0, 1, cc);
59  delete pc;
60  delete pr;
61  p->image[n].origin((p->size() + shift)/2);
62  if ( verbose & VERB_DEBUG )
63  cout << "DEBUG img_diffraction_origin: " << n << ": " << shift << tab << cc << endl;
64  d = (shift - oldshift).length();
65  oldshift = shift;
66  }
67 
68  if ( verbose ) {
69  cout << "Diffraction origins:\nImage\tox\toy\toz" << endl;
70  for ( n=0; n<p->images(); n++ )
71  cout << n+1 << tab << p->image[n].origin().x() << tab << p->image[n].origin().y() << tab << p->image[n].origin().z() << endl;
72  cout << endl;
73  }
74 
75  return 0;
76 }
77 
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1544
int edge(int type, Vector3< size_t > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
void sizeZ(size_t nz)
Definition: Bimage.h:332
Header file for image class.
Header file for general utilities.
#define VERB_DEBUG
Definition: utilities.h:105
int mask(Bimage *pmask, double fill)
Masks an image.
Definition: Bimage_mask.cpp:26
Generalized matrix class.
int img_diffraction_origin(Bimage *p, Bimage *pmask)
Finds the origin of a powder diffraction pattern by cross-correlation.
Type max()
Definition: Vector3.h:149
double average(size_t cc, double xf, double yf, double zf, size_t nn, double iscale)
Averages in the xy plane when scaling is less than 1.
Definition: Bimage.cpp:1209
Vector3< size_t > size() const
Definition: Bimage.h:327
General image parameter class.
Definition: Bimage.h:152
#define M_PI
Definition: utilities.h:52
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
void sampling(double s)
Definition: Bimage.h:440
#define FILL_USER
Definition: utilities.h:165
void origin(double x, double y, double z)
Definition: Bimage.h:132
int verbose
size_t images()
Definition: Bimage.h:438
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2414
void sizeX(size_t nx)
Definition: Bimage.h:330
void sizeY(size_t ny)
Definition: Bimage.h:331
int rotate()
Rotates an image using parameters defined in the image in place.
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bsub_image * image
Definition: Bimage.h:183
void origin(double ox, double oy, double oz)
Definition: Bimage.h:483