35 #include <Base/Image/Image.hh>
36 #include <Base/Image/ImageIO.hh>
37 #include <Base/Image/ImageConvert.hh>
38 #include <Base/ImageUtils/ImageDraw.hh>
39 #include <Base/Math/Random.hh>
40 #include <Image/JointHistogram.hh>
41 #include <Image/HistogramImage.hh>
43 #include <Filter/GradientGauss.hh>
44 #include <Filter/GradientSimple.hh>
49 int main(
int argc,
char *argv[])
53 Image<float> gauss1, gauss2, gauss1X, gauss1Y,gauss2X,gauss2Y;
59 cerr<< argv[0] <<
" <reference image> <output> <usegradient> filenames"<<endl;
65 cerr <<
"error loading file " << argv[1] <<
" " << res << endl;
70 cerr <<
"wrong channel count in image"<< endl;
74 int numberOfImages = argc-1;
75 std::vector<string> images;
78 float minJointEntropy=100000.0;
79 string minJointEntropyImageName;
80 string maxNMIImageName;
82 for(
int i=4;i<=numberOfImages;i++){
86 cerr <<
"error loading file " << argv[1] <<
" " << res << endl;
90 cout<<
"\nUsing image: "<<argv[i]<<
" for comparison"<<endl;
93 cerr <<
"wrong channel count in image"<< endl;
97 if(atoi(argv[3]) > 0){
98 gradientGenerator.
Filter(image1, gauss1X, gauss1Y, gauss1);
99 gradientGenerator.
Filter(image2, gauss2X, gauss2Y, gauss2);
100 if(atoi(argv[3]) == 2){
101 cout<<
"Using angle directions"<<endl;
109 double gradientThreshold = 30;
110 for(
unsigned int x=0;x<image1.
GetWidth();x++){
111 for(
unsigned int y=0;y<image1.
GetHeight();y++){
112 double YGradValue = idaY1[y][x];
113 double XGradValue = idaX1[y][x];
115 angle = atan2(YGradValue,XGradValue);
118 while (angle<0.0f) angle += 2.0f * (float)M_PI;
119 if (angle>
float(2.0f*M_PI)) angle = 2.0f * (
float)M_PI;
120 angle = (angle*180)/M_PI;
122 if(dst1[y][x] >= gradientThreshold)
123 dst1[y][x] = (float)angle;
125 dst1[y][x] = (float)0;
128 YGradValue = idaY2[y][x];
129 XGradValue = idaX2[y][x];
130 angle = atan2(YGradValue,XGradValue);
133 while (angle<0.0f) angle += 2.0f * (float)M_PI;
134 if (angle>
float(2.0f*M_PI)) angle = 2.0f * (
float)M_PI;
136 angle = (angle*180)/M_PI;
137 if(dst2[y][x] >= gradientThreshold)
138 dst2[y][x] = (float)angle;
140 dst2[y][x] = (float)0;
152 std::string filename;
158 jhist.
Draw(tmpImage);
164 cout<<
"Shannon Joint Entropy :"<<entropy<<endl;
165 if(entropy < minJointEntropy)
167 minJointEntropy = entropy;
168 minJointEntropyImageName = argv[i];
170 jhist.
Draw(tmpImage);
183 cout<<
"Shannon Entropies :"<<entropy0<<
","<<entropy1<<endl;
188 nmi = (entropy0 + entropy1)/entropy;
192 maxNMIImageName = argv[i];
195 cout<<
"Normalized Mutual Information: "<<nmi<<endl;
199 cout<<
"\n\n***************************************************************\n";
200 cout<<
"******************* Final results: *************************** \n";
201 cout<<
"ImageName with maximum NMI: "<<maxNMIImageName<<endl;
202 cout<<
"MaxNMI : "<<maxNMI<<endl;
203 cout<<
"ImageName with min JointEntropy: "<<minJointEntropyImageName<<endl;
204 cout<<
"Min Joint Entropy : "<<minJointEntropy<<endl;
205 cout<<
"***************************************************************\n";
float CalcShannonEntropy(unsigned int hist=0)
calculates the Shannon Entropy and treats entries in HistogramImage as probabilities ...
int InitHist(unsigned int bincount=256, unsigned int histcount=1)
reserves the internal data structures for histcount histograms with bincount bins in each in one imag...
int Draw()
actually draws histogram(s) from the internal data structures
unsigned int GetWidth() const
int AddHist(const Image< StorageType > &Image, unsigned int hist=0)
calculates the histogram of image and adds them to the internal data structures
simple gradient calculation gx(x,y) = I(x+1,y) - I(x-1,y) gy(x,y) = I(x,y+1) - I(x,y-1)
void Draw(BIAS::Image< float > &image)
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
float CalcShannonEntropy()
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
int Compute(BIAS::Image< StorageType > &image1, BIAS::Image< StorageType > &image2)
unsigned int GetHeight() const
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.
Class for easy histogram image generation.
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
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy
static int IP_ToGrey(Image< StorageType > &img)
In place conversion to gray image.
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase