How to import grayscale blob?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Dolax

How to import grayscale blob?

Post by Dolax »

Hello!

Is it possible to create a new image from an in memory grayscale data-array with Magick++?

From documentation I know there is image.read() method, but I don't know how to set the correct encoding format.

With best thanks,
Dolax
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to import grayscale blob?

Post by magick »

Look for Magick++/tests/readWriteBlob.cpp in the ImageMagick source distribution as an example of how to read images from a blob.
Dolax

Re: How to import grayscale blob?

Post by Dolax »

magick wrote:Look for Magick++/tests/readWriteBlob.cpp in the ImageMagick source distribution as an example of how to read images from a blob.
Hello magick,

thanks for your quick answer! I know how to create a new Blob from a given Image File, but in my case its different. I try to convert/import a grayscale IplImage from OpenCV to ImageMagick. So what I have is a char* full of gray values and a geometry.
If I try to make a Blob from this, I get the Error
terminate called after throwing an instance of 'Magick::ErrorMissingDelegate'
what(): ImageMagick: no decode delegate for this image format `' @ blob.c/BlobToImage/347
Aborted

So maybe there is a magick string that tells the method about my encoding?

Or maybe there is a character for "map_" from image.read(const unsigned int width_, const unsigned int height_, std::string map_, const StorageType type_, const void *pixels_) that tells this method there are only gray values?

Kind regards,
Dolax
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How to import grayscale blob?

Post by magick »

Have you read http://www.imagemagick.org/Magick++/tut ... torial.pdf? There is a brief section on blobs there. Basically all you need to do is set the image.magick() to gray, set the image size and the image depth then read the blob.
Dolax

Re: How to import grayscale blob?

Post by Dolax »

magick wrote:Have you read http://www.imagemagick.org/Magick++/tut ... torial.pdf? There is a brief section on blobs there.
Yes, I read the tutorial as well as the documentation.
magick wrote:Basically all you need to do is set the image.magick() to gray, set the image size and the image depth then read the blob.
That is the information I was looking for. Many thanks! I could not find a list or something describing in detail all the possibilities of magick string.

Now my code works. I post it here, maybe some day someone else want to convert from OpenCV Image:

Code: Select all

Magick::Image yourClass::OpenCV2Magick(const IplImage* ipl) const
{
    Magick::Image img;
    Magick::Blob blob(ipl->imageData, ipl->imageSize);
    img.size(Magick::Geometry(ipl->widthStep, ipl->height));
    img.depth(ipl->depth);
    if (strcmp(ipl->colorModel, "GRAYGRAY")==0.0) {
        img.magick( "gray" );
    }
    else {
        img.magick( "BGR" );
    }
    img.read(blob);
    img.crop(Magick::Geometry(ipl->width, ipl->height));
    img.page("0x0+0+0");
    return img;
}
mika

Re: How to import grayscale blob?

Post by mika »

Hello!

I used your function as is, but i always get this exception on the read(blob) line which says:
terminate called after throwing an instance of 'Magick::ErrorMissingDelegate'
what(): Magick: no decode delegate for this image format `' @ error/blob.c/BlobToImage/349

Any idea why that would be?

Many thx in advance!!

mika.
mika

Re: How to import grayscale blob?

Post by mika »

Actually that's not exactly right, i used the cv::Mat structure and replaced:
ipl->imageData with cv_mat.ptr(0)
ipl->widthStep with cv_mat.cols
ipl->height with cv_mat.rows
ipl->depth with cv_mask.channels()
and i hard-set magick_im.magick( "gray" )

So i guess this post would have a better place in an opencv forum, if there would have been one. Sorry about that.

An answer is welcome anyway though!
mika

Re: How to import grayscale blob?

Post by mika »

answering myself: that was a depth problem that was 16 where it should have been 8
Post Reply