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 #ifndef COLORCHANNEL_C_DEFINED
00039 #define COLORCHANNEL_C_DEFINED
00040
00041 #include "Channels/ColorChannel.H"
00042
00043 #include "Channels/BlueYellowChannel.H"
00044 #include "Channels/YellowBlueChannel.H"
00045 #include "Channels/ChannelOpts.H"
00046 #include "Channels/RedGreenChannel.H"
00047 #include "Channels/GreenRedChannel.H"
00048 #include "Component/OptionManager.H"
00049 #include "Image/ColorOps.H"
00050 #include "rutz/trace.h"
00051
00052
00053
00054
00055
00056 ColorChannel::ColorChannel(OptionManager& mgr) :
00057 ComplexChannel(mgr, "Color", "color", COLOR),
00058 itsLumThresh("ColorChannelLuminanceThreshold", this, 25.5F),
00059 itsMethod(&OPT_ColorComputeType, this)
00060 {
00061 GVX_TRACE(__PRETTY_FUNCTION__);
00062
00063 itsRG = nub::soft_ref<RedGreenChannel>(new RedGreenChannel(getManager(), true));
00064 itsBY = nub::soft_ref<BlueYellowChannel>(new BlueYellowChannel(getManager(), true));
00065
00066 this->addSubChan(itsRG);
00067 this->addSubChan(itsBY);
00068 }
00069
00070
00071 void ColorChannel::paramChanged(ModelParamBase* const param,
00072 const bool valueChanged,
00073 ParamClient::ChangeStatus* status)
00074 {
00075 ComplexChannel::paramChanged(param, valueChanged, status);
00076
00077
00078
00079 if (param == &itsMethod && valueChanged)
00080 {
00081 switch(itsMethod.getVal())
00082 {
00083 case COLstandardFull:
00084 {
00085 LINFO("Rebuilding Color Channels");
00086
00087 this->removeAllSubChans();
00088
00089
00090 itsRG = nub::soft_ref<RedGreenChannel>(new RedGreenChannel(getManager(), false));
00091 itsGR = nub::soft_ref<GreenRedChannel>(new GreenRedChannel(getManager(), false));
00092 itsBY = nub::soft_ref<BlueYellowChannel>(new BlueYellowChannel(getManager(), false));
00093 itsYB = nub::soft_ref<YellowBlueChannel>(new YellowBlueChannel(getManager(), false));
00094
00095 this->addSubChan(itsRG);
00096 this->addSubChan(itsGR);
00097 this->addSubChan(itsBY);
00098 this->addSubChan(itsYB);
00099 }
00100 default:
00101 break;
00102 }
00103
00104 }
00105
00106 }
00107
00108
00109 RedGreenChannel& ColorChannel::rg() const
00110 {
00111 GVX_TRACE(__PRETTY_FUNCTION__);
00112 return *itsRG;
00113 }
00114
00115
00116 BlueYellowChannel& ColorChannel::by() const
00117 {
00118 GVX_TRACE(__PRETTY_FUNCTION__);
00119 return *itsBY;
00120 }
00121
00122
00123 GreenRedChannel& ColorChannel::gr() const
00124 {
00125 GVX_TRACE(__PRETTY_FUNCTION__);
00126 return *itsGR;
00127 }
00128
00129
00130 YellowBlueChannel& ColorChannel::yb() const
00131 {
00132 GVX_TRACE(__PRETTY_FUNCTION__);
00133 return *itsYB;
00134 }
00135
00136
00137 ColorChannel::~ColorChannel()
00138 {
00139 GVX_TRACE(__PRETTY_FUNCTION__);
00140 }
00141
00142
00143 void ColorChannel::doInput(const InputFrame& inframe)
00144 {
00145 GVX_TRACE(__PRETTY_FUNCTION__);
00146 Image<float> rgimg, byimg;
00147
00148 switch(itsMethod.getVal())
00149 {
00150 case COLstandard:
00151 ASSERT(inframe.colorByte().initialized());
00152 LINFO("Using 'standard' method to compute color opponencies.");
00153 getRGBY(inframe.colorByte(), rgimg, byimg, itsLumThresh.getVal());
00154 break;
00155
00156 case COLstandardFull:
00157 {
00158 ASSERT(inframe.colorFloat().initialized());
00159
00160 LINFO("Using 'standard Full' method to compute color opponencies.");
00161 Image<float> grimg, ybimg;
00162 Image<float> r,g,b,y;
00163 getRGBY(inframe.colorFloat(), r, g, b, y, itsLumThresh.getVal());
00164 rgimg = r-g; grimg = g - r;
00165 byimg = b-y; ybimg = y - b;
00166 itsGR->input(InputFrame::fromGrayFloat
00167 (&grimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00168 itsYB->input(InputFrame::fromGrayFloat
00169 (&ybimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00170 }
00171 break;
00172
00173 case COLsimple:
00174 ASSERT(inframe.colorByte().initialized());
00175 LINFO("Using 'simple' method to compute color opponencies.");
00176 getRGBYsimple(inframe.colorByte(), rgimg, byimg, itsLumThresh.getVal());
00177 break;
00178
00179 default:
00180 LFATAL("Unknown ColorComputeType!");
00181 break;
00182 }
00183
00184
00185 itsRG->input(InputFrame::fromGrayFloat(&rgimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00186 itsBY->input(InputFrame::fromGrayFloat(&byimg, inframe.time(), &inframe.clipMask(), inframe.pyrCache()));
00187 LINFO("Double Opponent Color channel ok.");
00188 }
00189
00190
00191 void ColorChannel::setRG(nub::ref<RedGreenChannel> rg)
00192 {
00193 this->removeSubChan(itsRG);
00194 itsRG = rg;
00195 this->addSubChan(itsRG);
00196 }
00197
00198
00199 void ColorChannel::setBY(nub::ref<BlueYellowChannel> by)
00200 {
00201 this->removeSubChan(itsBY);
00202 itsBY = by;
00203 this->addSubChan(itsBY);
00204 }
00205
00206
00207 void ColorChannel::setGR(nub::ref<GreenRedChannel> gr)
00208 {
00209 this->removeSubChan(itsGR);
00210 itsGR = gr;
00211 this->addSubChan(itsGR);
00212 }
00213
00214
00215 void ColorChannel::setYB(nub::ref<YellowBlueChannel> yb)
00216 {
00217 this->removeSubChan(itsYB);
00218 itsYB = yb;
00219 this->addSubChan(itsYB);
00220 }
00221
00222
00223
00224
00225
00226
00227
00228 #endif // COLORCHANNEL_C_DEFINED