00001
00002 #ifndef _VISOPS_H_
00003 #define _VISOPS_H_
00004
00005 #include "SketchTypes.h"
00006 #include "Sketch.h"
00007 #include "SketchSpace.h"
00008
00009 #include "ShapeLine.h"
00010
00011 using namespace DualCoding;
00012 using DualCoding::uchar;
00013
00014 class DualCoding::SketchIndices;
00015
00016
00017 namespace visops {
00018
00019
00020 enum Connectivity_t { FourWayConnect, EightWayConnect };
00021
00022
00023
00024
00025
00026 Sketch<bool> zeros(SketchSpace& space);
00027
00028
00029 Sketch<bool> zeros(const SketchRoot& sketch);
00030
00031
00032 template<class T>
00033 Sketch<T> copy(const Sketch<T>& other) {
00034 Sketch<T> result("copy("+other->getName()+")", other);
00035 *result.pixels = *other.pixels;
00036 result->setColor(other->getColor());
00037 result->setColorMap(other->getColorMap());
00038 return result;
00039 }
00040
00041
00042
00043
00044
00045
00046
00047 template<class T>
00048 Sketch<T> max(const Sketch<T>& src, const T value) {
00049 Sketch<T> result("max(const)",src);
00050 for ( unsigned int i = 0; i < src.pixels->size()-1; i++ )
00051 (*result.pixels)[i] = ::max((*src.pixels)[i],value);
00052 return result;
00053 }
00054
00055
00056 template<class T>
00057 Sketch<T> max(const Sketch<T>& src, const int value) {
00058 return visops::max(src, (T)(value));
00059 }
00060
00061
00062
00063 template<class T>
00064 Sketch<T> max(const Sketch<T>& arg1, const Sketch<T>& arg2) {
00065 Sketch<T> result("max("+arg1->getName()+","+arg2->getName+")",arg1);
00066 for ( unsigned int i = 0; i < arg1.pixels->size()-1; i++ )
00067 (*result.pixels)[i] = ::max((*arg1.pixels)[i],(*arg2.pixels)[i]);
00068 return result;
00069 }
00070
00071
00072 template<class T>
00073 Sketch<T> min(const Sketch<T>& src, const T value) {
00074 Sketch<T> result("min(const)",src);
00075 for ( unsigned int i = 0; i < src.pixels->size()-1; i++ )
00076 (*result.pixels)[i] = ::min((*src.pixels)[i],value);
00077 return result;
00078 }
00079
00080
00081 template<class T>
00082 Sketch<T> min(const Sketch<T>& src, const int value) {
00083 return visops::min(src, (T)(value));
00084 }
00085
00086
00087 template<class T>
00088 Sketch<T> min(const Sketch<T>& arg1, const Sketch<T>& arg2) {
00089 Sketch<T> result("min("+arg1->getName()+","+arg2->getName+")",arg1);
00090 for ( unsigned int i = 0; i < arg1.pixels->size()-1; i++ )
00091 (*result.pixels)[i] = ::min((*arg1.pixels)[i],(*arg2.pixels)[i]);
00092 return result;
00093 }
00094
00095
00096
00097
00098
00099
00100
00101 Sketch<bool> colormask(const Sketch<uchar>& src, const std::string colorname);
00102
00103
00104 Sketch<bool> colormask(const Sketch<uchar>& src, int color_idx);
00105
00106
00107 Sketch<bool> seedfill(const Sketch<bool>& borders, size_t index);
00108
00109
00110
00111
00112 Sketch<uchar> neighborSum(const Sketch<bool> &im, Connectivity_t connectivity=EightWayConnect);
00113
00114
00115
00116
00117
00118
00119
00120 Sketch<bool> fillin(const Sketch<bool> &im, int iter,
00121 uchar min_thresh, uchar max_thresh,
00122 bool remove_only=false);
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132 Sketch<usint> bdist(const Sketch<bool> &dest, const Sketch<bool> &obst,
00133 const int maxdist=100);
00134
00135
00136
00137
00138
00139
00140 Sketch<usint> edist(const Sketch<bool> &dest);
00141
00142
00143 Sketch<usint> labelcc(const Sketch<bool>& source, int minarea=1);
00144
00145
00146
00147
00148
00149 Sketch<usint> oldlabelcc(const Sketch<bool>& source,
00150 Connectivity_t connectivity=EightWayConnect);
00151
00152
00153 Sketch<usint> areacc(const Sketch<bool>& source, Connectivity_t connectivity=EightWayConnect);
00154
00155
00156 Sketch<usint> areacc(const Sketch<usint>& labels);
00157
00158
00159 Sketch<bool> minArea(const Sketch<bool>& sketch, int minval=5);
00160
00161
00162
00163
00164
00165
00166
00167 template<typename T>
00168 Sketch<T> ifNot(const Sketch<T> &A, const Sketch<T> &B) {
00169 Sketch<T> result("ifNot("+A->getName()+","+B->getName()+")", A);
00170 T* Aptr = &(*A.pixels)[0];
00171 T* Bptr = &(*B.pixels)[0];
00172 T* Rptr = &(*result.pixels)[0];
00173 T* Rend = &(*result.pixels)[result->getNumPixels()];
00174 while ( Rptr != Rend ) {
00175 *Rptr++ = ( *Aptr != 0 ) ? *Aptr : * Bptr;
00176 *Aptr++; Bptr++;
00177 }
00178 return result;
00179 }
00180
00181
00182 template<typename T, typename Tv>
00183 Sketch<T> maskedAssign(const Sketch<T> &sketch, const Sketch<bool> &mask, const Tv value) {
00184 Sketch<T> result("maskedAssign("+sketch->getName()+")",sketch);
00185 T* Psrc = &(*sketch.pixels)[0];
00186 T* Pdest = &(*result.pixels)[0];
00187 T* Edest = &(*result.pixels)[sketch->getNumPixels()];
00188 bool* Pmask =&(*mask.pixels)[0];
00189 const T val = (T)value;
00190 while ( Pdest != Edest ) {
00191 *Pdest++ = *Pmask++ ? val : *Psrc;
00192 Psrc++;
00193 }
00194 return result;
00195 }
00196
00197
00198 template<typename T>
00199 Sketch<T> maskedAssign(const Sketch<T> &sketch, const Sketch<bool> &mask, const Sketch<T> &value) {
00200 Sketch<T> result("maskedAssign("+sketch->getName()+")",sketch);
00201 T* Psrc = &(*sketch.pixels)[0];
00202 T* Pdest = &(*result.pixels)[0];
00203 T* Edest = &(*result.pixels)[sketch->getNumPixels()];
00204 bool* Pmask = &(*mask.pixels)[0];
00205 T* Pval = &(*value.pixels)[0];
00206 while ( Pdest != Edest ) {
00207 *Pdest++ = *Pmask++ ? *Pval : *Psrc;
00208 Pval++;
00209 Psrc++;
00210 }
00211 return result;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221 Sketch<bool> edge(const Sketch<bool> &im);
00222
00223
00224
00225
00226
00227
00228
00229 Sketch<bool> horsym(const Sketch<bool>& sketch,
00230 int minskip=3, int maxskip=80);
00231
00232
00233
00234
00235
00236
00237
00238 Sketch<bool> versym(const Sketch<bool>& sketch,
00239 int minskip=3, int maxskip=80);
00240
00241
00242
00243 Sketch<bool> skel(const Sketch<bool>& sketch);
00244
00245
00246
00247
00248
00249
00250
00251 Sketch<bool> leftHalfPlane(const Shape<LineData> &ln);
00252
00253 Sketch<bool> rightHalfPlane(const Shape<LineData> &ln);
00254
00255 Sketch<bool> topHalfPlane(const Shape<LineData> &ln);
00256
00257 Sketch<bool> bottomHalfPlane(const Shape<LineData> &ln);
00258
00259
00260 Sketch<bool> non_bounds(const Sketch<bool>& im, int offset);
00261
00262
00263
00264
00265
00266 Sketch<uchar> susan_edges(const Sketch<uchar>& im, int brightness);
00267
00268
00269 Sketch<bool> susan_edge_points(const Sketch<uchar>& im, int brightness);
00270
00271
00272 Sketch<usint> convolve(const Sketch<uchar> &sketch, Sketch<uchar> &kernel,
00273 int i, int j, int width, int height);
00274
00275
00276 Sketch<usint> templateMatch(const Sketch<uchar> &sketch, Sketch<uchar> &kernel,
00277 int i, int j, int width, int height);
00278
00279
00280
00281 }
00282
00283 #endif