2 #ifndef vil_sobel_3x3_hxx_ 3 #define vil_sobel_3x3_hxx_ 14 template<
class srcT,
class destT>
22 for (
int p=0;p<np;++p)
34 template<
class srcT,
class destT>
44 for (
int p=0;p<np;++p)
56 template<
class srcT,
class destT>
58 std::ptrdiff_t s_istep, std::ptrdiff_t s_jstep,
59 destT* gi, std::ptrdiff_t gi_istep, std::ptrdiff_t gi_jstep,
60 destT* gj, std::ptrdiff_t gj_istep, std::ptrdiff_t gj_jstep,
61 unsigned ni,
unsigned nj)
63 const destT k125=static_cast<destT>(0.125);
64 const destT k25=static_cast<destT>(0.25);
65 const destT zero=static_cast<destT>(0.0);
67 const srcT* s_data = src;
71 if (ni==0 || nj==0)
return;
75 for (
unsigned j=0;j<nj;++j)
87 for (
unsigned i=0;i<ni;++i)
101 const std::ptrdiff_t o1 = s_jstep - s_istep;
102 const std::ptrdiff_t o2 = s_jstep;
103 const std::ptrdiff_t o3 = s_istep + s_jstep;
104 const std::ptrdiff_t o4 = -s_istep;
105 const std::ptrdiff_t o5 = s_istep;
106 const std::ptrdiff_t o6 = -s_istep - s_jstep;
107 const std::ptrdiff_t o7 = -s_jstep;
108 const std::ptrdiff_t o8 = s_istep - s_jstep;
110 const unsigned ni1 = ni-1;
111 const unsigned nj1 = nj-1;
113 s_data += s_istep + s_jstep;
117 for (
unsigned j=1;j<nj1;++j)
119 const srcT* s = s_data;
120 destT* pgi = gi_data;
121 destT* pgj = gj_data;
124 *pgi = 0; pgi+=gi_istep;
125 *pgj = 0; pgj+=gj_istep;
127 for (
unsigned i=1;i<ni1;++i)
132 *pgi = ( k125*static_cast<destT>(s[o3]) + k25*static_cast<destT>(s[o5]) + k125*static_cast<destT>(s[o8]) )
133 - ( k125*static_cast<destT>(s[o1]) + k25*static_cast<destT>(s[o4]) + k125*static_cast<destT>(s[o6]) );
135 *pgj = ( k125*static_cast<destT>(s[o1]) + k25*static_cast<destT>(s[o2]) + k125*static_cast<destT>(s[o3]) )
136 - ( k125*static_cast<destT>(s[o6]) + k25*static_cast<destT>(s[o7]) + k125*static_cast<destT>(s[o8]) );
154 for (
unsigned i=0;i<ni;++i)
156 *gi=zero; gi+=gi_istep;
157 *gj=zero; gj+=gj_istep;
158 *gi_data = zero; gi_data+=gi_istep;
159 *gj_data = zero; gj_data+=gj_istep;
164 #undef VIL_SOBEL_3X3_INSTANTIATE 165 #define VIL_SOBEL_3X3_INSTANTIATE(srcT, destT) \ 166 template void vil_sobel_3x3(const vil_image_view< srcT >& src, \ 167 vil_image_view<destT >& grad_ij); \ 168 template void vil_sobel_3x3(const vil_image_view< srcT >& src, \ 169 vil_image_view<destT >& grad_i, \ 170 vil_image_view<destT >& grad_j) 172 #endif // vil_sobel_3x3_hxx_ Concrete view of image data of type T held in memory.
void vil_sobel_3x3_1plane(const srcT *src, std::ptrdiff_t s_istep, std::ptrdiff_t s_jstep, destT *gi, std::ptrdiff_t gi_istep, std::ptrdiff_t gi_jstep, destT *gj, std::ptrdiff_t gj_istep, std::ptrdiff_t gj_jstep, unsigned ni, unsigned nj)
run Sobel 3x3 gradient filter on a single plane of an image.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
void vil_sobel_3x3(const vil_image_view< srcT > &src, vil_image_view< destT > &grad_i, vil_image_view< destT > &grad_j)
Compute gradients of an image using 3x3 Sobel filters.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
Apply 3x3 sobel operator to image data.