How to access the data of bit aligned view?

2012-05-31
2013-04-29
  • stereoMatching

    stereoMatching - 2012-05-31

    How could I access a bit align image data by bit align view?

    typedef bit_aligned_image1_type<1, boost::gil::gray_layout_t>::type image_t;
    typedef image_t::view_t view;
    //how to access the data?
    

    Thank you very much.

     
  • Davide

    Davide - 2012-05-31

    This is the reply I've got for a similar questions (in this topic: https://sourceforge.net/projects/adobe-source/forums/forum/648138):

    typedef rgb8_image_t Image_t;
    Image_t img(640,480);
    Image_t::view_t::x_iterator data_it = view(img).row_begin(0);
    unsigned int* data = (unsigned int*) &gil::at_c<0>(*data_it);
    

    "Beware this doesn't work for planar images."

    Hope it helps

     
  • stereoMatching

    stereoMatching - 2012-05-31

    Thanks for your help, but the link you post would link to the first page of the forum.
    Could you post it again?Thanks

     
  • stereoMatching

    stereoMatching - 2012-06-02

    @davideanastasia

    I use a container(QImage) to load image which store the data with 1bit per pixel.
    And I could get the data of that container by the member function
    "unsigned char *bits()" provided by QImage.

    Now I have two questions.

    1 : How could I create a view to to manipulate the data of gray1_view_t?
        

    typedef boost::gil::bit_aligned_image1_type<1, boost::gil::gray_layout_t>::type gray1_image_t;
    typedef gray1_image_t::view_t gray1_view_t;
    QImage src("lena.jpg"); //load an image which store each pixel with 1 bit
    gray1_view_t src_view; //interleaved_view can't work
    

    2 : The algorithms provided by GIL support the bit aligned view or not?

    Thank you very much

    Best Regards
    stereomatching

     
  • Davide

    Davide - 2012-06-02

    I am not sure I am the best person to reply (I hope somebody steps in as well), because I've been using GIL for less than a month now. Anyway, I'll try to reply.

    From my understanding, you have to do copy_pixel from a view in the same format of QImage into the view_gray1. However, you can just get rid completely of the image_gray1_t and, based on the data in the QImage, build a color_converted_view<gray1>, so you avoid the temp copy.

     
  • stereoMatching

    stereoMatching - 2012-06-02

    >(I hope somebody steps in as well)
    Me too, I hope I could see other answer,still trying to build a view which could
    work with the algotithms of gil.
    Thanks a lot

     
  • Anonymous - 2012-06-03

    If I understand correctly you want to create a view from a raw buffer. Now interleaved_view only works for homogeneous images types which excludes bit_aligned images. But you can create a x_iterator to traverse your QImage. The following code creates such an iterator:

    std::vector< unsigned char > buf( 100 );
    typedef bit_aligned_image1_type<1, gray_layout_t>::type::view_t view1_t;
    typedef color_converted_view_type< view1_t, view1_t::reference >::type cc_view_t;
    typedef cc_view_t::x_iterator cc_it_t;
    cc_it_t cc_it = cc_it_t( view1_t::x_iterator(&buf.front()) );
    

    Of course c++0x's keyword "auto" could hide some details. ;-)

    Hope this helps.

    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-03

    Thanks, could I set the width, height and the channel numbers of the bit_aligned_image_type?
    Could it work with the algorithms which work with packed_aligned_image ?Like

    template <typename SrcView, typename DstView, bool IsPlanar = false>
    void x_gradient_generic(const SrcView& src, const DstView& dst) {    
        typedef typename boost::gil::channel_type<DstView>::type dst_channel_t;        
        auto src2 = boost::gil::color_converted_view<typename DstView::value_type>(src);   
        for (int y = 0; y < src.height(); ++y) {        
            auto src_it = src2.row_begin(y);
            auto dst_it = dst.row_begin(y);
            for (int x = 1; x < src.width() -1; ++x)
                boost::gil::static_transform(src_it[x - 1], src_it[x + 1], dst_it[x],
                                             halfdiff_cast_channels_2());
        }
    }
    

    Do I have to design a brand new algorithm to fit those bit aligned image?
    Thank you very much

     
  • Anonymous - 2012-06-03

    Hi Tham,

    I'm getting lost here a bit. Would you mind posting a complete code sample. Also note that some algorithms are covered by the numeric extension.

    Basically a bit_aligned image is just like any other image type. You can define them like this:

        typedef bit_aligned_image1_type< 1, devicen_layout_t< 1 > >::type one_channel_bit_aligned_image_t;
        typedef bit_aligned_image1_type< 1, devicen_layout_t< 3 > >::type three_channels_bit_aligned_image_t;
        one_channel_bit_aligned_image_t    img1( 640, 480 );
        three_channels_bit_aligned_image_t img2( 640, 480 );
    

    We should strive to have one generic algorithm that fits all image/view types. When that's not possible we can always use compile-time polymorphism to have a seperate implementation for bit_aligned image types.

    Regards,
    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-03

    > Also note that some algorithms are covered by the numeric extension.
    Thanks, I will study it before I implement an algorithm.

    >always use compile-time polymorphism to have a seperate implementation for bit_aligned image types.
    Agree with you.

    #include <boost/gil/gil_all.hpp>
    #include <QtGui/QApplication>
    #include <QtGui/QImage>
    #include <create_simple_view.hpp>
    //#include "iview_factory_unit_test.hpp"
    int main(int argc, char *argv[])
    {        
        QApplication a(argc, argv);
        using namespace boost::gil;
        QImage src("../GIL_with_Qt/images_00/lena/lena.jpg");
        src.convertToFormat(QImage::Format_Indexed8);
        typedef bit_aligned_image1_type<1, gray_layout_t>::type::view_t view1_t;
        typedef color_converted_view_type< view1_t, view1_t::reference >::type cc_view_t;
        typedef cc_view_t::x_iterator cc_it_t;
        //copy_pixels(?, ?);//what should I fill in the ?
        //method .bits would return the first byte of the src(the real "pixel" position src point to)
        cc_it_t cc_it = cc_it_t( view1_t::x_iterator(src.bits()) );
        QImage dst(src.size(), src.format());
        cc_it_t cc_it2 = cc_it_t( view1_t::x_iterator(dst.bits()));
        *cc_it = *cc_it2; //always crash               
        return a.exec();    
        return 0;
    }
    

    I encounter a lot of problems when learning GIL, I will arrange them and
    post them on my blog.Hope this could smooth the learning curve of GIL.

    Always thanks for your help.

    Regards
    Tham

     
  • stereoMatching

    stereoMatching - 2012-06-03

    Anybody know what should I fill into the "?" ?
    Besides, I share some of my learning experience
    of GIL on my blog(http://stereomatching00.blogspot.tw/).
    I Hope this could be some help.

    Thanks a lot

     
  • Anonymous - 2012-06-03

    Let's stick to the first half of your code. I can see that you read an image and convert it into an indexed one. Not sure what the 8 stands for. Could you tell me what you want to copy to where?

    Also how to you access the raw bytes of an QImage. Sorry my knowledge of QT is rather limited.

    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-03

    Sorry, I did a mistake, it should be "Format_Mono" rather than "Format_Indexed8".
    Format_Indexed8 means the image is stored using 8-bit indexes into a colormap(gray8_view_t could deal with it pretty well)
    Format_Mono means the image is stored using 1-bit per pixel. Bytes are packed with the most significant bit (MSB) first

    #include <boost/gil/gil_all.hpp>
    #include <QtGui/QApplication>
    #include <QtGui/QImage>
    #include <create_simple_view.hpp>
    //#include "iview_factory_unit_test.hpp"
    int main(int argc, char *argv[])
    {        
        QApplication a(argc, argv);
        using namespace boost::gil;
        QImage src("../GIL_with_Qt/images_00/lena/lena.jpg"); //load lena.jpg
        src.convertToFormat(QImage::Format_Mono); //transform the format to 1bit per pixel
        typedef bit_aligned_image1_type<1, gray_layout_t>::type::view_t view1_t;
        typedef color_converted_view_type< view1_t, view1_t::reference >::type cc_view_t;
        typedef cc_view_t::x_iterator cc_it_t;   
        QImage dst(src.size(), src.format());  //construct other QImage with the same format and dimensions
       //what should I fill in the "?"  if I want to copy the data of src to dst?
        copy_pixels(?, ?);
        return a.exec();     
    }
    

    This could be done easier way with the help of QImage
    I use copy_pixel to copy the pixels of src to dst because
    I want to make sure the view could work.

    >Sorry my knowledge of QT is rather limited.
    Exactly, my knowledge of Qt is limited too, I only use it to present load,
    save and display the images after post processing.
    Thanks a lot.

    Best Regards
    Tham

     
  • stereoMatching

    stereoMatching - 2012-06-05

    Is this problem can't be solved by the current version of GIL?
    Thanks

    Best Regards
    Tham

     
  • Anonymous - 2012-06-06

    Hi Tham, I apologize for replying so late. This week I'm very busy. Please hold on to the weekend. I'm sure we can solve your problem then.

    Chrisitan

     
  • stereoMatching

    stereoMatching - 2012-06-07

    @Christian
    You don't need to apologize, you already help me a lot :), I develop the factory and algorithms for fun,because I like
    the philosophy of GP and dealing with different algorithms are pretty interesting.

    Anyway, sorry for my impatient.I could wait until you guys have times.Thanks.

     
  • Anonymous - 2012-06-09

    Tham, when you read an image with Qt your qt view factory should create a gil view. When you have that you can use copy_pixels.

    Let's have the view factory up and running and will take it from there. How does that sound?

    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-10

    >when you read an image with Qt your qt view factory should create a gil view. When you have that you can use copy_pixels.

    Hi, Christian
      It is what I am trying to do, but I have the problem on how to create the view of bit_aligned_image.

    >Let's have the view factory up and running and will take it from there. How does that sound?
    Fine with me, could you tell me which folder should I upload?Thanks

    Best Regards
    Tham

     
  • Anonymous - 2012-06-10

    Hi Tham, can you compile your qt view factory example? Here is what I have:

    http://pastebin.com/MRbT2563

    It's the compiler output from VS2010. That compiler is a must to support! Please let me know when you fixed it.

    Thanks,
    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-11

    I fixed it(I think port it would be a better word?) and make sure it could compile by vc2010.
    There are two reasons(atleast) why it can't be compiled
    1 : vc2010 do not support default template parameters for function

    template<typename T = int>
    void haha() { T a = 10; } //ok on mingw4.6.2 if enabled c++0x flag but vc2010 don't support it yet
    

    2 : vc2010 do not support std::initializer_list<T>

    std::vector<int> A = {1, 2, 3, 4, 5};  //ok on mingw4.6.2 if enabled c++0x flag but vc2010 don't support it yet
    

    The features above could make the codes more readable, but they are not being widely supported yet.

    Please tell me if you can't compile it, I will fix it as fast as I can.Thanks.

    Best Regards
    Tham

     
  • Anonymous - 2012-06-16

    Hi Tham,

    I'm able to compile your code now! Let's tackle your issue…

    Here is what I understand. You want to create wrapper so you can take a QImage and create a gil::view out of it and vice versa. You want to support all sorts of QImage types. Correct?

    I would suggest that we create something similar to what I did for OpenCV. There I have create some helper structures to encode all supported image types. Look here:

    http://code.google.com/p/gil-contributions/source/browse/trunk/gil_2/boost/gil/extension/opencv/ipl_image_wrapper.hpp

    I think we should do that as well for QImage. After that is done we could create a value type called qimage_wrapper, maybe. Then we need to create create_qimage to support gil -> qimage create. At last we need to think about how to qimage -> gil.

    Let's stick to the image definition and disregard algorithms for now.

    Regards,
    Christian

     
  • stereoMatching

    stereoMatching - 2012-06-18

    >You want to create wrapper so you can take a QImage and create a gil::view out of it and vice versa.
    I would like to take a QImage and create a gil::view out of it but not vice versa.But this could be done.

    >There I have create some helper structures to encode all supported image types. Look here:
    Thanks, I will create something similar to it.

    >Let's stick to the image definition and disregard algorithms for now.
    Ok

    >You want to support all sorts of QImage types. Correct?
    Bingo, but there are some problems to deal with bit align image.
    Like Format_RGB666(The image is stored using a 24-bit RGB format (6-6-6). The unused
    most significant bits is always zero.") and Format_Mono(The image is stored using 1-bit per pixel)

        QImage src("../GIL_with_Qt/images_00/lena/lena.jpg"); //load lena.jpg
        src.convertToFormat(QImage::Format_Mono); //transform the format to 1bit per pixel
        typedef bit_aligned_image1_type<1, gray_layout_t>::type::view_t view1_t;
        typedef color_converted_view_type< view1_t, view1_t::reference >::type cc_view_t;//now I have the view
    

      I could get the raw pixel from src by calling "uchar *bits ()", have the bytes per row by calling
    "int bytesPerLine () const" and I know the width and height of the image.The problem is
    how to bind the data of src to cc_view_t so I could manipulate the bit aligned views
    like those packed aligned views.

    What I mean is

    //pseudo codes
    cc_view_t src_view = interleave_view_for_bit_aligned_image(?);
    //now the src_view could act like gray8_view_t
    

    Or I should just transform those image to packed aligned images(like gray8 or bgra8)
    ,manipulate them and transform them back to the original format?Thanks

    Best Regards
    Tham

     
  • stereoMatching

    stereoMatching - 2012-06-18

    Could I get the number of "bytes per line"(how many bytes per row) from view or image?
    By the way, since QImage is an implicit sharing object, I think I don't need to design a qimage_wrapper for QImage.

    Best Regards
    Tham

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks