00001 #ifndef Impala_Core_VideoSet_LabHistExtractor_h
00002 #define Impala_Core_VideoSet_LabHistExtractor_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/ElemMax.h"
00009 #include "Core/Vector/DivAssign.h"
00010
00011 namespace Impala
00012 {
00013 namespace Core
00014 {
00015 namespace VideoSet
00016 {
00017
00018 class LabHistExtractor : public HistogramExtractor
00019 {
00020
00021 public:
00022
00023 LabHistExtractor(Reporter* reporter, CmdOptions& options) :
00024 HistogramExtractor(reporter, options, "labhistogram", 3 * BINS_PER_CHANNEL)
00025 {
00026 }
00027
00028 virtual
00029 ~LabHistExtractor()
00030 {
00031 }
00032
00033 protected:
00034
00035
00036 virtual VectorReal64
00037 ComputeHistogram(Array::Array2dVec3UInt8* image)
00038 {
00039 UInt8* data = image->CPB(0, 0);
00040 const int nPix = image->CW() * image->CH();
00041
00042 VectorReal64 histogram(GetBinCount());
00043 Real64* histL = histogram.GetData();
00044 Real64* histA = histL + BINS_PER_CHANNEL;
00045 Real64* histB = histA + BINS_PER_CHANNEL;
00046
00047 for (int i = 0; i < GetBinCount(); i++)
00048 histL[i] = 0;
00049
00050 for (int j = 0; j < nPix; j++)
00051 {
00052 const Array::Element::Vec3Real64 pixel =
00053 Array::Element::Vec3Real64(data[0], data[1], data[2]);
00054 const Array::Element::Color crgb(pixel, Array::Element::RGB);
00055
00056 Array::Element::Color clab = crgb.ToLab();
00057 Array::Element::Vec3Real64 lab = clab.Value();
00058
00059
00060 int l = ComputeBin(lab.X(), 0.0, 100.0, BINS_PER_CHANNEL);
00061 histL[l] += 1;
00062
00063
00064 int a = ComputeBin(lab.Y(), -90.0, 90.0, BINS_PER_CHANNEL);
00065 histA[a] += 1;
00066
00067
00068 int b = ComputeBin(lab.Z(), -90.0, 90.0, BINS_PER_CHANNEL);
00069 histB[b] += 1;
00070
00071 data += 3;
00072 }
00073
00074 const Real64 factor = nPix;
00075 Vector::DivAssign(histogram, factor);
00076
00077 return histogram;
00078 }
00079
00080
00081 private:
00082
00083 static const int BINS_PER_CHANNEL = 32;
00084
00085 ILOG_VAR_DECL;
00086 };
00087
00088 ILOG_VAR_INIT(LabHistExtractor, Impala.Core.VideoSet);
00089
00090
00091 }
00092 }
00093 }
00094
00095 #endif