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 STEREOCHANNEL_C_DEFINED
00039 #define STEREOCHANNEL_C_DEFINED
00040
00041 #include "Channels/StereoChannel.H"
00042
00043 #include "Channels/ChannelOpts.H"
00044 #include "Channels/DisparityChannel.H"
00045 #include "Component/OptionManager.H"
00046 #include "Image/CutPaste.H"
00047 #include "Image/FilterOps.H"
00048 #include "Image/Kernels.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/PyramidOps.H"
00051
00052
00053
00054
00055
00056
00057 const uint StereoChannel::nPhase;
00058 const uint StereoChannel::nTheta;
00059 const float StereoChannel::dPhase;
00060 const float StereoChannel::dTheta;
00061 const float StereoChannel::stddev;
00062 const float StereoChannel::period;
00063
00064
00065
00066 StereoChannel::StereoChannel(OptionManager& mgr) :
00067 ComplexChannel(mgr, "Stereo", "stereo", STEREO),
00068 itsPyrType("StereoChannelPyramidType", this, Gaussian3),
00069 itsNumTheta(&OPT_NumTheta, this),
00070 itsNumPhase("NumPhase", this, nPhase/2 + 1)
00071 {
00072 fImgL = NULL; fImgR = NULL;
00073
00074
00075
00076 buildSubChans();
00077 }
00078
00079
00080 StereoChannel::~StereoChannel()
00081 { }
00082
00083
00084 void StereoChannel::start1()
00085 {
00086
00087
00088 itsDepth = dispChan(0,0).getLevelSpec().maxDepth();
00089
00090
00091 createPhasedGaborPyramids();
00092 }
00093
00094
00095 DisparityChannel& StereoChannel::dispChan(const uint idO,
00096 const uint idP) const
00097 {
00098 uint idx= idO * itsNumPhase.getVal() + idP;
00099 return *(dynCast<DisparityChannel>(this->subChan(idx)));
00100 }
00101
00102
00103 void StereoChannel::buildSubChans()
00104 {
00105
00106 this->removeAllSubChans();
00107
00108
00109
00110
00111
00112 LINFO("Using %d orientations spanning [0..180]deg and %d phase spanning [0..360]deg",
00113 itsNumTheta.getVal(), itsNumPhase.getVal());
00114
00115 double theta;
00116 double phase;
00117
00118 for (uint i = 0; i < itsNumTheta.getVal(); i ++)
00119 for (uint j = 0; j < itsNumPhase.getVal(); j ++)
00120 {
00121 theta = 180.0 * double(i) / double(itsNumTheta.getVal());
00122
00123
00124
00125 if(j <= itsNumPhase.getVal()/2)
00126 phase = 90.0 * double(j) / double(itsNumPhase.getVal()/2);
00127
00128 else
00129 phase = 90.0 * double(j-1) / double(itsNumPhase.getVal()/2) +
00130 180.0;
00131
00132 addSubChan(makeSharedComp
00133 (new DisparityChannel(getManager(),
00134 i*itsNumPhase.getVal()
00135 +j,theta,phase )));
00136
00137 dispChan(i,j).setNumTheta(nTheta);
00138 dispChan(i,j).setNumPhase(nPhase);
00139
00140 }
00141
00142
00143
00144
00145
00146 ModelComponent::exportOptions(MC_RECURSE);
00147 }
00148
00149
00150 void StereoChannel::createPhasedGaborPyramids()
00151 {
00152
00153 if(fImgL != NULL || fImgR != NULL)
00154 {
00155 for(uint i = 0; i < itsDepth; i++)
00156 {
00157 for(uint j = 0; j < nTheta; j++)
00158 {
00159 delete(fImgL[i][j]);
00160 delete(fImgR[i][j]);
00161 }
00162 }
00163
00164 for(uint i = 0; i < itsDepth; i++)
00165 {
00166 delete(fImgL[i]);
00167 delete(fImgR[i]);
00168 }
00169
00170 delete(fImgL);
00171 delete(fImgR);
00172 }
00173
00174 fImgL = new Image<float>**[itsDepth];
00175 fImgR = new Image<float>**[itsDepth];
00176
00177 for(uint i = 0; i < itsDepth; i++)
00178 {
00179 fImgL[i] = new Image<float>*[nTheta];
00180 fImgR[i] = new Image<float>*[nTheta];
00181 }
00182
00183 for(uint i = 0; i < itsDepth; i++)
00184 {
00185 for(uint j = 0; j < nTheta; j++)
00186 {
00187 fImgL[i][j] = new Image<float>[nPhase];
00188 fImgR[i][j] = new Image<float>[nPhase];
00189 }
00190 }
00191 }
00192
00193
00194 void StereoChannel::paramChanged(ModelParamBase* const param,
00195 const bool valueChanged,
00196 ParamClient::ChangeStatus* status)
00197 {
00198 ComplexChannel::paramChanged(param, valueChanged, status);
00199
00200
00201
00202
00203 if (param == &itsNumTheta &&
00204
00205 numChans() != itsNumPhase.getVal() * itsNumTheta.getVal())
00206 buildSubChans();
00207 }
00208
00209
00210 void StereoChannel::doInput(const InputFrame& inframe)
00211 {
00212 ASSERT(inframe.grayFloat().initialized());
00213
00214 imgL = inframe.grayFloat();
00215
00216
00217
00218
00219
00220 pyrL = buildPyrGaussian(imgL, 0, itsDepth, 5);
00221 pyrR = buildPyrGaussian(imgR, 0, itsDepth, 5);
00222
00223
00224 applyGabor();
00225
00226
00227 ImageSet<float> tDispMap(itsDepth);
00228 ImageSet<float> tempDM;
00229
00230 for(uint d = 0; d < itsDepth; d++)
00231 {
00232 tDispMap[d].resize(pyrL[d].getWidth(),pyrL[d].getHeight(),true);
00233
00234 }
00235
00236
00237
00238 for (uint i = 0; i < itsNumTheta.getVal(); i ++)
00239 for (uint j = 0; j < itsNumPhase.getVal(); j ++)
00240 {
00241 dispChan(i,j).setRawFilteredImages(fImgL,fImgR);
00242 dispChan(i,j).doInput(inframe);
00243
00244
00245
00246
00247
00248
00249
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 }
00265
00266
00267 void StereoChannel::setSecondImage(const Image<float>* bwimg)
00268 {
00269 imgR = *bwimg;
00270 }
00271
00272
00273 void StereoChannel::getRawFilteredImages(Image<float> ****fImgLE,
00274 Image<float> ****fImgRI)
00275 {
00276 *fImgLE = fImgL;
00277 *fImgRI = fImgR;
00278 }
00279
00280
00281 void StereoChannel::applyGabor()
00282 {
00283 Image<float> gaborF;Image<float> gF;
00284 Point2D<int> a(3,3); Dims b(5,5);
00285 for(uint d = 0; d < itsDepth; d++)
00286 {
00287 for(uint t = 0; t < nTheta; t++)
00288 {
00289 for(uint p = 0; p < nPhase; p++)
00290 {
00291 gaborF = gaborFilter<float>(stddev,period,p*dPhase,t*dTheta);
00292 ASSERT(gaborF.getWidth() == 11 && gaborF.getHeight() == 11);
00293 gaborF = crop(gaborF,a,b,false);
00294
00295 fImgL[d][t][p] = convolve(pyrL[d],gaborF,CONV_BOUNDARY_ZERO);
00296
00297 fImgR[d][t][p] = convolve(pyrR[d],gaborF,CONV_BOUNDARY_ZERO);
00298
00299 }
00300 }
00301 }
00302 }
00303
00304
00305
00306
00307
00308
00309
00310 #endif // STEREOCHANNEL_C_DEFINED