Read/Write portion of image from/to file
Read/Write portion of image from/to file
Hi everyone!
I need to process really big images in C++. So I would like to read only a portion of an image from file using Magick++ API, process it, and write that portion back to file. I would process each chunk in turn until the entire image has been processed.
Is there a way to read and write only portions of file using Magick++ API?
Many thanks!
Julie
I need to process really big images in C++. So I would like to read only a portion of an image from file using Magick++ API, process it, and write that portion back to file. I would process each chunk in turn until the entire image has been processed.
Is there a way to read and write only portions of file using Magick++ API?
Many thanks!
Julie
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Read/Write portion of image from/to file
I do not know what can be done using Magick++. But see
http://www.imagemagick.org/Usage/files/#massive
http://www.imagemagick.org/Usage/formats/#jpg_read
http://www.imagemagick.org/script/stream.php
http://www.imagemagick.org/Usage/files/#massive
http://www.imagemagick.org/Usage/formats/#jpg_read
http://www.imagemagick.org/script/stream.php
Re: Read/Write portion of image from/to file
Thank you very much for your answer. It was very interesting.
However, I don't think this approach would work for me. The problem is that I'm developing a software written in C++ and I can't assume the users of my software will have imagemagick installed on their own machine... That's why I would need a way to do the exact same thing that is described in those links but using Magick++.
Thank you anyway!
Julie
However, I don't think this approach would work for me. The problem is that I'm developing a software written in C++ and I can't assume the users of my software will have imagemagick installed on their own machine... That's why I would need a way to do the exact same thing that is described in those links but using Magick++.
Thank you anyway!
Julie
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Read/Write portion of image from/to file
Yes, I understand, but do not know Magick++. Perhaps some one who uses Magick++ can advise you on that.
Re: Read/Write portion of image from/to file
Thank you very much.
So I tried to make this work with the Image Cache Methods (see the docs at http://www.imagemagick.org/Magick++/Ima ... l%20Access) but did not succeed yet. In particular, I have been trying to use the functions setPixels() and readPixels(). If I understand things correctly, after a call to setPixels(), I should be able to read only a portion of a file using readPixels(). That function takes "unsigned char *source_" as an argument. What exactly should be that source if I want to read directly from file (and not from a buffer)?
Many thanks for your help!
Julie
So I tried to make this work with the Image Cache Methods (see the docs at http://www.imagemagick.org/Magick++/Ima ... l%20Access) but did not succeed yet. In particular, I have been trying to use the functions setPixels() and readPixels(). If I understand things correctly, after a call to setPixels(), I should be able to read only a portion of a file using readPixels(). That function takes "unsigned char *source_" as an argument. What exactly should be that source if I want to read directly from file (and not from a buffer)?
Many thanks for your help!
Julie
Re: Read/Write portion of image from/to file
Here's what we are planning to do:
Read the entire big image using Image img = read( filename ) and then have access to the desired portion of the file using img.getConstPixels(). (The way we understand things is that ImageMagick itself should take care of swapping to disk when it's out of memory.)
Julie
Read the entire big image using Image img = read( filename ) and then have access to the desired portion of the file using img.getConstPixels(). (The way we understand things is that ImageMagick itself should take care of swapping to disk when it's out of memory.)
Julie
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Read/Write portion of image from/to file
I use MagickCore, the lower-level interface. As I understand it, IM reads the entire image into memory, swapping it as required. Then I access whatever rectangles I want. Typically, a rectangle is one entire line of the image. IM swaps data to and from disk as required, but I try to avoid swapping.
The exception is large MPC files. These are memory-mapped, so IM directly accesses the disk for each rectangle, so there is no swapping, and everything is much faster. When I am playing with large images (greater than about 1 G pixels), I first convert to an MPC file.
The exception is large MPC files. These are memory-mapped, so IM directly accesses the disk for each rectangle, so there is no swapping, and everything is much faster. When I am playing with large images (greater than about 1 G pixels), I first convert to an MPC file.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Read/Write portion of image from/to file
I do not know if this will help, but see http://www.imagemagick.org/script/archi ... php#stream
see also Best Practices under this topic http://www.imagemagick.org/script/archi ... .php#cache for notes about MPC format and IM environment variables for -limit
see also Best Practices under this topic http://www.imagemagick.org/script/archi ... .php#cache for notes about MPC format and IM environment variables for -limit
Re: Read/Write portion of image from/to file
Thanks to both of you! Your answers helped me a lot!
Julie
Julie
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Read/Write portion of image from/to file
Let us know what you finally did that worked for you.
Re: Read/Write portion of image from/to file
For now, we are planning on letting IM handle the swapping. Then, if we have performance issue, we will look into more fancy stuff.
I will keep you posted!
Again, thanks for your help!
Julie
I will keep you posted!
Again, thanks for your help!
Julie
Re: Read/Write portion of image from/to file
Hi there,
Here are news about how things are going... As described above, we decided to let IM handle the swapping. We had a round of beta releases and now, the product is finally out. It seems that all of our users are happy with the way IM handle big images!
Thanks!
Julie
Here are news about how things are going... As described above, we decided to let IM handle the swapping. We had a round of beta releases and now, the product is finally out. It seems that all of our users are happy with the way IM handle big images!
Thanks!
Julie