void blur(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    int max_x = src.width() - 1;
    int width = src.width();
    for (int y=1; y<src.height()-1; ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x < max_x; ++x) {
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	dst_it[x][c] =
            		src_it[x-1-width][c] / 16 +
            		src_it[x-width][c] / 8 +
            		src_it[x-1-width][c] / 16 +

            		src_it[x-1][c] / 8 +
            		src_it[x][c] / 4 +
            		src_it[x-1][c] / 8 +

            		src_it[x-1+width][c] / 16 +
            		src_it[x+width][c] / 8 +
            		src_it[x-1+width][c] / 16;
            }
        }
    }
}
void sobel_xy(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    int max_x = src.width() - 1;
    int width = src.width();
    for (int y=1; y<src.height()-1; ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x < max_x; ++x) {
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	dst_channel_t srcPlus1 = src_it[x+width][c]; //TODO should be replaced by line length
            	dst_channel_t srcMinus1 = src_it[x-width][c];
            	dst_channel_t sobelY = (srcPlus1 > srcMinus1) ?
            			srcPlus1 - srcMinus1 :
						srcMinus1 - srcPlus1;
            	srcPlus1 = src_it[x+1][c];
            	srcMinus1 = src_it[x-1][c];
            	dst_channel_t sobelX = (srcPlus1 > srcMinus1) ?
            			srcPlus1 - srcMinus1 :
						srcMinus1 - srcPlus1;
            	dst_it[x][c] = max(sobelX, sobelY);
            }
        }
    }
}
Exemple #3
0
inline void boost::gil::rescale_cols(const SrcView& src, const DstView& dst, const Filter& filter)
{
  typedef typename SrcView::value_type src_pixel_t;
  typedef typename gil::detail::create_accum_pixel_type<src_pixel_t>::type accum_pixel_t;

  if (src.height() != dst.height())
  {
    throw std::runtime_error("rescale_cols: height of source and destination views must match");
  }

  detail::weight_table weights;
  weights.reset(filter, src.width(), dst.width());

  detail::weight_table::const_iterator const table_begin = weights.begin();
  detail::weight_table::const_iterator const table_end   = weights.end();

  typedef typename DstView::coord_t coord_t;
  coord_t const height = dst.height();

  for (coord_t y=0; y<height; y++)
  {
    detail::rescale_line<accum_pixel_t>(
        src.row_begin(y)
      , dst.row_begin(y)
      , table_begin
      , table_end
      );
  }
}
void x_gradient(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    for (int y=0; y<src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x<src.width()-1; ++x)
            static_transform(src_it[x-1], src_it[x+1], dst_it[x], 
                               halfdiff_cast_channels<dst_channel_t>());
    }
}
void x_gradient(const SrcView& src, const DstView& dst) {

    int max_x = src.width()-1;
    for (int y=0; y<src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x < max_x; ++x) {
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	dst_it[x][c] = (src_it[x+1][c] - src_it[x-1][c])/2;
            }
        }
    }
}
void grayToRgbView(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    int width = src.width();
    for (int y=0; y< src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=0; x < width; ++x) {
        	dst_channel_t grayValue = (dst_channel_t) src_it[x];
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	dst_it[x][c] = grayValue;
            }
        }
    }
}
void rgbToGrayView(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    int width = src.width();
    for (int y=0; y< src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=0; x < width; ++x) {
        	int combination = 0;
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	combination += src_it[x][c] * RGB_TO_GRAY_INT[c];
            }
        	dst_it[x] = (dst_channel_t) (combination / 100);
        }
    }
}
Exemple #8
0
inline void view_multiplies_scalar(const SrcView& src,const Scalar& scalar,const DstView& dst) {
    BOOST_ASSERT(src.dimensions() == dst.dimensions());
    using PIXEL_SRC_REF = typename pixel_proxy<typename SrcView::value_type>::type;
    using PIXEL_DST_REF = typename pixel_proxy<typename DstView::value_type>::type;
    int height=src.height();
    for(int rr=0;rr<height;++rr) {
        typename SrcView::x_iterator it_src=src.row_begin(rr);
        typename DstView::x_iterator it_dst=dst.row_begin(rr);
        typename SrcView::x_iterator it_src_end=src.row_end(rr);
        while(it_src!=it_src_end) {
            pixel_assigns_t<PixelAccum,PIXEL_DST_REF>()(
                pixel_multiplies_scalar_t<PIXEL_SRC_REF,Scalar,PixelAccum>()(*it_src,scalar),
                *it_dst);
            ++it_src; ++it_dst;
        }
    }
}
void sobel_x(const SrcView& src, const DstView& dst) {
    typedef typename channel_type<DstView>::type dst_channel_t;

    int max_x = src.width()-1;
    for (int y=0; y<src.height(); ++y) {
        typename SrcView::x_iterator src_it = src.row_begin(y);
        typename DstView::x_iterator dst_it = dst.row_begin(y);

        for (int x=1; x < max_x; ++x) {
            for (int c=0; c< num_channels<rgb8_view_t>::value; ++c) {
            	dst_channel_t srcPlus1 = src_it[x+1][c];
            	dst_channel_t srcMinus1 = src_it[x-1][c];
            	dst_it[x][c] = (srcPlus1 > srcMinus1) ?
            			srcPlus1 - srcMinus1 :
						srcMinus1 - srcPlus1;
            }
        }
    }
}