Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biasscaleshiftimage.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #include <Base/Common/BIASpragma.hh>
26 #include <Base/Image/ImageBase.hh>
27 #include <Base/Image/ImageIO.hh>
28 #include <Base/Image/ImageConvert.hh>
29 #include <stdio.h>
30 #include <string>
31 #include <Utils/Param.hh>
32 #include <Utils/IOUtils.hh>
33 
34 using namespace BIAS;
35 using namespace std;
36 
37 void usage(int argc, char* argv[])
38 {
39  cout<<"\n"<<argv[0]<<" --help for usage instructions"<<endl;
40 }
41 
42 /**
43  @file
44  @ingroup g_tools
45  @brief scales and shifts image values in given range, see biasscaleshiftimage.cpp
46  @author ischiller
47 */
48 int main (int argc, char *argv[])
49 {
50  if(argc<2){
51  usage(argc, argv);
52  return -1;
53  }
54 
55  Param *param = new Param(true);
56  string *sourceImageName,*sinkImageName;
57  double *min, *max;
58  bool *convertToUC;
59  BIAS::ImageBase origImage;
60 
61  sourceImageName = param->AddParamString("SourceImage",
62  "The source Image",
63  "",'s');
64  sinkImageName = param->AddParamString("TargetImage",
65  "The target Image",
66  "",
67  't');
68 
69 
70  min = param->AddParamDouble("Min","Minimum Scaling value",0,0,255,'i');
71  max = param->AddParamDouble("Max","Maximum Scaling value",255,0,255,'a');
72 
73  convertToUC = param->AddParamBool("ConvertToUC","Convert to unsigned char image",false,'c');
74 
75  if(!IOUtils::ParseCommandLineEvalHelp(*param, argc, argv)) {
76  cout<<"Tool for Scaling and Shifting images:"<<endl;
77  return -1;
78  }
79  int res=0;
80  if((res = BIAS::ImageIO::Load(*sourceImageName,origImage)) <0)
81  {
82  cout<<" Loading of source image :"<<*sourceImageName<<"failed!"<<endl;
83  return -1;
84  }
85 
86 
88 
89  if(type==BIAS::ImageBase::ST_float){
90  BIAS::Image<float> resImage(origImage);
91  resImage.ScaleShiftBetween(*min,*max);
92  if(*convertToUC){
95  BIAS::ImageIO::Save(*sinkImageName,imageUC);
96  }
97  else{
98  BIAS::ImageIO::Save(*sinkImageName,resImage);
99  }
100  cout<<"Wrote image to "<<*sinkImageName<<endl;
101  }
102  else if(type==BIAS::ImageBase::ST_unsignedchar){
103  BIAS::Image<unsigned char> resImage(origImage);
104  resImage.ScaleShiftBetween(*min,*max);
105  BIAS::ImageIO::Save(*sinkImageName,resImage);
106  cout<<"Wrote image to:"<<*sinkImageName<<endl;
107  }
108  else{
109  cout<<"Source Image is of wrong storage type:"<<type<<endl;
110  return -1;
111  }
112 
113 
114 }
115 
116 
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:351
float image storage type
Definition: ImageBase.hh:118
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
static bool ParseCommandLineEvalHelp(Param &params, int argc, char *argv[])
parses the command line, adds parameter &quot;help&quot;
Definition: IOUtils.cpp:176
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
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
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:327