|
Boost Users : |
Subject: Re: [Boost-users] [GIL] any_image difference
From: Olivier Tournaire (olitour_at_[hidden])
Date: 2010-11-06 10:44:53
Hi,
2010/11/5 Olivier Tournaire <olitour_at_[hidden]>
> Hi all,
>
> What is the best way to compute the difference between 2 any_image? Of
> course, the input any_image may not be of the same type... So, if pixels are
> unsigned int for the 1st one and double for the 2nd one, the result must be
> stored as double.
> I (accidently) found pixel_minus_t in pixel_numeric_operations.hpp but
> cannot figure how to use it.
>
I am still having problem with this. I found a way to write such an image
difference, but not for any_image. Here is what I have now:
namespace boost { namespace gil {
typedef double bits64F;
GIL_DEFINE_BASE_TYPEDEFS(64F,gray)
typedef float bits32F;
GIL_DEFINE_BASE_TYPEDEFS(32F,gray)
} }
struct image_difference
{
typedef void result_type;
template<typename OutputViewType, typename ViewType1, typename ViewType2>
result_type operator()(OutputViewType &out, const ViewType1 &v1,
const ViewType2 &v2) const
{
typedef typename get_pixel_type<ViewType1>::type v1_pixel_t;
typedef typename get_pixel_type<ViewType2>::type v2_pixel_t;
typedef typename get_pixel_type<OutputViewType>::type out_pixel_t;
typename ViewType1::iterator v1_it = v1.begin();
typename ViewType2::iterator v2_it = v2.begin();
typename OutputViewType::iterator out_it = out.begin();
for(;v1_it!=v1.end();++v1_it, ++v2_it, ++out_it)
*out_it = pixel_minus_t<v1_pixel_t, v2_pixel_t,
out_pixel_t>()(*v1_it, *v2_it);
}
};
int main(int argc, char** argv)
{
gray16s_image_t mns;
gray32F_image_t mnt, mne;
read_image(
"/home/olivier/work/data/ZTerrain_c3/ZTerrain_c3.tif", mns ,
tiff_tag() );
read_image(
"/home/olivier/work/data/ZTerrain_c3/ZTerrain_c3_MNT.tif", mnt ,
tiff_tag() );
mne.recreate( mns.width(), mns.height() );
image_difference()( view(mne) , view(mns) , view(mnt) );
write_view(
"/home/olivier/work/data/ZTerrain_c3/ZTerrain_c3_MNE.tif", view(mne),
tiff_tag() );
}
I am however sure there is a generic and better way to do such a simple
image operation. 2 questions arise:
1) how can I use for_each_pixel in image_difference rather than a for loop?
2) how can I extend this code to work on any_image(_view) using
apply_operation?
Best regards,
Olivier
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