37 unsigned long i, datasize = p->
data_size();
44 cout <<
"Scale and shift: " << scale <<
" " << shift << endl << endl;
47 for ( i=0; i<p->
images(); i++ )
50 for ( i=0; i<datasize; i++ ) {
51 tdata = (*p)[i]*scale + shift;
52 if ( tdata < min ) tdata = min;
53 else if ( tdata > max ) tdata = max;
84 cerr <<
"Error in rescaling: minimum (" << min <<
") is greater than maximum ("
85 << max <<
") for " << p->
file_name() << endl;
90 double shift = min - p->
minimum()*scale;
93 cout <<
"Rescaling to: " << min <<
" " << max << endl;
118 cerr <<
"Warning: Cannot use a negative standard deviation to scale to! (" << std <<
")" << endl;
124 cerr <<
tab <<
"in img_rescale_to_avg_std" << endl;
139 double shift = avg - p->
average()*scale;
142 cout <<
"Rescaling to average and stdev: " << avg <<
" " << std << endl;
169 unsigned long i, datasize = p->
data_size();
175 if ( setmin < p->minimum() ) setmin = p->
minimum();
177 if ( min < tmin ) min = tmin;
178 if ( max > tmax ) max = tmax;
179 if ( setmin < tmin ) setmin = tmin;
180 if ( setmax > tmax ) setmax = tmax;
183 for ( i=0; i<p->
images(); i++ ) {
189 cout <<
"Truncating to: " << min <<
" " << max << endl;
190 cout <<
"Min and max replacement values: " << setmin <<
" " << setmax << endl << endl;
193 for ( i=0; i<datasize; i++ ) {
195 if ( tdata < min ) tdata = setmin;
196 if ( tdata > max ) tdata = setmax;
268 if ( min < tmin ) min = tmin;
269 if ( max > tmax ) max = tmax;
272 cout <<
"Truncating to background:" << endl;
273 cout <<
"Range: " << min <<
" " << max << endl;
274 cout <<
"Image\tBackground" << endl;
278 for ( n=0; n<p->
images(); n++ ) {
287 for ( n=0; n<p->
images(); n++ ) {
289 for ( i=n*imgsize, n1=n+imgsize; i<n1; i++ ) {
291 if ( tdata < min ) tdata = bkg;
292 if ( tdata > max ) tdata = bkg;
318 if ( nlevels > 255 ) {
319 cerr <<
"Error: There should be less than 255 gray levels (" << nlevels <<
")" << endl;
324 cout <<
"Limiting levels to: " << nlevels << endl << endl;
326 unsigned long i, datasize = p->
data_size();
327 double unit = 255.0/(nlevels - 1);
330 unsigned char* nudata =
new unsigned char[datasize];
333 cout <<
"Restricting to " << nlevels <<
" levels." << endl << endl;
335 for ( i=0; i<datasize; i++ )
336 nudata[i] = (
unsigned char) (unit*floor(((*p)[i] - p->
minimum())*scale));
void sizeX(unsigned long nx)
int img_rescale_to_min_max(Bimage *p, double min, double max)
Rescales the image data to a given minimum and maximum.
int img_truncate_to_avg(Bimage *p, double min, double max)
Sets voxels in image data exceeding a given minimum and maximum to the average.
Header file for general utilities.
int img_truncate_to_background(Bimage *p, double min, double max)
Sets voxels in image data exceeding a given minimum and maximum to the image background.
Header file for image utilities.
Class for complex numbers.
Generalized matrix class.
double average(unsigned long cc, double xf, double yf, double zf, unsigned long nn, double iscale)
Averages in the xy plane when scaling is less than 1.
size_t statistics()
Calculates the statistics for an image.
double data_type_max()
Get the maximum of a datatype.
General image parameter class.
void set(unsigned long j, double v)
Sets a single value at the given index.
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
int img_truncate(Bimage *p, double min, double max, double setmin, double setmax)
Truncates image data to a given minimum and maximum.
void file_name(Bstring s)
double standard_deviation()
unsigned char * data_pointer()
unsigned long data_size()
int img_rescale_to_avg_std(Bimage *p, double avg, double std)
Rescales the image data to a given average and standard deviation.
void sizeZ(unsigned long nz)
Header file for 2D and 3D image I/O.
int img_limit_levels(Bimage *p, int nlevels)
Converts a full gray scale image to a limited level image.
int img_truncate_to_min_max(Bimage *p, double min, double max)
Truncates image data to a given minimum and maximum.
int img_rescale(Bimage *p, double scale, double shift)
Rescales the image data to a given minimum and maximum.
void sizeY(unsigned long ny)
double data_type_min()
Get the minimum of a datatype.
ostream & tab(ostream &out)