ColorHist.C
Go to the documentation of this file.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 #include "Features/ColorHist.H"
00040 #include "Image/DrawOps.H"
00041 #include "Image/MathOps.H"
00042 #include "Image/Kernels.H"
00043 #include "Image/CutPaste.H"
00044 #include "Image/ColorOps.H"
00045 #include "Image/FilterOps.H"
00046 #include "Image/ShapeOps.H"
00047 #include "SIFT/FeatureVector.H"
00048
00049
00050 ColorHist::ColorHist()
00051 {
00052 }
00053
00054 ColorHist::~ColorHist()
00055 {
00056 }
00057
00058 std::vector<float> ColorHist::createFeatureVector(const Image<PixRGB<byte> >& img)
00059 {
00060
00061 if (!img.initialized())
00062 return std::vector<float>();
00063
00064 Image<float> lum,rg,by;
00065 getLAB(img, lum, rg, by);
00066
00067
00068 Image<float> kernel = gaussian<float>(0.0F, 1.4, lum.getWidth(),1.0F);
00069 Image<float> kernel2 = gaussian<float>(0.0F, 1.4, lum.getWidth(),1.0F);
00070 Image<float> kernel3 = gaussian<float>(0.0F, 1.4, lum.getWidth(),1.0F);
00071
00072 lum = sepFilter(lum, kernel, kernel, CONV_BOUNDARY_CLEAN);
00073 rg = sepFilter(rg, kernel2, kernel2, CONV_BOUNDARY_CLEAN);
00074 by = sepFilter(by, kernel3, kernel3, CONV_BOUNDARY_CLEAN);
00075
00076
00077 std::vector<float> lumFv = createFeatureVector(lum);
00078 std::vector<float> rgFv = createFeatureVector(rg);
00079 std::vector<float> byFv = createFeatureVector(by);
00080
00081 std::vector<float> fv = lumFv;
00082 fv.insert(fv.end(), rgFv.begin(), rgFv.end());
00083 fv.insert(fv.end(), byFv.begin(), byFv.end());
00084
00085 return fv;
00086
00087 }
00088
00089 std::vector<float> ColorHist::createFeatureVector(const Image<float>& img)
00090 {
00091 FeatureVector fv;
00092
00093 const int radius = std::min(img.getWidth()/2, img.getHeight()/2);
00094
00095
00096
00097 const int xi = img.getWidth()/2;
00098 const int yi = img.getHeight()/2;
00099
00100 Image<float> gradmag, gradorie;
00101 gradientSobel(img, gradmag, gradorie);
00102
00103
00104
00105
00106
00107 for (int ry = -radius; ry < radius; ry++)
00108 for (int rx = -radius; rx < radius; rx++)
00109 {
00110
00111 const float orgX = rx + float(xi);
00112 const float orgY = ry + float(yi);
00113
00114 if (! gradmag.coordsOk(orgX, orgY))
00115 continue;
00116
00117
00118
00119 const float xf = 2.0f + 2.0f * float(rx)/float(radius);
00120 const float yf = 2.0f + 2.0f * float(ry)/float(radius);
00121
00122
00123
00124 const float gaussFactor = 1;
00125 const float weightedMagnitude =
00126 gaussFactor * gradmag.getValInterp(orgX, orgY);
00127
00128
00129
00130 float gradAng = gradorie.getValInterp(orgX, orgY);
00131 gradAng=fmod(gradAng, 2*M_PI);
00132
00133
00134 if (gradAng < 0.0)
00135 gradAng += 2*M_PI;
00136 if (gradAng >= M_PI)
00137 gradAng -= 2*M_PI;
00138
00139 const float orient = (gradAng + M_PI) * 8 / (2 * M_PI);
00140
00141
00142 fv.addValue(xf, yf, orient, weightedMagnitude);
00143 }
00144
00145 return fv.getFeatureVector();
00146
00147 }
00148
00149
00150
00151
00152
00153
00154