Page 1 of 1
problems about Magick::Image API
Posted: 2008-06-26T06:06:45-07:00
by archer
I want to use ImageMagick only for decoding or encoding images of various formats, however, I am not sure how to access the matrix of pixels efficiently from an Image instance.
1. How to create an empty Image instance of some size, which will be used to hold a matrix of pixels later
2. How to import image data into an Image instance from a matrix, which has 0-3 bytes complement at the end of each row
3. How to export image data from an Image instance into a matrix?
Re: problems about Magick::Image API
Posted: 2008-06-26T07:26:48-07:00
by archer
I just want to use ImageMagick to read images files of various compression from disk, or to decode raw image data holden in memory buffers (may be similar with the Magick::Blob), and then get the image pixels for some image analysis task,
So is there any way easily to do that?
I have tried 'GetImagePixels' and 'SyncImagePixels' , unluckily, no header file seems to have stated them,
Even if the two functions above can do that, they still seems awkward.
So is there some easier way to fast transfer image pixels after decoded between the Image instance and user image matrix ?
Re: problems about Magick::Image API
Posted: 2008-06-26T10:04:04-07:00
by magick
Clarify which interface do you want to use: MagickCore, MagickWand, Magick++, PerlMagick, something else?
Re: problems about Magick::Image API
Posted: 2008-06-26T19:06:48-07:00
by archer
I used Magick++.
Here is the code:
#include<Magick++.h>
{
Magick::Blob blob(pBuf, nBufSize); //pBuf is a memory buffer holding the raw image data not yet decoded.
Magick::Image img;
try
{
img.read(blob);
}
catch (std::exception &)
{
return -1;
}
//now the "img" hold the pixel data after decoded? how to export the pixel data quickly into a matirx ?
}
On the other hand, when I want to encode an image matrix with "JPEG" format into a memory buffer,
how can I import the pixel data into the "img" (an instance of class Magick::Image) from an image matrix?
and what shoud be after that, is it like this:
{
Magick::Image img;
// what shoud be done to initialize the "img"? and how to import the pixel data from an image matrix into the "img" ?
Magick::Blob blob;
try
{
img.write(&blob, "JPEG");
}
catch (std::exception &)
{
}
memcpy(pBuf, blob.data(), blob.length());
}
I didn't know the how the class Magick::Image manages their internal memory stroage, why not provide with some API to direct access the data of the class Magick::Image, such as "data()" ?
Thanks!
Re: problems about Magick::Image API
Posted: 2008-06-26T19:24:28-07:00
by magick
Have you looked at
http://www.imagemagick.org/Magick++/Pixels.html? It discusses the low-level pixel methods. You also write to raw formats such as RGBA to create a linear array of pixels (width x height).
Re: problems about Magick::Image API
Posted: 2008-07-13T15:28:32-07:00
by kh263
This topic has been useful. Thanks all. By the way, what's the value of the try...catch in the code?
Re: problems about Magick::Image API
Posted: 2008-07-13T15:31:37-07:00
by kh263
archer,
did the code work for you? if not, can you show me the code that did work?
thanks