 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
39 Matrix3 mat,
int fill_type,
double fill)
44 for ( nn=0; nn<n; nn++ ) {
77 Matrix3 mat,
int fill_type,
double fill)
87 pt =
new Bimage(datatype, compoundtype, nusize, n);
88 for ( nn=0; nn<n; nn++ ) {
96 for ( nn=0; nn<n; nn++ )
111 for (
long cc=0; cc<c; cc++, i++ )
140 Matrix3 mat,
int fill_type,
double fill)
142 if ( !d.
uc )
return NULL;
144 if ( compoundtype >
TSimple ) {
145 error_show(
"Bimage::transform", __FILE__, __LINE__);
146 cerr <<
"Error: Interpolation not done on compound data types" << endl;
150 if ( fabs(scale[0]) < 0.001 || x < 2 ) scale[0] = 1;
151 if ( fabs(scale[1]) < 0.001 || y < 2 ) scale[1] = 1;
152 if ( fabs(scale[2]) < 0.001 || z < 2 ) scale[2] = 1;
154 if ( nusize[0] < 1 ) nusize[0] = (long) (fabs(scale[0])*x);
155 if ( nusize[1] < 1 ) nusize[1] = (long) (fabs(scale[1])*y);
156 if ( nusize[2] < 1 ) nusize[2] = (long) (fabs(scale[2])*z);
157 nusize = nusize.
max(1);
159 long i, cc, xx, yy, zz;
169 nuorigin =
origin + translate;
172 cout << endl <<
"Geometric transformation:" << endl;
173 cout <<
"Transformation origin: " << oldorigin << endl;
174 cout <<
"New origin: " << nuorigin << endl;
175 cout <<
"Scales: " << scale << endl;
176 cout <<
"New size: " << nusize <<
" voxels" << endl;
177 cout <<
" " << nurealsize <<
" A" << endl;
178 cout <<
"Matrix:" << endl << mat;
179 cout <<
"Fill value: " <<
fill << endl << endl;
187 Bimage* pt =
new Bimage(datatype, compoundtype, nusize, 1);
194 for ( i=zz=0; zz<pt->z; zz++ ) {
195 nu[2] = (double)zz - nuorigin[2];
196 for ( yy=0; yy<pt->y; yy++ ) {
197 nu[1] = (double)yy - nuorigin[1];
198 for ( xx=0; xx<pt->x; xx++ ) {
199 nu[0] = (double)xx - nuorigin[0];
200 old = affmat * nu + oldorigin;
203 for ( cc=0; cc<c; cc++, i++ )
221 cout <<
"DEBUG Bimage::transform: view=" <<
image[nn].
view() << endl;
225 viewmat =
view.matrix();
233 cout <<
"DEBUG Bimage::transform: view=" <<
view << endl;
236 uc.
size(nurealsize[0], nurealsize[1], nurealsize[2]);
242 cout <<
"DEBUG Bimage::transform: interpolation done" << endl;
534 for ( v = views; v; v = v->
next ) nviews++;
536 if ( nviews < 1 )
return NULL;
545 for ( v = views; v; v = v->
next, ++nn ) {
566 Matrix3 mat(-1,0,0,0,-1,0,0,0,-1);
573 for ( nn=0; nn<n; nn++ ) {
591 for (
long nn=0; nn<n; nn++ )
607 if ( vec.
length() == 0 )
return 0;
610 cout <<
"Translate by: " << vec << endl;
612 long i, j, xx, yy, zz, cc;
614 vector<float> temp(imgsize);
619 for ( j=zz=0; zz<z; zz++ ) {
620 for ( yy=0; yy<y; yy++ ) {
621 for ( xx=0; xx<x; xx++ ) {
622 for ( cc=0; cc<c; cc++, j++ ) {
629 for ( i=nn*imgsize, j=0; j<imgsize; i++, j++ )
set(i, temp[j]);
643 for (
long nn=0; nn<n; nn++ )
657 if ( vec.
length() == 0 )
return 0;
660 cout <<
"Translate by: " << vec << endl;
662 long i, j, xx, yy, zz, cc;
665 vector<float> temp(imgsize);
668 for ( j=zz=0; zz<z; zz++ ) {
669 loc[2] = -vec[2] + zz;
670 for ( yy=0; yy<y; yy++ ) {
671 loc[1] = -vec[1] + yy;
672 for ( xx=0; xx<x; xx++ ) {
673 loc[0] = -vec[0] + xx;
674 for ( cc=0; cc<c; cc++, j++ )
681 for ( i=nn*imgsize, j=0; j<imgsize; i++, j++ )
set(i, temp[j]);
698 for (
long nn=0; nn<n; nn++ )
712 for (
long nn=0; nn<n; nn++ )
724 for (
long nn=0; nn<n; nn++ )
737 if ( !pref )
return NULL;
760 double scalemax,
double step)
764 double scale, scalebest(1), cc, ccbest(0);
770 cout <<
"Finding the best scaling to the reference map:" << endl;
771 cout <<
"Scale range: " << scalemin <<
" - " << scalemax << endl;
772 cout <<
"Initial scale step size: " << step << endl << endl;
773 cout <<
"Scale\tSampling\tCC" << endl;
776 while ( step > 0.0001 ) {
777 for ( scale=scalemin; scale<=scalemax+0.001; scale+=step ) {
788 scalemin = scalebest - 0.75*step;
789 scalemax = scalebest + 0.75*step;
794 cout <<
"Best scale: " << scalebest <<
" ("
795 << ccbest <<
")" << endl;
796 cout <<
"Sampling correction: "
void coordinates(long i, long &nx, long &ny, long &nz)
Bimage * scale_to_same_size(Bimage *pref)
Scales and image to the given reference.
int mirror()
Inverts/mirrors each image through its origin.
int shift(Vector3< double > vec, int fill_type=0, double fill=0)
Shifts an image.
void set(long j, double v)
Sets a single value at the given index.
Matrix3 transpose() const
Bimage()
Initializes an image.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
int center(int fill_type=0, double fill=0)
Centers an image.
void unit_cell(UnitCell uc)
Bimage * scale_to_reference(Bimage *pref, Bimage *pmask, double scalemin, double scalemax, double step)
Scales and image to the given reference, searching for the correct scale.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
double background(long nn)
Vector3< long > size() const
void size(double a, double b, double c)
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
void view(double x, double y, double z, double a)
int shift_wrap(Vector3< double > vec)
Shifts an image.
int zero_origin()
Shifts the origins to zero with wrapping.
int rotate_and_add(Bimage *p, Vector3< double > origin, View view)
Rotates an image to a specified view and adds it to another image.
void origin(double x, double y, double z)
Bimage * orient(View *views)
Calculates multiple copies oriented according to views.
void add(long j, double v)
double correlate(Bimage *p)
Calculates correlation coefficient between two images.
int rotate()
Rotates an image using parameters defined in the image in place.
General image parameter class.
double interpolate_wrap(long cc, double xx, double yy=0, double zz=0, long nn=0) const
Interpolates using a given location with wrapping.
int replace(Bimage *img)
Replaces the data with that from the given image.
Header file for image class.
int center_wrap()
Centers an image with wrapping.
Header file for general utilities.
ostream & tab(ostream &out)
double interpolate(long cc, double xx, double yy=0, double zz=0, long nn=0, double fill=0) const
Interpolates using a given location.
void origin(double ox, double oy, double oz)
void change_type(char letter)
Get the data type indicated by a single letter code.
void sampling(double x, double y, double z)
Header file for general utilities.
vector< Vector3< double > > sampling()
void sampling(long nn, Vector3< double > u)
int fspace_resize(double scale, double res_hi, double res_lo)
Resizes an image in frequency space to avoid interpolation.
void view(double vx, double vy, double vz, double va)
void transform_voxel(long i, Bimage *pt, long nn, Vector3< double > oldorigin, Vector3< double > nuorigin, Matrix3 affmat, double fill)
long statistics()
Calculates the statistics for an image.