 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
34 cout <<
"Scale and shift: " << scale <<
" " <<
shift << endl << endl;
41 for ( i=0; i<datasize; i++ ) {
42 v1 = (*this)[i]*scale +
shift;
47 cerr <<
tab <<
"in Bimage::rescale" << endl;
69 cout <<
"Scale and shift: " << scale <<
" " <<
shift << endl << endl;
75 for ( i=0, j=nn*imgsize; i<imgsize; i++, j++ ) {
76 v1 = (*this)[j] * scale +
shift;
102 if ( numin >= numax ) {
103 cerr <<
"Error in rescaling: minimum (" << numin <<
") is greater than maximum ("
104 << numax <<
") for " <<
file_name() << endl;
108 double scale = (numax - numin)/(max - min);
109 double shift = numin - min*scale;
112 cout <<
"Rescaling to: " << numin <<
" " << numax << endl;
134 if ( numin >= numax ) {
135 cerr <<
"Error in rescaling: minimum (" << numin <<
") is greater than maximum ("
136 << numax <<
") for " <<
file_name() << endl;
144 cout <<
"Rescaling to: " << numin <<
" " << numax << endl;
166 cerr <<
"Warning: Cannot use a negative standard deviation to scale to! (" << nustd <<
")" << endl;
171 cerr <<
tab <<
"in Bimage::rescale_to_avg_std" << endl;
175 double scale = (std>1e-30)? nustd/std: 1;
176 double shift = nuavg - avg*scale;
179 cout <<
"Rescaling to average and stdev: " << nuavg <<
" " << nustd << endl;
202 cerr <<
"Warning: Cannot use a negative standard deviation to scale to! (" << nustd <<
")" << endl;
207 cerr <<
tab <<
"in Bimage::rescale_to_avg_std" << endl;
215 cout <<
"Rescaling to average and stdev: " << nuavg <<
" " << nustd << endl;
238 cerr <<
"Warning: Cannot use a negative standard deviation to scale to! (" << nustd <<
")" << endl;
242 double regavg(0), regstd(0);
247 cerr <<
"Error in Bimage::rescale_to_avg_std: Region standard deviation is zero for "
252 double scale = nustd/regstd;
253 double shift = nuavg - regavg*scale;
256 cout <<
"Rescaling to average and stdev: " << nuavg <<
" " << nustd << endl;
285 if ( setmin < min ) setmin = min;
286 if ( setmax > max ) setmax = max;
287 if ( minim < dtmin ) minim = dtmin;
288 if ( maxim > dtmax ) maxim = dtmax;
289 if ( setmin < dtmin ) setmin = dtmin;
290 if ( setmax > dtmax ) setmax = dtmax;
293 for ( i=0; i<n; i++ ) {
301 cout <<
"Truncating to: " << minim <<
" " << maxim << endl;
302 cout <<
"Min and max replacement values: " << setmin <<
" " << setmax << endl << endl;
305 for ( i=0; i<datasize; i++ ) {
307 if ( v1 < minim ) v1 = setmin;
308 if ( v1 > maxim ) v1 = setmax;
333 return truncate(minim, maxim, minim, maxim);
351 return truncate(minim, maxim, avg, avg);
371 long i, nn, n1, imgsize = x*y*z*n;
375 if ( minim < dtmin ) minim = dtmin;
376 if ( maxim > dtmax ) maxim = dtmax;
379 cout <<
"Truncating to background:" << endl;
380 cout <<
"Range: " << minim <<
" " << maxim << endl;
381 cout <<
"Image\tBackground" << endl;
385 for ( nn=0; nn<n; nn++ ) {
399 for ( nn=0; nn<n; nn++ ) {
402 for ( i=nn*imgsize, n1=nn+imgsize; i<n1; i++ ) {
404 if ( v1 < minim ) v1 = bkg;
405 if ( v1 > maxim ) v1 = bkg;
430 if ( nlevels > 255 ) {
431 cerr <<
"Error: There should be less than 255 gray levels (" << nlevels <<
")" << endl;
436 cout <<
"Limiting levels to: " << nlevels << endl << endl;
439 double unit = 255.0/(nlevels - 1);
440 double scale = 0.999*nlevels/(max - min);
442 unsigned char* nudata =
new unsigned char[datasize];
445 cout <<
"Restricting to " << nlevels <<
" levels." << endl << endl;
447 for ( i=0; i<datasize; i++ )
448 nudata[i] = (
unsigned char) (unit*floor(((*
this)[i] - min)*scale));
491 switch ( norm_type ) {
538 int bins = (int) max;
539 if ( bins < 256 ) bins = 256;
540 if ( bins > 1024 ) bins = 1024;
543 switch ( datatype ) {
552 default:
average = 0; stdev = 1;
break;
559 cout <<
"Mass normalizing ";
562 cout <<
"Normalizing type: ";
563 switch ( norm_type ) {
564 case 1: cout <<
"Gaussian";
break;
565 case 2: cout <<
"Poisson";
break;
566 default: cout <<
"Simple";
568 cout << endl <<
"Average and standard deviation: " <<
average <<
" " << stdev << endl;
573 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(
size_t nn){
581 #pragma omp parallel for
582 for (
long nn=0; nn<n; nn++ ) {
635 cout <<
"Normalizing with a kernel size of " <<
kernel.volume() << endl << endl;
641 for ( i=0; i<datasize; i++ ) pc->
next->
set(i, (*pc)[i] * (*pc)[i]);
643 for ( nn=0; nn<n; nn++ ) {
645 cout <<
"Image " << nn << endl;
646 for ( i=0; i<3; i++ )
647 pc->line_sums(nn, i,
kernel[i]);
654 for ( i=0; i<datasize; i++ ) {
656 s = (*pc->
next)[i] - v*v;
659 v = ((*this)[i] - v)/s;
682 for (
long j=0; j<datasize; j++ ) {
702 for (
long j=0; j<datasize; j++ ) {
704 if ( v > 0 ) v = sqrt(v);
734 double fudge = (avg - min)/1000;
735 double norm = 1.0/(avg - min + fudge);
737 for (
long i=0; i<datasize; i++ )
738 set(i, log(((*
this)[i] - min + fudge)*norm));
756 long i, j, nn, xx, yy, zz;
762 cout <<
"Correcting the image linear gradient:" << endl;
763 cout <<
"Image\tb0\tb1\tb2\tb3" << endl;
768 for ( zz=0; zz<z; zz++ ) {
769 for ( yy=0; yy<y; yy++ ) {
770 for ( xx=0; xx<x; xx++ ) {
784 for ( i=1; i<4; i++ ) {
785 for ( j=0; j<i; j++ )
787 if ( a[i][i] < 1 ) a[i][i] = 1;
790 for ( nn=0; nn<n; nn++ ) {
791 for ( i=0; i<4; i++ ) b[i] = 0;
793 for ( i = nn*x*y*z, zz=0; zz<z; zz++ ) {
794 for ( yy=0; yy<y; yy++ ) {
795 for ( xx=0; xx<x; xx++, i++ ) {
806 cout << n <<
tab << b[0] <<
tab << b[1] <<
tab << b[2] <<
tab << b[3] << endl;
807 for ( i = nn*x*y*z, zz=0; zz<z; zz++ ) {
808 for ( yy=0; yy<y; yy++ ) {
809 for ( xx=0; xx<x; xx++, i++ ) {
810 v = (*this)[i] - (b[0] + b[1]*xx + b[2]*yy + b[3]*zz);
828 long i, xx, yy, zz, nn;
829 double dx, dy, dz, v;
833 for ( i=nn=0; nn<n; nn++ ) {
834 for ( zz=0; zz<z; zz++ ) {
837 for ( yy=0; yy<y; yy++ ) {
840 for ( xx=0; xx<x; xx++, i++ ) {
843 v = param[0] + dx*param[1] + dy*param[2] + dz*param[3]
844 + dx*dx*param[4] + dy*dy*param[5] + dz*dz*param[6];
864 long i, j, nn, nterm(7);
868 vector<double> b(nterm);
869 vector<double> vec(nterm);
871 for ( nn=0; nn<n; nn++ ) {
872 for ( i=0; i<nterm; i++ ) {
873 for ( j=0; j<nterm; j++ ) a[i][j] = 0;
877 for ( zz=0; zz<z; zz++ ) {
881 for ( yy=0; yy<y; yy++ ) {
885 for ( xx=0; xx<x; xx++ ) {
889 i =
index(0,xx,yy,zz,nn);
890 for ( j=0; j<nterm; j++ ) b[j] += vec[j]*(*
this)[i];
891 for ( i=0; i<nterm; i++ )
892 for ( j=0; j<=i; j++ ) a[i][j] += vec[i]*vec[j];
896 for ( i=0; i<nterm-1; i++ )
897 for ( j=i+1; j<nterm; j++ ) a[i][j] = a[j][i];
898 for ( i=0; i<nterm; i++ )
899 if ( fabs(a[i][i]) < 1e-37 ) a[i][i] = 1;
902 cout <<
"Quadric coefficients: " <<
903 b[0] <<
tab << b[1] <<
tab << b[2] <<
tab << b[3] <<
tab << b[4] <<
tab << b[5] <<
tab << b[6] << endl << endl;
922 if ( reference < 1e-30 ) reference =
maximum();
930 cout <<
"Calculating a thickness image:" << endl;
931 cout <<
"Proportionality coefficient: " << lambda << endl;
932 cout <<
"Reference intensity: " << reference << endl << endl;
937 if ( v > 0 && v < reference )
938 pthick->
set(i, lambda*log(reference/v));
int rescale(double scale, double shift)
Rescales the image data with a given multiplier and offset.
void complex_to_intensities()
The intensities from a complex image is written to a simple image.
int truncate(double minim, double maxim, double setmin, double setmax)
Truncates image data to a given minimum and maximum.
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.
double standard_deviation()
Bimage()
Initializes an image.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
int truncate_to_background(double minim, double maxim)
Sets voxels in image data exceeding a given minimum and maximum to the image background.
int normalize(long imgnum, double average, double stdev, int norm_type, long bins)
Normalizes a sub-image to a desired average and standard deviation.
double background(long nn)
Vector3< long > size() const
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Bimage * thickness(double reference, double lambda)
Calculates a thickness based on intensities with respect to a reference.
double length(vector< T > v)
double standard_deviation()
void origin(double x, double y, double z)
void add(long j, double v)
int quadric_correct(vector< double > param)
Corrects for a quadric surface.
int gradient_correction()
Calculates and corrects for a linear gradient across an image.
int normalize_local(long kernel_size)
Normalizes by subtracting local average and dividing by local standard deviation.
int truncate_to_avg(double minim, double maxim)
Sets voxels in image data exceeding a given minimum and maximum to the average.
General image parameter class.
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
double LU_decomposition()
Matrix inversion by LU decomposition.
int replace(Bimage *img)
Replaces the data with that from the given image.
vector< double > quadric_fit()
Fits the whole image to a quadric surface.
Header file for image class.
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Bplot * plot()
Converts a one-dimensional image into a plot.
Bplot * histogram_poisson_fit(long bins, int flag=0)
Fits a poisson function to a histogram of an image.
Header file for general utilities.
ostream & tab(ostream &out)
Bplot * histogram_gauss_plot(long bins, long ngauss=1)
Fits a gaussian function to a histogram of an image.
void change_type(char letter)
Get the data type indicated by a single letter code.
long index(long nx, long ny) const
void square()
Calculates the square of an image.
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
int rescale_to_min_max(double numin, double numax)
Rescales the image data to a given minimum and maximum.
unsigned char * data_pointer()
vector< Vector3< double > > sampling()
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
void square_root()
Calculates the square root of an image.
void sampling(long nn, Vector3< double > u)
int limit_levels(int nlevels)
Converts a full gray scale image to a limited level image.
void logarithm()
Calculates the logarithm of the image data.
long statistics()
Calculates the statistics for an image.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.