 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
21 tile_size = tile_size.
max(min_size);
22 tile_size = tile_size.
min(img_size);
23 tile_size = tile_size.
min(max_size);
25 if ( tile_size[0] != tile_size[1] ) {
26 if ( tile_size[0] > tile_size[1] ) tile_size[0] = tile_size[1];
27 else tile_size[1] = tile_size[0];
28 if ( img_size[2] > 1 ) tile_size[2] = tile_size[0];
51 cout <<
"DEBUG Bimage::power_spectrum: flags=" << flags << endl;
52 cout <<
"DEBUG Bimage::power_spectrum: tiles=" << n << endl;
61 return error_show(
"Bimage::power_spectrum", __FILE__, __LINE__);
106 if ( x != y && x > max_size && y > max_size) {
108 if (
pad < y/10 )
pad = y/10;
115 ext_size[0] = tile_size[0]*((x - 2*
pad)/tile_size[0]);
116 ext_size[1] = tile_size[1]*((y - 2*
pad)/tile_size[1]);
117 ext_size[2] = tile_size[2]*((z - 2*
pad)/tile_size[2]);
118 ext_size = ext_size.
max(1);
120 start[0] = (x - ext_size[0])/2;
121 start[1] = (y - ext_size[1])/2;
122 start[2] = (z - ext_size[2])/2;
125 cout <<
"DEBUG Bimage::powerspectrum_tiled: img_num=" << img_num << endl;
126 cout <<
"DEBUG Bimage::powerspectrum_tiled: start=" << start << endl;
127 cout <<
"DEBUG Bimage::powerspectrum_tiled: tile_size=" << tile_size << endl;
155 double tilt_axis,
double tilt_offset,
int flags)
157 long i, xx, yy, ntiles(0);
158 double tan_a(tan(tilt_axis));
159 double inv_tan_a(1.0/tan_a);
160 double ratang(atan2(y, x));
162 vector<Vector3<long>> tile;
166 if ( fabs(tilt_axis) < ratang || fabs(tilt_axis) >
M_PI - ratang ) {
167 origin[1] += (long)tilt_offset;
168 ntiles = x/tile_size[0];
170 for ( i=0, xx =
origin[0] - (ntiles * tile_size[0])/2; i<ntiles; i++, xx += tile_size[0] ) {
172 tile[i][1] = (long) (
origin[1] + (xx -
origin[0])*tan_a);
175 origin[0] += (long)tilt_offset;
176 ntiles = y/tile_size[1];
178 for ( i=0, yy =
origin[1] - (ntiles * tile_size[1])/2; i<ntiles; i++, yy += tile_size[1] ) {
179 tile[i][0] = (long) (
origin[0] + (yy -
origin[1])*inv_tan_a);
185 cout <<
"DEBUG Bimage::powerspectrum_tilted: img_num=" << img_num << endl;
186 cout <<
"DEBUG Bimage::powerspectrum_tilted: origin=" <<
origin << endl;
187 cout <<
"DEBUG Bimage::powerspectrum_tilted: tile_size=" << tile_size << endl;
188 cout <<
"DEBUG Bimage::powerspectrum_tilted: ntiles=" << ntiles << endl;
199 nusize[0] = pex->
sizeX();
200 if ( pex->
sizeY() > 1 && nusize[0] > pex->
sizeY() ) nusize[0] = pex->
sizeY();
201 if ( pex->
sizeZ() > 1 && nusize[0] > pex->
sizeZ() ) nusize[0] = pex->
sizeZ();
202 if ( pex->
sizeY() > 1 ) nusize[1] = nusize[0];
203 if ( pex->
sizeZ() > 1 ) nusize[2] = nusize[0];
223 vector<double> vs(x,0);
225 for (
size_t i=0; i<vs.size(); ++i ) {
228 s1 = f1 - sqrt(f1*f1 + s2*s2 - f2*s2);
229 vs[i] = sqrt(s1)/interval;
234 for ( i=0, yy=0; yy<y; ++yy ) {
235 dis[1] = double(yy) - ori[1];
236 for ( xx=0; xx<x; ++xx, ++i ) {
237 dis[0] = double(xx) - ori[0];
244 coor += dis * (f1*vs[j] + f2*vs[j+1])/len;
273 double tilt_axis,
double tilt_angle,
double defocus,
double iCL2,
int flags)
282 Vector3<long> edge_rect(tile_size/1.5), edge_start((tile_size-edge_rect)/2);
283 edge_rect = edge_rect.max(1);
288 vector<Vector3<long>> coor =
tile_coordinates(start, region, tile_size, step_size, 0);
297 double ddef, ca(cos(tilt_axis)), sa(sin(tilt_axis)), tt(tan(tilt_angle));
303 cout <<
"DEBUG Bimage::powerspectrum_tilted: origin=" <<
image->
origin() << endl;
304 cout <<
"DEBUG Bimage::powerspectrum_tilted: ca=" << ca <<
" sa=" << sa <<
" tt=" << tt << endl;
312 for ( nn=0; nn<pex->
images(); nn++ ) {
315 ddef = (vec[1]*ca - vec[0]*sa)*tt;
318 scale[0] = scale[1] = sqrt(1 + ddef/defocus);
357 double tilt_axis,
double tilt_angle,
double tilt_offset,
358 double defocus,
double iCL2,
int flags)
362 if ( flags & 16 ) nimg = 1;
369 for ( nn = 0; nn<n; nn++ ) {
370 if ( fabs(tilt_angle) > 1e-6 ) {
385 if ( flags & 16 ) ps->
multiply(1.0/nn);
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
void set(long j, double v)
Sets a single value at the given index.
Bimage()
Initializes an image.
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
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
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 origin(double x, double y, double z)
void multiply(long j, Complex< double > cv)
void add(long j, double v)
FourierType fourier_type()
int power_spectrum(int flags=0)
Calculates a power spectrum.
General image parameter class.
Bimage * extract_tiles(long nn, vector< Vector3< long >> &coords, Vector3< long > tile_size)
Extracts a set of tiles at specified positions from an image into a new image.
void power(double v)
Calculates the power of an image.
void color_to_simple()
A color image is converted to a simple image.
int replace(Bimage *img)
Replaces the data with that from the given image.
Bimage * powerspectrum_tilted(long img_num, Vector3< long > tile_size, double tilt_axis, double tilt_angle, double defocus, double iCL2, int flags=0)
Prepares a tiled powerspectrum from a tilted image for determining CTF parameters.
int set_tile_size(Vector3< long > &tile_size, Vector3< long > img_size)
Complex< double > complex(long j)
Returns a complex value at the given index.
Header file for image class.
int center_wrap()
Centers an image with wrapping.
Bimage * powerspectrum_tilt_axis(long img_num, Vector3< long > tile_size, double tilt_axis, double tilt_offset, int flags=0)
Prepares a tiled powerspectrum from a tilted image for determining CTF parameters.
Header file for general utilities.
double interpolate(long cc, double xx, double yy=0, double zz=0, long nn=0, double fill=0) const
Interpolates using a given location.
vector< Vector3< long > > tile_coordinates(Vector3< long > &start, Vector3< long > ®ion, Vector3< long > &tile_size, Vector3< long > &step_size, int exceed)
Generates a set of tile coordinates for an image.
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)
Bimage * powerspectrum_tiled_and_tilted(Vector3< long > tile_size, double tilt_axis, double tilt_angle, double tilt_offset, double defocus, double iCL2, int flags=0)
Prepares a tiled powerspectrum from a tilted image for determining CTF parameters.
vector< Vector3< double > > sampling()
int pad(long sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
void sampling(long nn, Vector3< double > u)
Bimage * powerspectrum_tiled(long img_num, Vector3< long > tile_size, int flags=0)
Prepares a tiled power spectrum from an image for determining CTF parameters.
Bimage * defocus_scale(long nn, double df, double df2, double iCL2, int fill_type)
int edge(int type, Vector3< long > rect, Vector3< double > start, double width, int fill_type=0, double fill=0)
Smooths the image edge with a soft rectangular function.
void logarithm()
Calculates the logarithm of the image data.
long statistics()
Calculates the statistics for an image.
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.