Skip to content
This repository
Browse code

Have BlockSum aply the kernel centered on the pixel

Previously it was doing it from the top left. This change makes the BlockSum operation more consistent with Convolution.
  • Loading branch information...
commit b70793ecf16fd7c8e64ed6f503517c8d0428440d 1 parent a40138b
Zack Moratto zmoratto authored

Showing 1 changed file with 12 additions and 9 deletions. Show diff stats Hide diff stats

  1. +12 9 src/vw/Image/IntegralView.h
21 src/vw/Image/IntegralView.h
@@ -123,18 +123,19 @@ namespace vw {
123 123 template <class ImageT>
124 124 class BlockSumView : public ImageViewBase<BlockSumView<ImageT> > {
125 125 ImageT m_child;
126   - uint32 m_range;
  126 + int32 m_range; // Odd numbered forward step
  127 + int32 m_back_step; // Even numbered back step
127 128
128 129 // This type can hold image pixels and sum them with minimal risk of overflow
129 130 typedef typename CompoundChannelCast<typename ImageT::pixel_type,typename AccumulatorType<typename CompoundChannelType<typename ImageT::pixel_type>::type>::type>::type sum_t;
130 131
131 132 template <typename PixelAccessorT>
132   - inline sum_t sum_block(const PixelAccessorT& upper_left) const {
  133 + inline sum_t sum_block(const PixelAccessorT& center) const {
133 134 return
134   - *upper_left
135   - + *upper_left.advance_copy(2*m_range, 2*m_range)
136   - - *upper_left.advance_copy(0, 2*m_range)
137   - - *upper_left.advance_copy(2*m_range, 0);
  135 + *center.advance_copy(-m_back_step,-m_back_step)
  136 + + *center.advance_copy(m_range, m_range)
  137 + - *center.advance_copy(-m_back_step, m_range)
  138 + - *center.advance_copy(m_range,-m_back_step);
138 139 }
139 140
140 141 public:
@@ -145,8 +146,8 @@ namespace vw {
145 146 typedef ProceduralPixelAccessor<BlockSumView> pixel_accessor;
146 147
147 148 BlockSumView( ImageT const& image, uint32 window_size = 3)
148   - : m_child(image), m_range((window_size-1)/2) {
149   - VW_ASSERT(window_size % 2 == 1, vw::LogicErr() << "BlockSumView's window_size must be odd");
  149 + : m_child(image), m_range((window_size-1)/2), m_back_step(m_range+1) {
  150 + VW_ASSERT(window_size % 2 == 1, vw::LogicErr() << "BlockSumView's window_size must be odd");
150 151 }
151 152
152 153 inline int32 cols() const { return m_child.cols(); }
@@ -173,7 +174,8 @@ namespace vw {
173 174 inline void rasterize( DstT const& dst, BBox2i const& bbox ) const {
174 175
175 176 BBox2i child_bbox(bbox);
176   - child_bbox.expand(m_range);
  177 + child_bbox.expand(m_range); // Expand for kernel size
  178 + child_bbox.min() -= Vector2i(1,1); // Expand TL because we access index -1
177 179
178 180 typedef ImageView<typename CompoundChannelCast<pixel_type,typename AccumulatorType<typename CompoundChannelType<pixel_type>::type>::type>::type> SrcT;
179 181
@@ -183,6 +185,7 @@ namespace vw {
183 185 typedef typename DstT::pixel_accessor DstAccessT;
184 186
185 187 SrcAccessT splane = src.origin();
  188 + splane.advance(m_range+1,m_range+1);
186 189 DstAccessT dplane = dst.origin();
187 190 for( int32 p=0; p<dst.planes(); ++p ) {
188 191 SrcAccessT srow = splane;

0 comments on commit b70793e

Please sign in to comment.
Something went wrong with that request. Please try again.