|
Boost : |
Subject: [boost] [GIL] image rescale algorithms
From: Nicolas Lelong (rotoglup_at_[hidden])
Date: 2009-09-04 08:15:47
Hi,
I'm still working on updating my image management codebase, and I noticed
that GIL does come only with by a very limited image rescaling/resampling
algorithm (in gil/extension/numeric/resample.hpp) which does proper
filtering for upsampling an image.
As I need more robust image resampling, I came up with a source code for
GIL, inspired by FreeImage
implementation<http://freeimage.cvs.sourceforge.net/viewvc/freeimage/FreeImage/Source/FreeImageToolkit/>;
this code is available here ::
http://code.google.com/p/rotoglup-scratchpad/source/browse/trunk/#trunk/rtgu/image
This implementation is certainly not as generic as it could be, and could
certainly benefit from 'gil concept checking' and various improvements ; I
tried to make the code more 'readable' than 'efficient', and as I'm not
really at ease with template metaprogramming, I may have missed a few
points.
For example, I think the mechanism I use to select the intermediate pixel
format (used to store the averaged pixels during resizing) may be improved,
and that there must be a way to let the user select a better pixel format if
needed.
I came up with virtual rescale view type, that allows to seamlessly rescale
virtual views of any kind - it is not very efficient, but can be proved
useful. I tried, as much as possible, to provide access to separable rescale
functions (X & Y) so that users can control when/how (or whether) they
should allocate the intermediate view for image rescaling.
Feel free to use this work, and I'd be very happy to have some feedback on
things that could be improved.
The main functions defined are, in
rescale.hpp<http://code.google.com/p/rotoglup-scratchpad/source/browse/trunk/rtgu/image/rescale.hpp>::
// horizontal rescale only, rescale src view into dst view, matching dst
view width
template <typename SrcView, typename DstView, typename Filter>
inline void rescale_cols(const SrcView& src, const DstView& dst, const
Filter& filter);
// vertical rescale only, rescale src view into dst view, matching dst
view height
template <typename SrcView, typename DstView, typename Filter>
inline void rescale_rows(const SrcView& src, const DstView& dst, const
Filter& filter);
// rescale src view into dst view, matching dst view dimensions
template <typename SrcView, typename DstView, typename Filter>
inline void rescale(const SrcView& src, const DstView& dst, const Filter&
filter);
in rescale_any_view.hpp<http://code.google.com/p/rotoglup-scratchpad/source/browse/trunk/rtgu/image/rescale_any_view.hpp>::
template <typename ViewTypes, typename Filter>
inline void rescale_any_view(any_image_view<ViewTypes>& src,
any_image_view<ViewTypes>& dst, const Filter& filter);
in rescale_virtual_view.hpp<http://code.google.com/p/rotoglup-scratchpad/source/browse/trunk/rtgu/image/rescale_virtual_view.hpp>::
// view factories
template <typename SourceView, typename Filter>
typename rescale_x_view_type<SourceView>::view_t
rescale_x_view(SourceView const& view, typename SourceView::coord_t
dst_width, const Filter& filter);
template <typename SourceView, typename Filter>
typename rescale_y_view_type<SourceView>::view_t
rescale_y_view(SourceView const& view, typename SourceView::coord_t
dst_height, const Filter& filter);
template <typename SourceView, typename Filter>
typename rescale_view_type<SourceView>::view_t
rescale_view(SourceView const& view, typename SourceView::coord_t
dst_width, typename SourceView::coord_t dst_height, const Filter& filter);
and a few filters<http://code.google.com/p/rotoglup-scratchpad/source/browse/trunk/rtgu/image/filters.hpp>are
provided.
Cheers,
Nicolas.
**
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk