Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TestImageIO.cpp
1 #include <Base/Image/ImageIO.hh>
2 
3 #include <string>
4 
5 using namespace BIAS;
6 using namespace std;
7 
8 int main(int argc, char *argv[])
9 {
10  const unsigned width=640, height=480, cc=1;
11  const bool interleaved = true;
12  ImageBase fib(width, height, cc, ImageBase::ST_float, interleaved);
13  ImageBase ucib(width, height, cc, ImageBase::ST_unsignedchar, interleaved);
14  Image<float> fi(width, height, cc, interleaved);
15  Image<unsigned char> uci(width, height, cc, interleaved);
16 
17  const string fname="float_img.mip", ucname="unsigned_char_image.mip";
18  if (ImageIO::Save(fname, fib)!=0){
19  cerr << "Error saving float image\n";
20  BIASABORT;
21  }
22  if (ImageIO::Save(ucname, ucib)!=0){
23  cerr << "Error saving unsigned char image\n";
24  BIASABORT;
25  }
26 
27  // try to re-load images as ImageBase and as template
28  if (ImageIO::Load(fname, fi)!=0){
29  cerr << "Error reloading float image into Image<float>\n";
30  BIASABORT;
31  }
32  if (ImageIO::Load(ucname, uci)!=0){
33  cerr << "Error reloading unsigned char image into Image<unsigned char>\n";
34  BIASABORT;
35  }
36  if (ImageIO::Load(fname, fib)!=0){
37  cerr << "Error reloading float image into ImageBase with StorageType "
38  << "float\n";
39  BIASABORT;
40  }
41  if (ImageIO::Load(ucname, ucib)!=0){
42  cerr << "Error reloading unsigned char image into ImageBase with "
43  << "StorageType unsigned char \n";
44  BIASABORT;
45  }
46 
47  // try to load image of wrong StorageType must fail
48  if (ImageIO::Load(ucname, fi)==0){
49  cerr << "Error: Loaded unsigned char image into Image<float> "
50  << "without error\n";
51  BIASABORT;
52  }
53  if (ImageIO::Load(fname, uci)==0){
54  cerr << "Error: Loaded float image into Image<unsigned char> without "
55  << "error\n";
56  BIASABORT;
57  }
58  if (ImageIO::Load(ucname, fib)==0){
59  cerr << "Error: Loaded unsigned char image into ImageBase with StorageType "
60  << "float without error\n";
61  BIASABORT;
62  }
63  if (ImageIO::Load(fname, ucib)==0){
64  cerr << "Error: Loaded float image into ImageBase with StorageType "
65  << "unsigned char without error\n";
66  BIASABORT;
67  }
68 
69  // when the StorageType of image base is not determined, loading must succeed
70  ImageBase ib1, ib2;
71  if (ImageIO::Load(ucname, ib1)!=0){
72  cerr << "Error loading unsigned char image into ImageBase with "
73  << "StorageType unknown\n";
74  BIASABORT;
75  }
76  if (ImageIO::Load(fname, ib2)!=0){
77  cerr << "Error loadingfloat image into ImageBase with "
78  << "StorageType unknown\n";
79  BIASABORT;
80  }
81 
82  if (argc==1){ cout << "OK\n"; }
83  return 0;
84 }
float image storage type
Definition: ImageBase.hh:118
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102