2 #ifndef vil_sobel_1x3_hxx_ 3 #define vil_sobel_1x3_hxx_ 14 template<
class srcT,
class destT>
19 unsigned ni = src.
ni();
20 unsigned nj = src.
nj();
22 for (
unsigned p=0;p<np;++p)
34 template<
class srcT,
class destT>
40 unsigned ni = src.
ni();
41 unsigned nj = src.
nj();
44 for (
unsigned p=0;p<np;++p)
55 template<
class srcT,
class destT>
57 std::ptrdiff_t s_istep, std::ptrdiff_t s_jstep,
58 destT* gi, std::ptrdiff_t gi_istep, std::ptrdiff_t gi_jstep,
59 destT* gj, std::ptrdiff_t gj_istep, std::ptrdiff_t gj_jstep,
60 unsigned ni,
unsigned nj)
62 const destT point5=static_cast<destT>(0.5);
63 const destT zero=static_cast<destT>(0.0);
65 const srcT* s_data = src;
69 if (ni==0 || nj==0)
return;
73 for (
unsigned j=0;j<nj;++j)
85 for (
unsigned i=0;i<ni;++i)
99 const std::ptrdiff_t o2 = s_jstep;
100 const std::ptrdiff_t o4 = -s_istep;
101 const std::ptrdiff_t o5 = s_istep;
102 const std::ptrdiff_t o7 = -s_jstep;
104 const unsigned ni1 = ni-1;
105 const unsigned nj1 = nj-1;
107 s_data += s_istep + s_jstep;
110 for (
unsigned j=1;j<nj1;++j)
112 const srcT* s = s_data;
113 destT* pgi = gi_data;
114 destT* pgj = gj_data;
117 *pgi = zero; pgi+=gi_istep;
118 *pgj = zero; pgj+=gj_istep;
121 for (
unsigned i=1;i<ni1;++i)
126 *pgi = point5*static_cast<destT>(s[o5]) - point5*static_cast<destT>(s[o4]);
128 *pgj = point5*static_cast<destT>(s[o2]) - point5*static_cast<destT>(s[o7]);
146 for (
unsigned i=0;i<ni;++i)
148 *gi=zero; gi+=gi_istep;
149 *gj=zero; gj+=gj_istep;
150 *gi_data = zero; gi_data+=gi_istep;
151 *gj_data = zero; gj_data+=gj_istep;
157 #undef VIL_SOBEL_1X3_INSTANTIATE 158 #define VIL_SOBEL_1X3_INSTANTIATE(srcT, destT) \ 159 template void vil_sobel_1x3(const vil_image_view< srcT >& src, \ 160 vil_image_view<destT >& grad_ij); \ 161 template void vil_sobel_1x3(const vil_image_view< srcT >& src, \ 162 vil_image_view<destT >& grad_i, \ 163 vil_image_view<destT >& grad_j) 165 #endif // vil_sobel_1x3_hxx_ void vil_sobel_1x3(const vil_image_view< srcT > &src, vil_image_view< destT > &grad_i, vil_image_view< destT > &grad_j)
Compute gradients of an image using 1x3 Sobel filters.
Concrete view of image data of type T held in memory.
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.
Apply 1x3 sobel operator to image data.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
void vil_sobel_1x3_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)
Compute gradients of single plane of 2D data using 1x3 Sobel filters.