
Hi all,
I am trying to use GIL and face a problem. Here is the code :
namespace boost
{
namespace gil
{
/// Extension a GIL pour gerer les pixels "double" ...
typedef pixel< double, boost::gil::gray_layout_t > gray64_pixel_t;
typedef image< gray64_pixel_t, false > gray64_image_t;
typedef image< gray64_pixel_t, true > gray64_planar_image_t;
//typedef image_view< gray64_pixel_t > gray64_view_t;
}
}
int main ( int argc , char **argv)
{
typedef boost::mpl::vector<
boost::gil::gray8_image_t,
boost::gil::gray16_image_t,
boost::gil::gray32_image_t,
//boost::gil::gray64_image_t,
boost::gil::rgb8_image_t,
boost::gil::rgb16_image_t,
boost::gil::rgb32_image_t > my_img_types;
typedef boost::mpl::vector<
boost::gil::gray8_view_t,
boost::gil::gray16_view_t,
boost::gil::gray32_view_t,
//boost::gil::gray64_view_t,
boost::gil::rgb8_view_t,
boost::gil::rgb16_view_t,
boost::gil::rgb32_view_t > my_view_types;
if ( argc < 4 )
{
usage();
return 1;
}
std::string input_filename( argv[1] );
std::string output_filename( argv[3] );
int channel_index;
try
{
channel_index = boost::lexical_cast<int>( argv[2] );
}
catch( boost::bad_lexical_cast &e)
{
std::cout << "bad_lexical_cast exception : " << e.what() <<
std::endl;
return 1;
}
boost::gil::any_image

Hi Oliver, I don't get it to compile even when you put the nth_channel_view call inside jpeg_write_view for a simple reason. nth_channel_view needs the reference type of your any_image. But that's not possible since no one knows what image type the any_image actually is. You can cast your any_image to a specific image type using gil's variant::_dynamic_cast member. Then you can use nth_channel_view. Are you sure your code compiles? Let me know if you keep having troubles. Regards, Christian

2009/1/27 Christian Henning
Hi Oliver,
Hi Christian,
Yes, my code compiles fine with boost 1.36. In attachement, maybe you could try. Regards, Olivier
-- Olivier Tournaire MATIS - Institut Géographique National 73, Ave de Paris 94165 St Mandé cedex, France tel: (+33) 1 43 98 80 00 - 71 25 fax: (+33) 1 43 98 85 81

Mhmm, somehow I screwed up. The following compiles fine now:
int main ( int argc , char **argv)
{
typedef boost::mpl::vector<
boost::gil::gray8_image_t,
boost::gil::gray16_image_t,
boost::gil::gray32_image_t,
boost::gil::rgb8_image_t,
boost::gil::rgb16_image_t,
boost::gil::rgb32_image_t > my_img_types;
typedef boost::mpl::vector<
boost::gil::gray8_view_t,
boost::gil::gray16_view_t,
boost::gil::gray32_view_t,
boost::gil::rgb8_view_t,
boost::gil::rgb16_view_t,
boost::gil::rgb32_view_t > my_view_types;
boost::gil::any_image

Thank you Christian.
2009/1/27 Christian Henning
Since it extracts one channel from an image, I thought I could retrieve one of the following : boost::gil::gray8_view_t, boost::gil::gray16_view_t or boost::gil::gray32_view_t. I am probably wrong, but is there a way to achieve such a task ? Regards, Olivier
-- Olivier Tournaire MATIS - Institut Géographique National 73, Ave de Paris 94165 St Mandé cedex, France tel: (+33) 1 43 98 80 00 - 71 25 fax: (+33) 1 43 98 85 81

Olivier,
you can cast the any_image to any of the images you specified. Then
you can easily apply the nth_channel_view() function. Something like
this:
typedef mpl::vector< gray8_image_t
, rgb8_image_t
>::type my_img_types_t;
typedef nth_channel_view_type< rgb8_image_t::view_t >::type channel_view_t;
any_image< my_img_types_t > runtime_image;
rgb8_view_t v( view( runtime_image._dynamic_cast

Christian, Thank you for this code. However, I would like the extracted channel to be the same pixel type as the original runtime image. I guess it is possible since if I write the extracted channel view without storing it in a variable (see my first post), it works fine. Here it is: boost::gil::jpeg_read_image( input_filename , runtime_image ); boost::gil::jpeg_write_view( output_filename , boost::gil::nth_channel_view( view(runtime_image) , channel_index ) ); I just want to be as generic as possible and avoid "if ... else if ..." to get the right pixel type at runtime and thus perform the right dynamic_cast. Is it possible ? Regards, Olivier

Sorry Olivier, I tried some stuff but haven't made much progress. It
still is riddle to me why the code compiles. Should it compile? I
don't know. Hopefully Lubomir can fill in some time.
Regards,
Christian
On Thu, Jan 29, 2009 at 12:44 PM, Olivier Tournaire
participants (2)
-
Christian Henning
-
Olivier Tournaire