 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
56 const char*
month[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
57 "Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"} ;
80 return read_img(fn, readdata, img_select);
85 return read_img(filename.
str(), readdata, img_select);
91 cout <<
"DEBUG read_img: Filename=" << filename <<
" dataflag=" << readdata << endl;
93 if ( !filename.length() ) {
94 cerr <<
"Error: No input image file given!" << endl;
106 string clean_filename(filename.substr(0, filename.find(
"#")));
113 if ( clean_filename.find(
"@") != string::npos ) {
114 img_select = stoi(clean_filename.substr(clean_filename.find(
"@")+1));
115 clean_filename = clean_filename.substr(0, clean_filename.find(
"@"));
119 if ( filename.find(
"://") != string::npos )
120 clean_filename =
find_file(clean_filename, path);
123 clean_filename = clean_filename.substr(0, clean_filename.find(
":"));
128 if ( access(clean_filename.c_str(), R_OK) && ext.find(
"krn") != string::npos )
131 if ( access(clean_filename.c_str(), R_OK) ) {
132 error_show(clean_filename.c_str(), __FILE__, __LINE__);
139 if ( filename.find(
"#") != string::npos )
149 cout <<
"DEBUG read_img: Transferred filename=" << p->
file_name() << endl;
150 cout <<
"DEBUG read_img: Extension=" << ext << endl;
151 cout <<
"DEBUG read_img: img_select=" << img_select << endl;
154 if ( filename.find(
"#") != string::npos || ext.length() < 1 )
156 else if ( ext.find(
"raw") != string::npos )
158 else if ( ext.find(
"asc") != string::npos || ext.find(
"txt") != string::npos )
160 else if ( ext.find(
"bcr") != string::npos )
162 else if ( ext.find(
"pic") != string::npos )
164 else if ( ext.find(
"brx" ) != string::npos || ext.find(
"brix" ) != string::npos )
166 else if ( ext.find(
"dat" ) != string::npos )
168 else if ( ext.find(
"ccp") != string::npos || ext.find(
"map") != string::npos )
170 else if ( ext.find(
"di") != string::npos )
171 err =
readDI(p, readdata, img_select);
172 else if ( ext.find(
"dm") != string::npos )
173 err =
readDM(p, readdata, img_select);
174 else if ( ext.find(
"omap" ) != string::npos || ext.find(
"dsn6") != string::npos || ext.find(
"dn6") != string::npos )
176 else if ( ext.find(
"dx") != string::npos )
177 err =
readDX(p, readdata);
178 else if ( ext.find(
"em") != string::npos )
179 err =
readEM(p, readdata);
180 else if ( ext.find(
"pot") != string::npos )
182 else if ( ext.find(
"grd") != string::npos )
183 err =
readGRD(p, readdata, img_select);
184 else if ( ext.find(
"hkl") != string::npos )
186 else if ( ext.find(
"img") != string::npos || ext.find(
"hed") != string::npos )
188 else if ( ext.find(
"ip") != string::npos )
189 err =
readIP(p, readdata);
190 else if ( ext.find(
"jpg") != string::npos || ext.find(
"jpeg") != string::npos )
192 else if ( ext.find(
"krn") != string::npos )
194 else if ( ext.find(
"mif") != string::npos )
195 err =
readMIFF(p, readdata, img_select);
196 else if ( ext.find(
"mff") != string::npos )
198 else if ( ext.find(
"mrc") != string::npos || ext ==
"stk" )
199 err =
readMRC(p, readdata, img_select);
200 else if ( ext ==
"st" || ext.find(
"ali") != string::npos || ext.find(
"rec") != string::npos )
201 err =
readMRC(p, readdata, img_select);
202 else if ( ext.find(
"pif") != string::npos || ext.find(
"sf") != string::npos )
203 err =
readPIF(p, readdata, img_select);
204 else if ( ext.find(
"bp") != string::npos || ext.find(
"bq") != string::npos )
206 else if ( ext.find(
"png") != string::npos )
208 else if ( ext.find(
"pbm") != string::npos || ext.find(
"pgm") != string::npos || ext.find(
"ppm") != string::npos )
209 err =
readPNM(p, readdata, img_select);
210 else if ( ext.find(
"ser") != string::npos )
212 else if ( ext.find(
"sit") != string::npos )
214 else if ( ext.find(
"spe") != string::npos )
215 err =
readSPE(p, readdata, img_select);
216 else if ( ext.find(
"spi") != string::npos )
218 else if ( ext.find(
"spm") != string::npos || ext.find(
"sup") != string::npos || ext ==
"f" )
220 else if ( ext.find(
"tga") != string::npos )
222 else if ( ext.find(
"tif") != string::npos )
223 err =
readTIFF(p, readdata, img_select);
224 else if ( ext.find(
"xpl") != string::npos || ext.find(
"cns") != string::npos || ext.find(
"rfl") != string::npos )
227 cerr <<
"Error: File format with extension \"" << ext <<
"\" not supported!" << endl;
253 if ( img_select < 0 )
254 cout <<
"Reading file: " << p->
file_name() << endl;
256 cout <<
"Reading image " << img_select <<
" from file: " << p->
file_name() << endl;
261 if ( !p->
data_pointer() ) cout <<
"Data not read!" << endl << endl;
283 string thefile(filename);
285 return write_img(thefile, p, compression);
297 if ( !filename.length() ) {
298 cerr <<
"Error: No output image file name given!" << endl;
302 int err(0), flags(compression);
308 if ( ext.length() < 1 ) {
309 cerr <<
"Error: No extension found in the file name " << filename << endl << endl;
323 if ( ext.find(
"tif") == string::npos && ext.find(
"jp") == string::npos
324 && ext.find(
"mif") == string::npos && ext.find(
"png") == string::npos
325 && ext.find(
"pbm") == string::npos && ext.find(
"pgm") == string::npos
326 && ext.find(
"ppm") == string::npos && ext.find(
"ps") == string::npos
327 && ext.find(
"tga") == string::npos ) {
328 cerr <<
"Warning: Only TIFF, JPEG, PNG, PBM, PGM, PPM, MIFF, TGA or postscript files are acceptable as RGB output formats!" << endl;
336 string::size_type pos = filename.find(
":");
337 if ( pos != string::npos ) filename = filename.substr(pos);
339 pos = filename.find(
"#");
340 if ( pos != string::npos ) filename = filename.substr(pos);
355 cout <<
"DEBUG write_img: Image setup done for file " << p->
file_name() <<
" (extension " << ext <<
")" << endl;
359 if ( ext.find(
"raw") != string::npos )
361 else if ( ext.find(
"asc") != string::npos || ext.find(
"txt") != string::npos )
363 else if ( ext.find(
"bcr") != string::npos )
365 else if ( ext.find(
"pic") != string::npos )
367 else if ( ext.find(
"brx" ) != string::npos || ext.find(
"brix" ) != string::npos )
369 else if ( ext.find(
"dat" ) != string::npos )
371 else if ( ( ext.find(
"ccp") != string::npos || ext.find(
"map") != string::npos ) )
373 else if ( ext.find(
"omap" ) != string::npos || ext.find(
"dsn6") != string::npos || ext.find(
"dn6") != string::npos )
375 else if ( ext.find(
"em") != string::npos )
377 else if ( ext.find(
"dm") != string::npos )
379 else if ( ext.find(
"dx") != string::npos )
381 else if ( ext.find(
"pot") != string::npos )
383 else if ( ext.find(
"grd") != string::npos )
385 else if ( ext.find(
"hkl") != string::npos )
387 else if ( ext.find(
"img") != string::npos || ext.find(
"hed") != string::npos )
389 else if ( ext.find(
"ip") != string::npos )
391 else if ( ext.find(
"jpg") != string::npos || ext.find(
"jpeg") != string::npos )
393 else if ( ext.find(
"krn") != string::npos )
395 else if ( ext.find(
"mff") != string::npos )
397 else if ( ext.find(
"mif") != string::npos )
399 else if ( ext.find(
"mrc") != string::npos || ext ==
"stk" )
401 else if ( ext ==
"st" || ext.find(
"ali") != string::npos || ext.find(
"rec") != string::npos )
403 else if ( ext.find(
"pif") != string::npos || ext.find(
"sf") != string::npos )
405 else if ( ext.find(
"bp") != string::npos || ext.find(
"bq") != string::npos )
407 else if ( ext.find(
"png") != string::npos )
409 else if ( ext.find(
"pbm") != string::npos || ext.find(
"pgm") != string::npos || ext.find(
"ppm") != string::npos )
411 else if ( ext.find(
"ps") != string::npos )
413 else if ( ext.find(
"ser") != string::npos )
415 else if ( ext.find(
"sit") != string::npos )
417 else if ( ext.find(
"spe") != string::npos )
419 else if ( ext.find(
"spi") != string::npos )
421 else if ( ext.find(
"spm") != string::npos || ext.find(
"sup") != string::npos || ext ==
"f" )
423 else if ( ext.find(
"tga") != string::npos )
425 else if ( ext.find(
"tif") != string::npos ) {
426 if ( p->
sizeZ() > 1 ) flags |= 1;
428 }
else if ( ext.find(
"xpl") != string::npos || ext.find(
"cns") != string::npos || ext.find(
"rfl") != string::npos )
431 cout <<
"File format with extension \"" << ext <<
"\" not supported!" << endl << endl;
444 cout <<
"Writing file: " << p->
file_name() << endl;
447 cout <<
"DEBUG write_img: p->data_pointer()=" <<
static_cast<void*
>(p->
data_pointer()) << endl;
459 long hermx,
long friedel,
long oldx,
long nux,
460 long xo1,
long xo2,
long yo1,
long yo2,
461 long zo1,
long zo2,
int z_even,
int y_even)
468 long x, y, z, nz, i, j, izi, izf, iyi, iyf, jz, jy;
469 long xf, yf, zf, xi, yi, zi;
476 for ( z=0; z<p->
sizeZ(); z++ ) {
478 if ( zi < 0 ) zi += p->
sizeZ();
479 if ( zi >= (
int)p->
sizeZ() ) zi -= p->
sizeZ();
481 zf = (zi)? p->
sizeZ()-zi: zi;
484 if ( zf < 0 ) zf += p->
sizeZ();
485 izi = (nz + zi)*p->
sizeY();
486 izf = (nz + zf)*p->
sizeY();
487 jz = (nz + z)*p->
sizeY();
488 for ( y=0; y<p->
sizeY(); y++ ) {
490 if ( yi < 0 ) yi += p->
sizeY();
491 if ( yi >= (
int)p->
sizeY() ) yi -= p->
sizeY();
493 yf = (yi)? p->
sizeY()-yi: yi;
496 if ( yf < 0 ) yf += p->
sizeY();
497 iyi = (izi + yi)*oldx;
498 iyf = (izf + yf)*oldx;
500 for ( x=0; x<nux; x++ ) {
502 if ( xi < 0 ) xi += p->
sizeX();
503 if ( xi >= (
int)p->
sizeX() ) xi -= p->
sizeX();
504 xf = (xi)? p->
sizeX()-xi: xi;
505 if ( !friedel || ( xi < (
int)hermx ) ) {
514 if ( phisgn > 0 ) nusdata[j] = sdata[i];
515 else nusdata[j] = sdata[i].
conj();
517 if ( phisgn > 0 ) nuidata[j] = idata[i];
518 else nuidata[j] = idata[i].
conj();
520 if ( phisgn > 0 ) nufdata[j] = fdata[i];
521 else nufdata[j] = fdata[i].
conj();
523 if ( phisgn > 0 ) nuddata[j] = ddata[i];
524 else nuddata[j] = ddata[i].
conj();
559 cout <<
"DEBUG img_convert_fourier: old transform type = " << p->
fourier_type() << endl;
560 cout <<
"DEBUG img_convert_fourier: new transform type = " << nutransform << endl;
561 cout <<
"DEBUG img_convert_fourier: input size = " << p->
size() << endl;
574 cout <<
"Converting Fourier transform: ";
576 case Standard: cout <<
"Standard -> ";
break;
577 case Centered: cout <<
"Centered -> ";
break;
578 case Hermitian: cout <<
"Hermitian -> ";
break;
579 case CentHerm: cout <<
"Centered hermitian -> ";
break;
582 switch ( nutransform ) {
583 case Standard: cout <<
"Standard";
break;
584 case Centered: cout <<
"Centered";
break;
585 case Hermitian: cout <<
"Hermitian";
break;
586 case CentHerm: cout <<
"Centered hermitian";
break;
589 cout << endl << endl;
592 long hermx = p->
sizeX()/2 + 1;
603 long xo1, yo1, zo1, xo2, yo2, zo2;
620 switch ( nutransform ) {
637 cout <<
"DEBUG img_convert_fourier: hermx=" << hermx <<
" oldx=" << oldx <<
" nux=" << nux << endl;
638 cout <<
"DEBUG img_convert_fourier: input origin={" << xo1 <<
"," << yo1 <<
"," << zo1 << endl;
639 cout <<
"DEBUG img_convert_fourier: output origin={" << xo2 <<
"," << yo2 <<
"," << zo2 << endl;
645 int z_even = 0, y_even = 0;
646 if ( p->
sizeZ()%2 == 0 ) z_even = 1;
647 if ( p->
sizeY()%2 == 0 ) y_even = 1;
650 dispatch_apply(p->
images(), dispatch_get_global_queue(0, 0), ^(
size_t n){
652 xo1, xo2, yo1, yo2, zo1, zo2, z_even, y_even);
655 #pragma omp parallel for
656 for (
long n=0; n<p->
images(); n++ )
658 xo1, xo2, yo1, yo2, zo1, zo2, z_even, y_even);
int readCCP4(Bimage *p, int readdata)
Reading a CCP4 map image file format.
int writeIP(Bimage *p)
Writing an image plate reader file format.
Header file for reading and writing Brix files.
Header file for reading and writing the What If MFF files.
int readBrookhavenSTEM(Bimage *p, int readdata)
Reading a BrookhavenSTEM image file format.
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
int writeKernel(Bimage *p)
Writes a text kernel file.
int writePIC(Bimage *p)
Writing a PIC image file format(s). A 2D image format used in electron microscopy.
int readTIFF(Bimage *p, int readdata, int img_select)
int readDX(Bimage *p, int readdata)
Reading an OpenDX image format.
int writeSPIDER(Bimage *p)
Writing a SPIDER image file format. A 3D image format used in electron microscopy.
int readSitus(Bimage *p, int readdata)
Reading a Situs image format.
int writeGRD(Bimage *p)
Writing a Basel GRD map image file format.
FourierType
Fourier transform format specifier.
int writeBRIX(Bimage *p)
Writing a BRIX image file format.
Header file for reading and writing Brookhaven STEM files.
Header file for file checking functions.
Header file for reading and writing SPE files.
Header file for functions to read and write kernel files.
int readJPEG(Bimage *p, int readdata)
Header file for reading and writing BioRad files.
Header file for reading and writing Image Science's Imagic files.
int writeHKL(Bimage *p)
Writing a HKL structure factor file format. This function writes a HKL structure factor file.
int writeBIORAD(Bimage *p)
Writing a BioRad image file format.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Class for complex numbers.
int information()
Prints out header information for an image.
Header file for reading (only) Digital Instruments files.
Bstring parameter_file_path(Bstring filename)
Finds the parameter file path.
Header file for reading and writing Basel GRD files.
int writeGOODFORD(Bimage *p)
Writing Peter Goodford's GRID map image file format. A 3D image format used for electrostatic potenti...
Vector3< long > size() const
int readDM(Bimage *p, int readdata, int img_select)
Reading a Digital Micrograph image file format.
Header file for unit cell functions.
int writeRAW(Bimage *p)
Writing a raw block of data in a file.
int readGRD(Bimage *p, int readdata, int img_select)
Reading a Basel GRD map image file format.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
int readSER(Bimage *p, int readdata)
Header file for reading and writing AFM BCR-STM files.
int writeSPE(Bimage *p)
Writing a SPE image file format.
int writeMFF(Bimage *p)
Writeing a MFF image format.
Header file for reading and writing Situs files.
int writeEM(Bimage *p)
Writing a EM map image file format. A 3D image format used in electron microscopy.
int writeTIFF(Bimage *p, int istiled)
Header file for (reading and) writing postscript image files.
Header file for reading and writing Truevision TGA files.
void origin(double x, double y, double z)
int readPNM(Bimage *p, int readdata, int img_select)
Reading a PNM type file. A simple image format. PBM bit image format. PGM grayscale image format....
int img_convert_fourier(Bimage *p, FourierType nutransform)
Converts Fourier transform types.
Header file for reading and writing OpenDX files.
Header file for reading and writing CCP4 files.
int readGOODFORD(Bimage *p, int readdata)
Reading Peter Goodford's GRID map image file format. A 3D image format used for electrostatic potenti...
FourierType fourier_type()
int readSUPRIM(Bimage *p, int readdata)
Reading a SUPRIM map image file format. A 3D image format used in electron microscopy....
Header file for reading and writing HKL reflection files as images.
int writePostScriptImage(Bimage *p)
Writing a postscript image format.
Header file for reading and writing SUPRIM files.
Header file for reading and writing image plate reader files.
General image parameter class.
CompoundType compound_type()
Header file for reading and writing DM files.
Class for 3-value vectors.
int readMIFF(Bimage *p, int readdata, int img_select)
Reading an Image Magick map image file format. A 2D image format used for X-windows display....
int readEM(Bimage *p, int readdata)
Reading a EM map image file format. A 3D image format used in electron microscopy....
int readKernel(Bimage *p)
Reads a text kernel file.
int readDSN6(Bimage *p, int readdata)
Reading a DSN6 map image file format.
int readHKL(Bimage *p, int readdata)
Reading a HKL structure factor file format. This function reads a HKL file typically produced with MT...
int writeCCP4(Bimage *p)
Writing a CCP4 map image file format.
int readPIC(Bimage *p, int readdata)
Reading a PIC image file format(s). A 2D image format used in electron microscopy....
int writeASCII(Bimage *p)
Writing an ASCII or text image format.
Header file for reading and writing ASCII files.
int writeIMAGIC(Bimage *p)
Writing an IMAGIC image format. A file format for the IMAGIC package.
Header file for general utilities.
int writeDX(Bimage *p)
Writing a DX image format.
int readASCII(Bimage *p, int readdata)
Reading an ASCII or text image format.
Header file for reading and writing MRC files.
Header file for reading and writing PNG files.
int writeBrookhavenSTEM(Bimage *p)
Writing a BrookhavenSTEM image file format.
Header file for reading and writing DSN6 files.
int writeDM(Bimage *p)
Writing a Digital Micrograph map image file format.
int img_convert_fourier_one(Bimage *p, Complex< float > *nufdata, int n, long hermx, long friedel, long oldx, long nux, long xo1, long xo2, long yo1, long yo2, long zo1, long zo2, int z_even, int y_even)
int readIMAGIC(Bimage *p, int readdata, int img_select)
Reading an IMAGIC image format. A 2D file format for the IMAGIC package. The header is stored in a se...
int writePIF(Bimage *p)
Writing a PIF image file format. A 2D and 3D image format used in electron microscopy.
Header file for 2D and 3D image I/O.
int readTGA(Bimage *p, int readdata)
Reading a Truevision TGA image file format.
int writeXPLOR(Bimage *p)
Writing a XPLOR map or structure factor file format. A text format used in X-ray crystallography.
void meta_data_update()
Update metadata from the sub-image information.
Header file for reading and writing SPIDER files.
int readBIORAD(Bimage *p, int readdata)
Reading a BioRad image file format.
void check()
Checks an image for reasonable properties.
Header file for reading and writing TIFF files.
Bstring find_file(Bstring filename, Bstring path, int flag=0)
Searches for a file within or without the given path.
int writeMIFF(Bimage *p)
Writing an Image Magick map image file format. A 2D image format used for X-windows display.
int subimage_information()
Prints out header information for all sub-images.
int readDI(Bimage *p, int readdata, int img_select)
Reading a Digital Instruments image file format. A two-image 2D image format used in Digital Instrume...
string extension(string filename)
int readMFF(Bimage *p, int readdata)
Reading a MFF image format.
unsigned char * data_pointer()
Header file for reading and writing Raw files.
int readMRC(Bimage *p, int readdata, int img_select)
Reading a MRC map image file format.
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
Header file for reading and writing PIC's BP and BQ files.
int readIP(Bimage *p, int readdata)
Reading an image plate reader file format.
Header file for reading and writing JPEG files.
int writeSUPRIM(Bimage *p)
Writing a SUPRIM map image file format. A 3D image format used in electron microscopy.
int readBCR(Bimage *p, int readdata)
Reading a BCR-STM image format.
Header file for reading and writing PIF files.
Header file for reading and writing PNM files.
int writeSitus(Bimage *p)
Writing a Situs image format.
int readPIF(Bimage *p, int readdata, int img_select)
Reading a PIF image and structure factor file format. A 2D and 3D image format used in electron micro...
int writeDSN6(Bimage *p)
Writing a DSN6 map image file format.
Header file for reading and writing XPLOR reflection files.
int writeMRC(Bimage *p)
Writing a MRC map image file format.
Header file for reading and writing Peter Goodford's GRID files.
int readPNG(Bimage *p, int readdata)
int readBRIX(Bimage *p, int readdata)
Reading a BRIX image file format.
int readSPE(Bimage *p, int readdata, int img_select)
Reading a SPE image file format.
int writeTGA(Bimage *p)
Writing a Truevision TGA map image file format.
Header file for reading and writing EM files.
long statistics()
Calculates the statistics for an image.
Header file for reading and writing FEI Ser files.
int writeBCR(Bimage *p)
Writing a BCR-STM image format.
int readRAW(Bimage *p, int img_select)
Reading a raw block of data in a file.
int readXPLOR(Bimage *p, int readdata)
Reading a XPLOR map or structure factor file format. A minimal implementation.
int writePNM(Bimage *p)
Writing a PNM type file. A simple image format.
int readSPIDER(Bimage *p, int readdata, int img_select)
Reading a SPIDER image file format.