25 #include <Base/Image/Image.hh>
26 #include <Base/Image/ImageConvert.hh>
27 #include <Base/Image/ImageIO.hh>
28 #include <Image/ImagePackage.hh>
29 #include <Image/Camera.hh>
30 #include <Utils/IOUtils.hh>
31 #include <Utils/Param.hh>
32 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
33 #include <Image/ConvertBayerPattern.hh>
45 int main(
int argc,
char* argv[])
49 bool *pack = param.
AddParamBool(
"pack",
"pack ImageList to package",
false,
52 "unpack package, use output to override filenames from package",
false,
54 string *infile = param.
AddParamString(
"input",
"file to process",
"",
'i');
59 "basename of output file(s) (a number and file extension will be added by the program)",
63 "optional camera projection xml file to be set in extracted images",
"",
66 "apply lookuptable mapping with lut file",
"",
'l');
67 bool *toRgb = param.
AddParamBool(
"rgb",
"optional convert to rgb",
false);
72 "if convert to rgb is active, assume this bayer pattern if color model is CM_Grey in the input image",
75 "extension of images to save (in unpack mode)",
"mip",
'e');
77 if (!IOUtils::ParseCommandLineEvalHelp(param, argc, argv))
82 bool bSetProj =
false;
84 if (proj->length() > 0)
92 unsigned int w = 0, h = 0;
94 if (lut->length() > 0)
98 BIASERR(
"you have to add a sink proj for mapping to work");
108 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
114 vector<string> imageNames;
115 if (Param::ParseListFile(*infile, imageNames) != 0)
117 BIASERR(
"error parsing image names!");
123 for (
unsigned int i = 0; i < imageNames.size(); i++)
126 cout <<
"adding image: " << imageNames[i] << endl;
130 ImageIO::Load(imageNames[i], im);
135 BIASERR(
"to rgb only for unsigned char images.");
141 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
142 if (ucharsrc.GetChannelCount() == 1)
143 demosaic.
Convert(ucharsrc, uchardst);
145 ImageConvert::ToRGB(ucharsrc, uchardst);
147 ImageConvert::ToRGB(ucharsrc, uchardst);
149 uchardst.SetMetaData( meta );
155 BIASERR(
"lut map only for unsigned char images.");
161 uchardst.FillImageWithConstValue((
unsigned char)0);
184 if (infile->find(
".pack") == string::npos)
186 cout <<
"input file should end with .pack" << endl;
189 string fname = *infile;
190 unsigned pos = fname.find(
".pack");
192 fname = fname.substr(0,pos);
195 cout<<
"*** Opened package ***: "<<fname<<endl;
204 == ImageBase::CM_Grey)
208 if (strcmp(bayer->c_str(),
"BGGR") == 0)
210 cout <<
"converting bayer BGGR to RGB" << endl;
211 pattern = ImageBase::CM_Bayer_BGGR;
213 else if (strcmp(bayer->c_str(),
"GBRG") == 0)
215 cout <<
"converting bayer GBRG to RGB" << endl;
216 pattern = ImageBase::CM_Bayer_GBRG;
218 else if (strcmp(bayer->c_str(),
"GRBG") == 0)
220 cout <<
"converting bayer GRBG to RGB" << endl;
221 pattern = ImageBase::CM_Bayer_GRBG;
223 else if (strcmp(bayer->c_str(),
"RGGB") == 0)
225 cout <<
"converting bayer RGGB to RGB" << endl;
226 pattern = ImageBase::CM_Bayer_RGGB;
230 cout << *bayer <<
"? i dont know this pattern... abort!"
242 BIASERR(
"to rgb only for unsigned char images.");
248 #if !defined(WIN32) && defined(BIAS_HAVE_DC1394)
249 if (ucharsrc.GetChannelCount() == 1)
250 demosaic.
Convert(ucharsrc, uchardst);
252 ImageConvert::ToRGB(ucharsrc, uchardst);
254 ImageConvert::ToRGB(ucharsrc, uchardst);
256 uchardst.SetMetaData( meta );
262 BIASERR(
"lut map only for unsigned char images.");
268 uchardst.FillImageWithConstValue((
unsigned char)0);
282 if (outfile->length() > 0)
284 filename = *outfile + FileHandling::LeadingZeroString(++n, 5)
287 else if (ext->compare(
"mip") != 0)
289 filename = filename.substr(0, filename.rfind(
"."));
290 filename +=
"." + (*ext);
292 cout <<
"saving: " << filename << endl;
293 ImageIO::Save(filename, im);
EColorModel
These are the most often used color models.
InterpolationMethod
accuracy for resampling
virtual int Load(const std::string &filename)
convenience wrapper which tries to read different formats
int SetLookupTable(const std::string &filename, InterpolationMethod &method)
Loads the LUT from a file, replaces the call to PrepareLookupTableMapping().
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
void SetColorModel(EColorModel Model)
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
int Open(const std::string filename)
open a package
unsigned int GetWidth() const
Wrapper class to dc1394 bayer conversion class.
const void * GetImageData() const
const ProjectionParametersBase * GetParameters(unsigned int cam=0) const
const parameter access function
This class hides the underlying projection model, like projection matrix, spherical camera...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int SetProj(const Projection &Proj)
unsigned int GetHeight() const
An Image Package is multiple .mip images in one file.
virtual int GetImageSize(unsigned int &Width, unsigned int &Height) const
Obtain image dimensions.
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
enum EColorModel GetColorModel() const
int UpdateMetaData()
copy P_ and co.
int GetNextImage(ImageBase &image, std::string &filename)
get next image, call subsequently to walk through package file
This class Param provides generic support for parameters.
int MapWithLookupTable(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod method)
applies precomputed coordinates in src, fast for repeated usages of same mapping function ...
invalid (not set) image format
enum EStorageType GetStorageType() const
void SetMetaData(const MetaData &m)
This is the base class for images in BIAS.
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
int Create(const std::string filename, unsigned int num=1)
Create image Package file.
int ParseMetaData(bool bUse2x64bitTS=true)
After ImageIO::Load() operated on AppData_, this method fills P_, Timestamp, DC_*, ...
int Convert(Image< StorageType > &src, Image< StorageType > &dst, BayerDemosaicMethod method=BAYER_DEMOSAIC_METHOD_AHD, ImageBase::EColorModel bayer_pattern=ImageBase::CM_invalid)
converts image with bayerpattern to rgb.
int AddImage(const ImageBase image, const std::string filename="")
Adding an image with empty filename will use default name.