
Hi, I wrapped boost::gil::rgb8_image_t::view_t as a simple class Image: class Image { public: // ... some methods here. private: boost::gil::rgb8_image_t::view_t view; }; And I have a method Crop, which is crop image to other image object, like this: void Image::Crop(int x, int y, int width, int height, Image& out) const { boost::gil::rgb8_image_t s(width, height); boost::gil::copy_pixels( boost::gil::subimage_view(view, x, y, width, height), boost::gil::view(s)); out.view = boost::gil::view(s); } I will get error after I run this code... But I can't understand what's wrong. So, how can I implement this? Thank you very much. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Hi there, you're passing an Image into your and override the view
member with a view to the a local gil::image. After the crop function
is done this local image is destroyed the the view to that image now
points to garbage.
Also it's unclear to me how you initialize the view member in your Image class.
This works on my machine:
#include

Hi, Thanks for your reply, I initialize view member using io extension to read image file. I try to create a local rgb8_image_t in crop method because I have another method fill. It look like this: Image& Image::Fill(int x1, int y1, int x2, int y2, int r, int g, int b) { boost::gil::rgb8_pixel_t pixel(r, g, b); boost::gil::fill_pixels( boost::gil::subimage_view(view, x1, y1, x2 - x1, y2 - y1), pixel); return *this; } But when I do this: Image a("a.png"); Image b; a.crop(100, 100, 50, 50, b); a.fill(100, 100, 50, 50, 0xff, 0xff, 0xff); I found that b will be also filled with white color. So, I try to "copy" all pixels from a to b. copy_pixels requires two view with the same dimension, but I can't change dimension of a view directly, that is why I create a local rgb8_image_t to do that. Now, I clarify my requirement. I need to do this: Image a("a.png"); Image b; a.crop(100, 100, 50, 50, b); a.fill(100, 100, 50, 50, 0xff, 0xff, 0xff); a and b are now with independent view. a.fill should not affect b. How can I do that? Thank you! -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Quick question. Why don't you use the gil::image type as the member instead of the gil::view? Doesn't that make more sense? I would argue that your Image class should also be able to recreate or destroy its pixels. Meaning own the pixels. Christian

Good question, ha :) That is because I don't know how to implement crop method if I only have rgb8_image_t member. How do I use subimage_view to change a rgb8_image_t? Always make a copy? Thanks. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Oh, I forgot to say, I have two version crop method. One is void Crop(int x, int y, int width, int height, Image& out) const This should make a copy to out. Another is void Crop(int x, int y, int width, int height) This should crop image in-place. I don't know how to implement second version if I only have rgb8_image_t member because I don't know how to use subimage_view to do that. Thank you. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

You can create a view from an image like this: rgb8_image_t img( 100, 100 ); rgb8_view_t v = view( img ); Creating a view is very cheap and shouldn't produce any overhead. To create a subview do this: rgb8_image_t img( 100, 100 ); rgb8_view_t sv = subimage_view( view( img ), 0, 0, 100, 100 ); Hope that helps, Christian

Hi, Thanks for your reply, I knew that. Oh, let me clarify what problem I actually have: Consider the class Image: class Image { public: Image() { } Image(std::string& file) { // using io extension to read image. // ... } Image(const Image& other) { img = other.img; // view = boost::gil::view(img); view = other.view; } Image& Image::Crop(int x, int y, int width, int height) { view = boost::gil::subimage_view(view, x, y, width, height); return *this; } void Image::Crop(int x, int y, int width, int height, Image& out) const { out = *this; out.Crop(x, y, width, height); } Image& Image::Fill(int x1, int y1, int x2, int y2, int r, int g, int b) { boost::gil::rgb8_pixel_t pixel(r, g, b); boost::gil::fill_pixels( boost::gil::subimage_view(view, x1, y1, x2 - x1, y2 - y1), pixel); return *this; } private: boost::gil::rgb8_image_t img; boost::gil::rgb8_image_t::view_t view; }; Image a("a.png"); // 100x100 size. a.Crop(100, 100, 50, 50); // Now, the a should be 50x50 size. Image b; a.Crop(0, 0, 10, 10, b); // b should be 10x10. a.Fill(0, 0, 10, 10, 0xff, 0xff, 0xff); // This will cause b also filled with white color. How to change my Image class to make a.Fill not to affect b? Thank you very much. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Hi there, you are overriding b's view member when calling a.Crop(0, 0, 10, 10, b) with a's view. They both have different dimensions, but there are pointing to the same memory. I don't really understand why you have a class "Image" with an gil::image and gil::view members. I would not have a gil::view member but would create one when I need one. Also, do you really need to have Image class? Isn't gil::image enough for your purposes? Christian

Mm... If I only have rgb8_image_t member, I don't know how to implement Crop method. void Image::Crop(int x, int y, int width, int height, Image& out) { // Cropped view. rgb8_image_t::view_t view = subimage_view(view(img), x, y, width, height); out.img = .... // I don't know how to do that... How to assign a view to a image??? } I need a Image class because I am writing a simple class library for our partner, they are using other languages such as python. Thanks for your help. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Why not return a view from crop?
On Tue, Apr 28, 2009 at 12:14 PM, blp330
Mm... If I only have rgb8_image_t member, I don't know how to implement Crop method.
void Image::Crop(int x, int y, int width, int height, Image& out) { // Cropped view. rgb8_image_t::view_t view = subimage_view(view(img), x, y, width, height);
out.img = .... // I don't know how to do that... How to assign a view to a image??? }
I need a Image class because I am writing a simple class library for our partner, they are using other languages such as python.
Thanks for your help. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Because I need to wrap GIL's type from my library. I need this: Image a("a.png"); Image b; a.Crop(0, 0, 100, 100, b); if I return view, it will look like this: Image a("a.png"); boost::gil::view v = a.Crop(0, 0, 100, 100); But only Image class is exported from my library for other languages to use. I know that is just for my purpose, I need to know a way to assign a view to image to implement Crop method if I only have rgb8_image_t member or to know a way to copy view. Thank you very much. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

What is the crop function which takes an image as a parameter suppose to do?
On Tue, Apr 28, 2009 at 12:56 PM, blp330
Because I need to wrap GIL's type from my library.
I need this:
Image a("a.png"); Image b;
a.Crop(0, 0, 100, 100, b);
if I return view, it will look like this:
Image a("a.png"); boost::gil::view v = a.Crop(0, 0, 100, 100);
But only Image class is exported from my library for other languages to use.
I know that is just for my purpose, I need to know a way to assign a view to image to implement Crop method if I only have rgb8_image_t member or to know a way to copy view.
Thank you very much. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Because I want to make a copy of cropped image. I can do this: Image a("a.png"); Image b; a.Crop(0, 0, 100, 100, b); // Now b is copied 100x100 size image from a. Or Image a("a.png"); Image *b = a.Crop(0, 0, 100, 100); // This might be another way. Or Image a("a.png"); Image b(a, 0, 0, 100, 100); Whatever, I need a way to copy cropped image from a to b. So, if I have a rgb8_image_t and a cropped view, how do I assign a view to a rgb8_image_t? Thanks for your patient. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Because I want to make a copy of cropped image. I can do this: Image a("a.png"); Image b; a.Crop(0, 0, 100, 100, b); // Now b is copied 100x100 size image from a. Or Image a("a.png"); Image *b = a.Crop(0, 0, 100, 100); // This might be another way. Or Image a("a.png"); Image b(a, 0, 0, 100, 100); Whatever, I need a way to copy cropped image from a to b. So, if I have a rgb8_image_t and a cropped view, how do I assign a view to a rgb8_image_t? Thanks for your patient. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.

Because I want to make a copy of cropped image. I can do this: Image a("a.png"); Image b; a.Crop(0, 0, 100, 100, b); // Now b is copied 100x100 size image from a. Or Image a("a.png"); Image *b = a.Crop(0, 0, 100, 100); // This might be another way. Or Image a("a.png"); Image b(a, 0, 0, 100, 100); Whatever, I need a way to copy cropped image from a to b. So, if I have a rgb8_image_t and a cropped view, how do I assign a view to a rgb8_image_t? Thanks for your patient. -- View this message in context: http://www.nabble.com/-GIL--How-can-I-copy-a-subimage_view-to-a-view--tp2323... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (2)
-
blp330
-
Christian Henning