00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef IMAGE_OMNI_C_DEFINED
00040 #define IMAGE_OMNI_C_DEFINED
00041
00042 #include "Image/OmniOps.H"
00043
00044 #include "Image/Image.H"
00045 #include "Image/Pixels.H"
00046
00047 #include <cmath>
00048 #include <iostream>
00049
00050
00051 template <class T>
00052 void lowPassPixel(Image<T>& src,
00053 const int x, const int y, const int radius)
00054 {
00055 int startX = x - radius, endX = x + radius;
00056 int startY = y - radius, endY = y + radius;
00057 T sum = T(); int n = 0;
00058 if (startX < 0) startX = 0;
00059 if (endX > src.getWidth() - 1) endX = src.getWidth() - 1;
00060 if (startY < 0) startY = 0;
00061 if (endY > src.getHeight() - 1) endY = src.getHeight() - 1;
00062 for (int xx = startX; xx < endX ; xx++)
00063 for(int yy = startY; yy < endY; yy++)
00064 { sum += src.getVal(xx, yy); n ++; }
00065 sum /= n;
00066 src.setVal(x, y, sum);
00067 }
00068
00069
00070 template <class T>
00071 Image<PixRGB<T> > omniCorrectGen(const Image<PixRGB<T> >& src,
00072 const int Rx, const int Ry,
00073 const int Xc, const int Yc,
00074 const int RA)
00075 {
00076 Point2D<int> oldPoint, point;
00077 float newX = 0.0F, newY = 0.0F, absX, absY;
00078 bool negX, negY, noPix, stop;
00079
00080 PixRGB<T> value;
00081
00082 Image<PixRGB<T> > result(src.getDims(), NO_INIT);
00083
00084 Dims dims = src.getDims();
00085
00086 for (int x = 0; x < dims.w(); x++)
00087 {
00088 std::cout << ".";
00089 for(int y = 0; y < dims.h(); y++)
00090 {
00091 noPix = false; stop = false; oldPoint.i = x; oldPoint.j = y;
00092
00093 absX = fabs(Rx - x);
00094 absY = fabs(Ry - y);
00095 if (x < Xc) negX = true; else negX = false;
00096 if (y < Yc) negY = true; else negY = false;
00097
00098 if ((absY <= Ry) && (absY != 0))
00099 newX = sqrt(1.0 - pow((absY / (Ry + RA)), 2.0));
00100 else
00101 noPix = true;
00102
00103 if((absX <= Rx) && (!noPix) && (absX != 0))
00104 newY = sqrt(1.0 - pow((absX / (Rx + RA)), 2));
00105 else
00106 noPix = true;
00107
00108 if(noPix)
00109 {
00110 value = src.getVal(oldPoint);
00111 result.setVal(oldPoint, value);
00112 }
00113 else
00114 {
00115 if ((x != 0) && (newX != 0))
00116 newX = absX / newX;
00117 else
00118 {
00119 value = src.getVal(oldPoint);
00120 result.setVal(oldPoint,value);
00121 stop = true;
00122 }
00123 if ((y != 0) && (newY != 0))
00124 newY = absY / newY;
00125 else
00126 {
00127 value = src.getVal(oldPoint);
00128 result.setVal(oldPoint,value);
00129 stop = true;
00130 }
00131 if (stop == false)
00132 {
00133 if (negX) newX = Xc - newX; else newX = Xc + newX;
00134 if (negY) newY = Yc - newY; else newY = Yc + newY;
00135 point.i = (int)newX; point.j = (int)newY;
00136 value = src.getVal(oldPoint);
00137
00138
00139 if (point.i < dims.w() && point.j < dims.h())
00140 {
00141
00142 if (point.i >= 0 && point.j >= 0)
00143 result.setVal(point, value);
00144 }
00145 }
00146 }
00147 }
00148 }
00149
00150 return result;
00151 }
00152
00153
00154 template <class T>
00155 Image<PixRGB<T> > omniCorrectSp(const Image<PixRGB<T> >& src,
00156 const float r,
00157 const float hh, const float kk,
00158 const int , const int ,
00159 const int Xc, const int Yc)
00160 {
00161
00162
00163
00164 Image<PixRGB<T> > result(src.getDims(), NO_INIT);
00165
00166 for(int x = 0; x < src.getWidth(); ++x)
00167 for(int y = 0; y < src.getHeight(); ++y)
00168 {
00169
00170
00171
00172 bool negX = (x < Xc);
00173 bool negY = (y < Yc);
00174
00175
00176
00177 int newX = int(-(sqrt(-pow((x - kk), 2.0) + pow(r, 2.0)) - hh));
00178 int newY = int(-(sqrt(-pow((y - kk), 2.0) + pow(r, 2.0)) - hh));
00179
00180 if (negX) newX = -newX;
00181 if (negY) newY = -newY;
00182
00183 PixRGB<T> value = src.getVal(x, y);
00184 result.setVal(newX, newY, value);
00185 }
00186
00187 return result;
00188 }
00189
00190
00191 template <class T>
00192 Image<PixRGB<T> > omniDenebulize(const Image< PixRGB<T> >& src,
00193 const int radius)
00194 {
00195 Image<PixRGB<T> > result = src;
00196
00197 for (int x = 0; x < src.getWidth(); ++x)
00198 for (int y = 0; y < src.getHeight(); ++y)
00199 {
00200 PixRGB<T> pix = src.getVal(x,y);
00201 if((pix.red() < T(1)) &&
00202
00203 (pix.green() < T(1)) &&
00204 (pix.blue() < T(1)))
00205 lowPassPixel(result, x, y, radius);
00206 }
00207
00208 return result;
00209 }
00210
00211
00212 template <class T>
00213 Image<T> omniDenebulize(const Image<T>& src, const int radius)
00214 {
00215 Image<T> result = src;
00216
00217 for (int x = 0; x < src.getWidth(); ++x)
00218 for (int y = 0; y < src.getHeight(); ++y)
00219 if (src.getVal(x, y) == T(0))
00220 lowPassPixel(result, x, y, radius);
00221
00222 return result;
00223 }
00224
00225
00226 #include "inst/Image/OmniOps.I"
00227
00228
00229
00230
00231
00232
00233
00234 #endif // !IMAGE_OMNI_C_DEFINED