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 #include "SpaceVariant/SpaceVariantModule.H"
00037 #include "SpaceVariant/SVChanLevels.H"
00038 #include "Image/CutPaste.H"
00039 #include "Image/ImageSet.H"
00040
00041
00042
00043
00044
00045
00046 SpaceVariantModule::SpaceVariantModule(OptionManager& mgr, const std::string& descrName, const std::string& tagName) :
00047 ModelComponent(mgr, descrName, tagName),
00048 itsTransform(),
00049 itsMapTransform()
00050 { }
00051
00052
00053 SpaceVariantModule::~SpaceVariantModule()
00054 { }
00055
00056
00057 void SpaceVariantModule::clear(const Dims& input_dims)
00058 {
00059 }
00060
00061
00062 void SpaceVariantModule::clear()
00063 {
00064 itsTransform.reset();
00065 itsMapTransform.reset();
00066 }
00067
00068
00069 void SpaceVariantModule::reset1()
00070 {
00071 clear();
00072 }
00073
00074
00075 Image<PixRGB<float> > SpaceVariantModule::transformRbg(const Image<PixRGB<byte> >& image,
00076 const ImageSet<PixRGB<float> >* const pyr_cache)
00077 {
00078 return this->transform(image, pyr_cache);
00079 }
00080
00081
00082 void SpaceVariantModule::transformRgbPyramid(const Image<PixRGB<byte> >& image, ImageSet<PixRGB<float> >& pyramid, const SVChanLevels& levels, const ImageSet<PixRGB<float> >* const pyr_cache)
00083 {
00084 return this->transformPyramid(image, pyramid, levels, pyr_cache);
00085 }
00086
00087
00088 Image<float> SpaceVariantModule::transformFloat(const Image<float>& image, const ImageSet<float>* const pyr_cache)
00089 {
00090 return this->transform(image, pyr_cache);
00091 }
00092
00093
00094 void SpaceVariantModule::transformFloatPyramid(const Image<float>& image, ImageSet<float>& pyramid, const SVChanLevels& levels, const ImageSet<float>* const pyr_cache)
00095 {
00096 return this->transformPyramid(image, pyramid, levels, pyr_cache);
00097 }
00098
00099
00100 template <class T_or_RGB>
00101 ImageSet<T_or_RGB> SpaceVariantModule::getScaleSpace(const Image<T_or_RGB>& inp, const float& maxrf)
00102 {
00103 ImageSet<T_or_RGB> set;
00104 if (inp.initialized())
00105 {
00106
00107 if (!validTransforms())
00108 clear(inp.getDims());
00109 else if (inp.getDims() != itsTransform->getCTDims())
00110 clear(inp.getDims());
00111
00112 set = (maxrf < 0.0)
00113 ? ::getScaleSpace(inp, itsTransform->getMaxRFSize())
00114 : ::getScaleSpace(inp, maxrf);
00115 }
00116 return set;
00117 }
00118
00119
00120 template <class T_or_RGB>
00121 Image<T_or_RGB> SpaceVariantModule::transform(const Image<T_or_RGB>& ret_image, const ImageSet<typename promote_trait<T_or_RGB, float>::TP>* const pyr_cache)
00122 {
00123 Image<T_or_RGB> output;
00124 if (ret_image.initialized())
00125 {
00126
00127 if (!validTransforms())
00128 clear(ret_image.getDims());
00129 else if (ret_image.getDims() != itsTransform->getCTDims())
00130 clear(ret_image.getDims());
00131
00132
00133 output = transformTo(*itsTransform, ret_image, pyr_cache);
00134 }
00135 return output;
00136 }
00137
00138
00139 template <class T_or_RGB>
00140 void SpaceVariantModule::transformPyramid(const Image<T_or_RGB>& ret_image, ImageSet<typename promote_trait<T_or_RGB, float>::TP>& pyramid, const SVChanLevels& levels, const ImageSet<typename promote_trait<T_or_RGB, float>::TP>* const pyr_cache)
00141 {
00142 if (ret_image.initialized())
00143 {
00144
00145 if (!validTransforms())
00146 clear(ret_image.getDims());
00147 else if (ret_image.getDims() != itsTransform->getCTDims())
00148 clear(ret_image.getDims());
00149
00150 pyramid = ImageSet<typename promote_trait<T_or_RGB, float>::TP>(levels.numLevels());
00151 for (uint ii = 0; ii < levels.numLevels(); ++ii)
00152 pyramid[ii] = transformTo(*itsTransform, ret_image, pyr_cache, levels.getVariance(ii));
00153 }
00154 }
00155
00156
00157 template <class T_or_RGB>
00158 Image<T_or_RGB> SpaceVariantModule::transform(const Image<T_or_RGB>& ret_image, const Point2D<int>& fovea, const ImageSet<typename promote_trait<T_or_RGB, float>::TP>* const pyr_cache)
00159 {
00160 const int i = ret_image.getWidth() / 2 - fovea.i;
00161 const int j = ret_image.getHeight() / 2 - fovea.j;
00162 const Image<T_or_RGB> shifted_image = shiftClean(ret_image, i, j);
00163
00164 return this->transform(shifted_image, pyr_cache);
00165 }
00166
00167
00168 template <class T_or_RGB>
00169 Image<T_or_RGB> SpaceVariantModule::cropTransform(const Image<T_or_RGB>& ret_image, const Point2D<int>& fovea, const Dims& dims, const ImageSet<typename promote_trait<T_or_RGB, float>::TP>* const pyr_cache)
00170 {
00171 if ((dims.w() < ret_image.getWidth()) && (dims.h() < ret_image.getHeight()))
00172 {
00173 const int i = ret_image.getWidth() / 2 - fovea.i;
00174 const int j = ret_image.getHeight() / 2 - fovea.j;
00175 Point2D<int> c((ret_image.getWidth() - dims.w())/2, (ret_image.getHeight() - dims.h())/2);
00176 const Image<T_or_RGB> shifted_image = shiftClean(ret_image, i, j);
00177 return this->transform(crop(shifted_image, c, dims, false), pyr_cache);
00178 }
00179 else
00180 return this->transform(ret_image, fovea, pyr_cache);
00181 }
00182
00183
00184 template <class T_or_RGB>
00185 Image<T_or_RGB> SpaceVariantModule::inverseTransform(const Image<T_or_RGB>& ret_image) const
00186 {
00187 Image<T_or_RGB> ret;
00188 if (itsTransform.is_valid() && (ret_image.getDims() == itsTransform->getSVDims()))
00189 ret = transformFrom(*itsTransform, ret_image);
00190 return ret;
00191 }
00192
00193
00194 template <class T_or_RGB>
00195 Image<T_or_RGB> SpaceVariantModule::inverseMap(const Image<T_or_RGB>& map_image) const
00196 {
00197 Image<T_or_RGB> ret;
00198 if (itsMapTransform.is_valid() && (map_image.getDims() == itsMapTransform->getSVDims()))
00199 ret = transformFrom(*itsMapTransform, map_image);
00200 return ret;
00201 }
00202
00203
00204 void SpaceVariantModule::toSvCoords(Point2D<int>& point) const
00205 {
00206 if (itsTransform.is_valid())
00207 itsTransform->to(point.i, point.j, point.i, point.j);
00208 }
00209
00210
00211 void SpaceVariantModule::fromSvCoords(Point2D<int>& point) const
00212 {
00213 if (itsTransform.is_valid())
00214 itsTransform->from(point.i, point.j, point.i, point.j);
00215 }
00216
00217
00218 void SpaceVariantModule::toSvCoordsMap(Point2D<int>& point) const
00219 {
00220 if (itsMapTransform.is_valid())
00221 itsMapTransform->to(point.i, point.j, point.i, point.j);
00222 }
00223
00224
00225 void SpaceVariantModule::fromSvCoordsMap(Point2D<int>& point) const
00226 {
00227 if (itsMapTransform.is_valid())
00228 itsMapTransform->from(point.i, point.j, point.i, point.j);
00229 }
00230
00231
00232 bool SpaceVariantModule::validTransforms() const
00233 {
00234 return (itsTransform.is_valid() && itsMapTransform.is_valid());
00235 }
00236
00237
00238 rutz::shared_ptr<SpaceVariantTransform> SpaceVariantModule::getTransform()
00239 {
00240 return itsTransform;
00241 }
00242
00243
00244 rutz::shared_ptr<SpaceVariantTransform> SpaceVariantModule::getMapTransform()
00245 {
00246 return itsMapTransform;
00247 }
00248
00249
00250 void SpaceVariantModule::setTransform(rutz::shared_ptr<SpaceVariantTransform> transform)
00251 {
00252 itsTransform = transform;
00253 }
00254
00255
00256 void SpaceVariantModule::setMapTransform(rutz::shared_ptr<SpaceVariantTransform> map_transform)
00257 {
00258 itsMapTransform = map_transform;
00259 }
00260
00261
00262 float SpaceVariantModule::getMaxRf() const
00263 {
00264 return itsTransform->getMaxRFSize();
00265 }
00266
00267
00268 float SpaceVariantModule::getMaxRf(const float& offset, const float& surround_factor)
00269 {
00270 return (itsTransform->getMaxRFSize() + offset) * surround_factor;
00271 }
00272
00273 #define INST_CLASS SpaceVariantModule::
00274 #include "inst/SpaceVariant/SpaceVariantModule.I"
00275
00276
00277
00278
00279