Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

LabHist3dExtractor.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_VideoSet_LabHist3dExtractor_h
00002 #define Impala_Core_VideoSet_LabHist3dExtractor_h
00003 
00004 #include "Core/VideoSet/HistogramExtractor.h"
00005 
00006 #include "Core/Array/Element/Vec3Real64.h"
00007 #include "Core/Array/Element/Color.h"
00008 #include "Core/Vector/DivAssign.h"
00009 
00010 namespace Impala
00011 {
00012 namespace Core
00013 {
00014 namespace VideoSet
00015 {
00016 
00017 class LabHist3dExtractor : public HistogramExtractor
00018 {
00019 
00020 protected:
00021 
00022     typedef Vector::VectorTem<Array::Array2dScalarReal64> Array3dReal64;
00023 
00024 public:
00025 
00026     LabHist3dExtractor(Reporter* reporter, CmdOptions& options) :
00027       HistogramExtractor(reporter, options, "labhistogram3d", 
00028           BINS_FOR_L * BINS_FOR_A_B * BINS_FOR_A_B)
00029     {
00030     }
00031 
00032     virtual 
00033     ~LabHist3dExtractor()
00034     {
00035     }
00036 
00037 protected:
00038 
00039     // Lab histogram computation - maintaining L-a-b relation information 
00040     // using a 3D array.
00041     virtual VectorReal64
00042     ComputeHistogram(Array::Array2dVec3UInt8* image)
00043     {
00044         const UInt8* data = image->CPB(0, 0);
00045         const int nPix = image->CW() * image->CH();
00046 
00047         VectorReal64 histogram(GetBinCount());
00048         Real64* const histData = histogram.GetData();
00049         for (int i = 0; i < GetBinCount(); i++)
00050             histData[i] = 0;
00051 
00052         for (int j = 0; j < nPix; j++) 
00053         {
00054             const Array::Element::Vec3Real64 pixel = 
00055                 Array::Element::Vec3Real64(data[0], data[1], data[2]);
00056             const Array::Element::Color crgb(pixel, Array::Element::RGB);
00057 
00058             Array::Element::Color clab = crgb.ToLab();
00059             Array::Element::Vec3Real64 lab = clab.Value();
00060 
00061             int l = ComputeBin(lab.X(), 0.0, 100.0, BINS_FOR_L);
00062             int a = ComputeBin(lab.Y(), -90.0, 90.0, BINS_FOR_A_B);
00063             int b = ComputeBin(lab.Z(), -90.0, 90.0, BINS_FOR_A_B);
00064 
00065             int offset = 
00066                 (l * BINS_FOR_A_B * BINS_FOR_A_B) + (a * BINS_FOR_A_B) + b;
00067             histData[offset] += 1;
00068 
00069             data += 3;
00070         }
00071 
00072         const Real64 factor = nPix;
00073         Vector::DivAssign(histogram, factor);
00074         return histogram;
00075     }
00076 
00077 private:
00078 
00079     static const int BINS_FOR_L = 6;
00080     static const int BINS_FOR_A_B = 5;
00081 
00082     ILOG_VAR_DECL;
00083 };
00084 
00085 ILOG_VAR_INIT(LabHist3dExtractor, Impala.Core.VideoSet);
00086 
00087 } // namespace VideoSet
00088 } // namespace Core
00089 } // namespace Impala
00090 
00091 #endif

Generated on Fri Mar 19 09:31:30 2010 for ImpalaSrc by  doxygen 1.5.1