From: Gehua Y. <yan...@ho...> - 2003-05-08 04:29:32
|
Is your image color or grayscale? Different results are expected if it is a color image. > vil_image img = vil_load("castle.000.jpg"); > vil_memory_image_of<unsigned char> buf1(img); The constructor of vil_memory_image-of would not convert a color image to grayscale for you. As the result, buf1 contains invalid information, most likely to be r1, g1, b1, r2, g2,b2, etc. The correction would be the following, depending on whether you want color or gray scale. vil_memory_image_of<vil_rgb<vil_byte> > buf1(img); vil_memory_image_of<unsigned char> buf1( vil_image_as_byte(img) ); In the case of > vil_memory_image_of<unsigned char> buf2; > buf2.resize( w, h ); > vil_image_as_byte( img ).get_section( buf2.get_buffer(), 0, 0, w, h ); img is converted to grayscale before filling the buffer. In case you haven't noticed, vil2 is going to replace vil."vil2 now has more functionality that vil. it has a cleaner design, is faster, and has support for more general memory formats". If you just began using vil, my advice is to jump to vil2. Regards, Gehua Yang ----- Original Message ----- From: "Lianqing Yu" <yul...@ne...> To: <vxl...@li...> Sent: Wednesday, May 07, 2003 9:03 PM Subject: [Vxl-users] vil_memory_image question, two construction ways, two results > Hi, vxl users, > > I've got a problem concerned with vil_memory_image when I tried to access the image pixels. > > The way that vxl book demonstrates is to construct an object of vil_memory_image_of with a vil_image parameter: > vil_memory_image_of<unsigned char> buf(img); > > Another way used by osl_harris is a little different: > vil_memory_image_of<unsigned char> buf; > buf.resize( w, h ); > vil_image_as_byte( img ).get_section( buf.get_buffer(), 0, 0, w, h ); > > However, different results are obtained when I run the code below: > > #include <vcl_iostream.h> > #include <vil/vil_load.h> > #include <vil/vil_memory_image_of.h> > #include <vil/vil_image_as.h> > > int main() > { > vil_image img = vil_load("castle.000.jpg"); > > int w = img.width(), h = img.height(); > > vil_memory_image_of<unsigned char> buf1(img); > > vil_memory_image_of<unsigned char> buf2; > buf2.resize( w, h ); > vil_image_as_byte( img ).get_section( buf2.get_buffer(), 0, 0, w, h ); > > // Access pixels and print its value as an int. > for ( int i = 0; i <= 200; i+=100 ) { > for ( int j = 0; j <= 200; j+=100 ) > vcl_cout << (int)buf1[i][j] << " "; > vcl_cout << vcl_endl; > } > vcl_cout << vcl_endl; > for ( int i = 0; i <= 200; i+=100 ) { > for ( int j = 0; j <= 200; j+=100 ) > vcl_cout << (int)buf2[i][j] << " "; > vcl_cout << vcl_endl; > } > } > > Any help will be greatly appreciated! > > Yu Lianqing > Department of computer science > Beijing Institute of technology > > > -- > Your favorite stores, helpful shopping tools and great gift ideas. > Experience the convenience of buying online with Shop@Netscape! > http://shopnow.netscape.com/ > > > > ------------------------------------------------------- > Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara > The only event dedicated to issues related to Linux enterprise solutions > www.enterpriselinuxforum.com > > _______________________________________________ > Vxl-users mailing list > Vxl...@li... > https://lists.sourceforge.net/lists/listinfo/vxl-users > |