Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biasdiv.cpp
1 #include <Base/Debug/Error.hh>
2 #include <Base/Image/ImageIO.hh>
3 #include <Utils/Param.hh>
4 #include <iostream>
5 
6 using namespace BIAS;
7 using namespace std;
8 
9 /** @file
10  @ingroup g_tools
11  @brief tool for computing pixelwise division of two images, see biasdiv.cpp
12  @author woelk (vision^n) 09/2007 */
13 int main(int argc, char ** argv)
14 {
15  Param param;
16  param.AddParamBool("help","",false, 'h');
17  param.AddParamBool("ignoreNegative", "do not use negative values",
18  false,'n');
20 
21  int next = param.ParseCommandLine(argc, argv);
22  if (argc<4 || *param.GetParamBool("help")){
23  param.Usage();
24  if (argc>0) cerr << argv[0] <<" <image 1> <image 2> <outfile> \n";
25  cerr << " divides image 1 by image 2 (pixelwise) and writes the result "
26  <<"to outfile"<<endl;
27  return 0; // for Dart testing
28  }
29 
30  ImageBase im1, im2, result;
31  if (ImageIO::Load(argv[next], im1)!=0){
32  BIASERR("error loading "<<argv[next]);
33  return -1;
34  }
35  if (ImageIO::Load(argv[next+1], im2)!=0){
36  BIASERR("error loading "<<argv[next+1]);
37  return -1;
38  }
39  if (!im1.SamePixelAndChannelCount(im2)) {
40  BIASERR("image size,depth,or ST does not match");
41  exit(-2);
42  }
43  BIASASSERT(im1.GetStorageType()==im2.GetStorageType());
44  BIASASSERT(im1.GetWidth()==im2.GetWidth());
45  BIASASSERT(im1.GetHeight()==im2.GetHeight());
46 
47  switch (im1.GetStorageType()){
48  case ImageBase::ST_float:
49  {
50  Image<float> fim1(im1), fim2(im2), div;
51  div = fim1 / fim2;
52 
53  if (*param.GetParamBool("ignoreNegative")){
54  cout << "ignoring negative\n";
55  float *i1=fim1.GetImageData();
56  float *i2=fim2.GetImageData();
57  float *d=div.GetImageData();
58  float *end = i1 + fim1.GetPixelCount() * fim1.GetChannelCount();
59  // ignore negative pixel
60  do {
61  if ( (*i1)<=0.0 || (*i2) <=0.0) *d = 0.0;
62  i1++; i2++; d++;
63  } while (i1<end);
64 
65  if (ImageIO::Save(string(argv[next+2]), div)!=0){
66  BIASERR("error writing "<<argv[next+2]);
67  }
68  }
69  }
70  break;
71  default:
72  cerr << "storage type not supported \n";
73  break;
74  }
75  return 0;
76 }
void DisableDestructorWarning()
Uses this just before end of your program to avoid error from destructor.
Definition: Param.hh:513
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
float image storage type
Definition: ImageBase.hh:118
unsigned int GetWidth() const
Definition: ImageBase.hh:312
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
bool * GetParamBool(const std::string &name) const
Definition: Param.cpp:633
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
Definition: Param.cpp:176
unsigned int GetHeight() const
Definition: ImageBase.hh:319
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same &quot;size&quot; as Image of other type
Definition: ImageBase.hh:73
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
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
Definition: Image.hh:137
This class Param provides generic support for parameters.
Definition: Param.hh:231
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
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
This is the base class for images in BIAS.
Definition: ImageBase.hh:102