Bsoft  1.9
Bernard's software package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
img_util.cpp
Go to the documentation of this file.
1 
9 #include "rwimg.h"
10 #include "utilities.h"
11 
12 // Declaration of global variables
13 extern int verbose; // Level of output to the screen
14 
15 
26 {
27  if ( !p->data_pointer() ) return NULL;
28 
29  if ( p->size().volume() < 1 ) {
30  error_show("img_rotate_by_pi", __FILE__, __LINE__);
31  cerr << "Error: Size of image is less than one!" << endl;
32  return NULL;
33  }
34 
35  Bimage* prot = p->copy_header();
36  prot->data_alloc();
37 
38  unsigned long i, j, c, x, y, z, n, oldx, oldy, oldz;
39 
40  if ( verbose & VERB_LABEL )
41  cout << "Rotating an image by PI" << endl << endl;
42 
43  for ( i=n=0; n<p->images(); n++ ) {
44  for ( z=0; z<p->sizeZ(); z++ ) {
45  oldz = p->sizeZ() - z - 1;
46  for ( y=0; y<p->sizeY(); y++ ) {
47  oldy = p->sizeY() - y - 1;
48  for ( x=0; x<p->sizeX(); x++ ) {
49  oldx = p->sizeX() - x - 1;
50  j = (((n*p->sizeZ()+oldz)*p->sizeY() + oldy)*p->sizeX() + oldx)*p->channels();
51  for ( c=0; c<p->channels(); c++, i++, j++ ) prot->set(i, (*p)[j]);
52  }
53  }
54  }
55  }
56 
57  return prot;
58 }
59 
unsigned long images()
Definition: Bimage.h:402
Bimage * copy_header()
Definition: Bimage.h:478
Bimage * img_rotate_by_pi(Bimage *p)
Rotates an image by pi.
Definition: img_util.cpp:25
void sizeX(unsigned long nx)
Definition: Bimage.h:332
int verbose
Header file for general utilities.
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:616
unsigned long channels()
Definition: Bimage.h:327
Vector3< int > size()
Definition: Bimage.h:329
General image parameter class.
Definition: Bimage.h:149
unsigned char * data_alloc()
Definition: Bimage.h:220
void set(unsigned long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:885
unsigned char * data_pointer()
Definition: Bimage.h:225
void sizeZ(unsigned long nz)
Definition: Bimage.h:334
Header file for 2D and 3D image I/O.
void sizeY(unsigned long ny)
Definition: Bimage.h:333
#define VERB_LABEL
Definition: utilities.h:98
double volume()
Definition: Vector3.h:207