Boost logo

Boost Users :

Subject: Re: [Boost-users] [GIL] any_image difference
From: Christian Henning (chhenning_at_[hidden])
Date: 2010-11-08 13:43:57


Hi Olivier, here is a slightly better version:

#include <boost\gil\gil_all.hpp>
#include <boost\gil\extension\dynamic_image\dynamic_image_all.hpp>
#include <boost\gil\extension\numeric\pixel_numeric_operations.hpp>

namespace boost { namespace gil {

template <typename Channel1,typename Channel2,typename ChannelR>
struct channel_abs_t : public std::binary_function<Channel1,Channel2,ChannelR> {
    ChannelR operator()(typename channel_traits<Channel1>::const_reference ch1,
                        typename
channel_traits<Channel2>::const_reference ch2) const {
        return std::abs( ChannelR(ch1) - ChannelR(ch2) );
    }
};

template <typename PixelRef1, // models pixel concept
          typename PixelRef2, // models pixel concept
          typename PixelR> // models pixel value concept
struct pixel_abs_t {
    PixelR operator() (const PixelRef1& p1,
                       const PixelRef2& p2) const {
        PixelR result;
        static_transform(p1,p2,result,
                           channel_abs_t<typename channel_type<PixelRef1>::type,
                                         typename channel_type<PixelRef2>::type,
                                         typename
channel_type<PixelR>::type>());
        return result;
    }
};

typedef double bits64F;

GIL_DEFINE_BASE_TYPEDEFS(64F,gray)

typedef float bits32F;

GIL_DEFINE_BASE_TYPEDEFS(32F,gray)

} // namespace gil

} // namespace boost

using namespace boost;
using namespace gil;

template< typename SRC1, typename SRC2, typename DST >
void generate_diff( const SRC1& src1, const SRC2& src2, const DST& dst )
{
    transform_pixels( src1, src2, dst, pixel_abs_t< typename SRC1::value_type
                                                  , typename SRC2::value_type
                                                  , typename DST::value_type
>()
                    );
}

int main(int argc, char** argv)
{
    {
        gray16s_image_t mns( 10, 10 );

        gray32F_image_t mnt( 10, 10 ), mne( 10, 10 );

        fill_pixels( view( mns ), gray16s_image_t::value_type( 5 ));
        fill_pixels( view( mnt ), gray32F_image_t::value_type( 12 ));
        fill_pixels( view( mne ), gray32F_image_t::value_type( 0 ));

        generate_diff( const_view( mns ), const_view( mnt ), view( mne ) );

        gray32F_image_t::value_type p = *view( mne ).xy_at( 0, 0 );
    }

    return 0;
}

Does that somehow fit your needs?

Regards,
Christian


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net