Some problems about GIL

Hi, 1. Does any one know how to crop a image using GIL? 2. The IO extension seems not support to serialize a image binary data to memory, how to do that using GIL? (read png -> do some stuffs... -> write png to char* buffer not file.) 3. Is there any one good performance image comparison algorithm to compare two images by GIL? I am using ImageMagick to do that now. It try to compute Mean Absolute Error for two images, how this can be done by GIL? Thanks for your answer, I am try to adopt my old ImageMagick's code to GIL, I like elegant design of GIL but I am a newbie. Thanks for you patient to answer my questions. :) -- View this message in context: http://www.nabble.com/Some-problems-about-GIL-tp20526156p20526156.html Sent from the Boost - Users mailing list archive at Nabble.com.

Hi there,
1. Does any one know how to crop a image using GIL?
You can create a sub-image view of an existing image. Like this for instance: // original image gray8_image_t src( 10, 10 ); // cropped image gray8_image_t dst( 4, 4 ); // coppy pixels copy_pixels( subimage_view( view( src ), point_t( 2, 2 ), point_t( 4, 4 )) , view( dst ));
2. The IO extension seems not support to serialize a image binary data to memory, how to do that using GIL? (read png -> do some stuffs... -> write png to char* buffer not file.)
I'm not sure if I understand you correctly. To get access to the image's memory buffer you can do the following: gray8_image_t src( 10, 10 ); unsigned char* buf = &( *view( src ).begin() )[0]; But you have to be careful when it comes to planar and interleaved images since the data is arranged differently in memory.
3. Is there any one good performance image comparison algorithm to compare two images by GIL? I am using ImageMagick to do that now. It try to compute Mean Absolute Error for two images, how this can be done by GIL?
I would assume the two images are compatible. If yes, you could do this: template< typename View1, typename View2 > bool cmp( const View1& v1, const View2& v2 ) { for( int y = 0; y < std::min( v1.height(), v2.height() ); ++y ) { const View1::x_iterator it1 = v1.row_begin( y ); const View2::x_iterator it2 = v2.row_begin( y ); for( int x = 0; x < std::min( v1.width(), v2.width() ); ++x ) { if( !static_equal( it1[x], it2[x] )) return false; } } return true; } The function has the advantage of not caring about the if an image is planar or interleaved and also not caring about the layout of the channels. For instance the following still works: bgr8_image_t img1( 10, 10 ); rgb8_planar_image_t img2( 10, 10 ); assert( cmp( view( img1 ), view( img2 ))); There are still a lot of drawbacks here and I wouldn't recommend this function in production code. But I hope it gives you the idea of how to use gil. For instance, in case the channels are floating point data you would want to something use something else than the ==operator. Currently, there is no algorithm available to compute the Mean Absolute Error. If you want you can take the challenge! ;-) Am right in assuming that you would accumulate the differences of each channel and then at the end take the mean?
Thanks for your answer, I am try to adopt my old ImageMagick's code to GIL, I like elegant design of GIL but I am a newbie. Thanks for you patient to answer my questions. :)
Not a problem. Christian

Thank your answers. :) For the problem 2, I mean I need a raw image buffer **with png format** including header and not just pixels. png_io's png_write_view only writes png format to file. I must pass that data to other library to do something. If I write png to file than read it to memory then pass it, it might be too slow. How to do that? For the problem 3, If I can make sure that two images **always** have the same format (png), the same size, the same layout of the channels, and the same channel depth...etc. Is there any good performance way to do that? I am not sure that to compute Mean Absolute Error is the best way to do that. I just simply follow the recommendation of ImageMagicks (http://www.imagemagick.org/Usage/compare/). But after this review, I found MAE is used to compute "how different are two images"... oh, actually, I don't need to know how difference, I just want to know two images are different. :( I think that simply pixel by pixel comparison might be the fastest way to do that? Thank you very much. -- View this message in context: http://www.nabble.com/Some-problems-about-GIL-tp20526156p20533158.html Sent from the Boost - Users mailing list archive at Nabble.com.

Hi there,
For the problem 2, I mean I need a raw image buffer **with png format** including header and not just pixels. png_io's png_write_view only writes png format to file. I must pass that data to other library to do something. If I write png to file than read it to memory then pass it, it might be too slow.
How to do that?
The PNG extension is using libpng which will transform the data into the png format. Though there is no straightforward way to have access to the png image buffer. Unless you write the file and reopen.
For the problem 3, If I can make sure that two images **always** have the same format (png), the same size, the same layout of the channels, and the same channel depth...etc. Is there any good performance way to do that?
Well byte by byte comparison is the fastest without doing any crazy optimization. Use memcmp if possible.
I am not sure that to compute Mean Absolute Error is the best way to do that. I just simply follow the recommendation of ImageMagicks (http://www.imagemagick.org/Usage/compare/). But after this review, I found MAE is used to compute "how different are two images"... oh, actually, I don't need to know how difference, I just want to know two images are different. :(
That what I was thinking. Christian
participants (2)
-
blp330
-
Christian Henning