32 #include <Base/Image/ImageBase.hh>
33 #include <Base/Image/ImageIO.hh>
34 #include <Base/Image/ImageConvert.hh>
35 #include <Image/HomographyMapping.hh>
36 #include <Utils/Param.hh>
37 #include <Utils/IOUtils.hh>
47 cout <<
"Usage: biasaverage [options] files"<<endl;
48 cout <<
" Options: "<< endl
49 <<
" -r : rescale output by 2"<<endl
51 cout <<
"at each pixel position average values of all images"<<endl<<endl;
56 string::size_type EndOfPrefix;
59 EndOfPrefix = fn.rfind(
'.');
61 if (EndOfPrefix == string::npos)
return -1;
62 suffix = fn.substr(EndOfPrefix+1,fn.length());
72 int main (
int argc,
char *argv[])
76 string* imageList = params.
AddParamString(
"images",
"list of images",
"",
'i');
77 string* output = params.
AddParamString(
"output",
"output filename (defaults to average.mip",
"average.mip",
'o');
78 string* varoutput = params.
AddParamString(
"varoutput",
"variance output filename (defaults to variance.mip",
"variance.mip",
'O');
79 string* outputUC = params.
AddParamString(
"outputUC",
"output filename of uchar image (defaults to average.pgm",
"average.pgm",
'u');
80 double* rescaleFactor = params.
AddParamDouble(
"rescale",
"rescale factor", 1.0, 0.001, 1000.0,
'r');
81 bool* convertToRGB = params.
AddParamBool(
"convertToRGB",
"Convert to RGB before calculating",
false,
'c');
82 bool* computeVariance = params.
AddParamBool(
"computeVariance",
"Also compute a variance image",
false,
'v');
83 bool* analyzeSamples = params.
AddParamBool(
"analyzeSamples",
"Analyze 5 sample points",
false,
'a');
88 if (imageList->length() == 0) {
93 vector<string> imageNames;
95 BIASERR(
"error parsing image names!" << *imageList);
100 if (*rescaleFactor != 1.0) {
101 std::cout <<
"rescale"<<endl;
109 bool initialized =
false;
110 bool ucharout =
true;
113 for (
unsigned int i=0;i<imageNames.size();i++) {
115 BIASERR(
"Error reading "<< imageNames[i]);
150 for (
unsigned int y=0; y<CurImage.
GetHeight(); y++) {
152 for (
unsigned int x=0; x<CurImage.
GetWidth(); x++) {
153 for (
unsigned int c=0; c<channels; c++) {
157 ((
float**)ida)[y][x*channels+c];
164 float( ((
unsigned char**)ida)[y][x*channels+c]) ;
166 BIASERR(
"Unknown storage type" << imageNames[i]);
173 averageImage.
ScaleShift(1.0/
double(countImages),0);
180 for (
unsigned int i=0;i<imageNames.size();i++) {
183 BIASERR(
"Error reading "<< imageNames[i]);
203 for (
unsigned int y=0; y<averageImage.
GetHeight(); y++) {
204 for (
unsigned int x=0; x<averageImage.
GetWidth(); x++) {
205 for (
unsigned int c=0; c<channels; c++) {
206 idaVar[y][x*channels+c] += pow( (idaAv[y][x*channels+c]-((
float**)ida)[y][x*channels+c]),2);
211 varianceImage.
ScaleShift(1.0/
double(countImages),0);
215 unsigned width = averageImage.
GetWidth();
216 unsigned height = averageImage.
GetHeight();
220 vector<Vector2<unsigned> > points;
222 p.Set(width-10,height-10); points.push_back(p);
223 p.Set(width/2,height/2); points.push_back(p);
224 p.Set(width-10,10); points.push_back(p);
225 p.Set(10,height-10); points.push_back(p);
226 for(
unsigned i=0;i<points.size();i++){
227 cout<<
"Mean at "<<points[i]<<
": "<<idaAv[points[i][1]][points[i][0]]<<endl;
228 cout<<
"Variance at "<<points[i]<<
": "<<idaVar[points[i][1]][points[i][0]]<<endl;
232 float *mean =
new float[channels];
233 float *var =
new float[channels];
237 cout<<
"Image mean and variance variance : ";
238 for(
unsigned i=0;i<channels;i++) cout<<mean[i]<<
" "<<var[i]<<endl;
247 H[0][0] = H[1][1] = 1.0 / (*rescaleFactor);
248 rescaled.
Init((
unsigned int)ceil( (*rescaleFactor)*
double(averageImage.
GetWidth()) ),
250 if(*computeVariance){
251 varRescaled.
Init((
unsigned int)ceil( (*rescaleFactor)*
double(averageImage.
GetWidth()) ),
256 if(*computeVariance){
260 rescaled = averageImage;
262 varRescaled = varianceImage;
264 if(*convertToRGB ==
false) {
274 if(*convertToRGB ==
false) {
a 3x3 Matrix describing projective transformations between planes
Maps image src to image sink with homography H (software implementation)
bool IsInterleaved() const
void SetColorModel(EColorModel Model)
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
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)
int ScaleShift(double Scale, double Shift)
scales and shifts image (all channels simultanously)
unsigned int GetWidth() const
void GetMeanPixelValue(StorageType mean[])
calculates mean of pixel
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
void ** GetImageDataArray() const
Get an array of pointers to image data.
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
color values, 3 channels, order: red,green,blue
TFileFormat
format specifier when writing an image to a file Do NOT change order or associated enum value because...
unsigned int GetHeight() const
int Map(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod=MapTrilinear, bool newSink=false, double SuperSampling=1.0)
backward mapping with various interpolations
static int ParseListFile(const std::string &ListFileName, std::vector< std::string > &LinesInFile)
Extracts lines from passed file.
static bool ParseCommandLineEvalHelp(Param ¶ms, int argc, char *argv[])
parses the command line, adds parameter "help"
bool SamePixelAndChannelCount(const ImageBase &Image) const
checks if data area has same "size" as Image of other type
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.
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
enum EColorModel GetColorModel() const
This class Param provides generic support for parameters.
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...
enum EStorageType GetStorageType() const
(8bit) unsigned char image storage type
This is the base class for images in BIAS.
void SetHomography(const HMatrix &H)
set your homography H (source = H * sink) before calling Map()
std::string * AddParamString(const std::string &name, const std::string &help, std::string deflt="", char cmdshort=0, int Group=GRP_NOSHOW)
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.
void SetZero()
zeroes the image
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase