Non-uniformity correction of infrared images by midway equalization
|
00001 /* 00002 * Copyright 2012 IPOL Image Processing On Line http://www.ipol.im/ 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00035 #ifdef _OPENMP 00036 #include <omp.h> 00037 #endif 00038 #include <stdio.h> 00039 #include <stdlib.h> 00040 #include <iostream> 00041 #include "io_png/io_png.h" 00042 #include "MIRE.h" 00043 #include "borders.h" 00044 00053 int main(int argc, char **argv) 00054 { 00055 //Check arguments : IN OUT; 00056 if (argc != 3) 00057 { 00058 std::cerr << " **************************************** " << std::endl 00059 << " ********** MIRE ******************************** " << std::endl 00060 << " ************************************************** " << std::endl 00061 << "Usage: " << argv[0] << " ImNoisy.png ImDenoised.png " << std::endl 00062 << "Input" << std::endl 00063 << "ImNoisy: columns artifacts, gray (1 channel), PNG. " << std::endl 00064 << "Output" << std::endl 00065 << "ImDenoised: denoised in PNG. " << std::endl 00066 << " ************************************************** " << std::endl 00067 << "**************** Yohann Tendero, 2011 *********** " << std::endl 00068 << " ************************************************** " << std::endl; 00069 return 1; 00070 } 00071 00075 00076 //During the optimal sigma parameter guess phase each sigma such that 00077 //sigma=SIGMA_MIN+k*DELTAT and sigma<=SIGMA_MAX will be tested. 00078 00079 const int SIGMA_MIN=0; // minimal std-dev of the Gaussian-weighting function 00080 const int SIGMA_MAX=8; //maximal std-dev of the Gaussian-weighting function 00081 const float DELTA=0.5; //step between two consecutive std-dev 00082 00083 00084 00085 00089 00090 float * Image; //image 00091 size_t w1, h1; // width an height of the image 00092 if (NULL == (Image = read_png_f32_gray(argv[1], &w1, &h1))) 00093 { 00094 std::cerr << "Unable to load file " << argv[1] << std::endl; 00095 return 1; 00096 } 00097 00098 00099 00103 00104 00105 00106 00107 int W=w1+8*SIGMA_MAX; 00108 //new width of image afer mirror symmetry : 4 times SIGMA_MAX on each sides 00109 float* Imsym= new float[W*h1]; //new image allocation 00110 00111 //input : image, New image, width,height, total size of the extension 00112 borders(Image,Imsym,w1,h1,4*SIGMA_MAX); //Output : 00113 //Classic mirror symmetry on columns : 00114 // C1 C2 ... CN => C2 C1 |C1 C2 ... CN|CN CN-1 etc 00115 00116 00117 00118 00119 00123 00124 //input image , width (after symetrication), height 00125 MIRE_automatic(Imsym,W,h1,SIGMA_MIN, SIGMA_MAX, DELTA); 00126 00127 00128 00129 00133 00134 00135 00136 //#pragma omp parallel for 00137 // The following realize a CROP 00138 for (unsigned column=0;column<w1;column++) // for all columns 00139 { 00140 for (unsigned line=0;line<h1;line++) // for all lines 00141 { 00142 Image[line*w1+column] 00143 =Imsym[line*(w1+8*SIGMA_MAX)+column+4*SIGMA_MAX]; 00144 // using the useless memory of the input 00145 } 00146 } 00147 00148 delete [] Imsym; 00149 00150 00151 00156 00157 00158 //Computing the min and max of the output 00159 float min=Image[0]; 00160 float max=Image[0]; 00161 //#pragma omp parallel for 00162 for (unsigned i=1;i<w1*h1;i++) 00163 { 00164 if (Image[i]<min) min=Image[i]; 00165 if (Image[i]>max) max=Image[i]; 00166 } 00167 00168 00169 //Actually changing image-values 00170 //#pragma omp parallel for 00171 for (unsigned i=1;i<w1*h1;i++) 00172 { 00173 Image[i]=(255*(Image[i]-min)/(max-min)); 00174 } 00175 00176 00180 write_png_f32(argv[2],Image,w1, h1, 1); 00181 free(Image); 00182 00183 00184 return 0; 00185 }