| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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
30 int img_diffraction_origin(Bimage* p, Bimage* pmask)
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
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1544
Bimage::edge
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.
Definition: Bimage_edit.cpp:227
Bimage::sizeZ
void sizeZ(size_t nz)
Definition: Bimage.h:332
Bimage.h
Header file for image class.
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:105
Bimage::mask
int mask(Bimage *pmask, double fill)
Masks an image.
Definition: Bimage_mask.cpp:26
Vector3< float >
Matrix.h
Generalized matrix class.
img_diffraction_origin
int img_diffraction_origin(Bimage *p, Bimage *pmask)
Finds the origin of a powder diffraction pattern by cross-correlation.
Definition: img_diffraction.cpp:30
Vector3::max
Type max()
Definition: Vector3.h:149
Bimage::average
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
Bimage::size
Vector3< size_t > size() const
Definition: Bimage.h:327
Float
Definition: utilities.h:150
Bimage
General image parameter class.
Definition: Bimage.h:152
M_PI
#define M_PI
Definition: utilities.h:52
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:100
Bimage::sampling
void sampling(double s)
Definition: Bimage.h:440
FILL_USER
#define FILL_USER
Definition: utilities.h:165
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:132
verbose
int verbose
Bimage::images
size_t images()
Definition: Bimage.h:438
Bimage::copy
Bimage * copy()
Copies the header information and data of an image into a new image structure.
Definition: Bimage.cpp:2414
Bimage::sizeX
void sizeX(size_t nx)
Definition: Bimage.h:330
Bimage::sizeY
void sizeY(size_t ny)
Definition: Bimage.h:331
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:220
Bimage::find_shift
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.
Definition: Bimage_correlate.cpp:672
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bimage::image
Bsub_image * image
Definition: Bimage.h:183
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:483