Page 1 of 1
How to import grayscale blob?
Posted: 2009-06-24T06:37:22-07:00
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
Re: How to import grayscale blob?
Posted: 2009-06-24T06:47:43-07:00
by magick
Look for Magick++/tests/readWriteBlob.cpp in the ImageMagick source distribution as an example of how to read images from a blob.
Re: How to import grayscale blob?
Posted: 2009-06-24T08:49:33-07:00
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
Re: How to import grayscale blob?
Posted: 2009-06-24T10:47:26-07:00
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.
Re: How to import grayscale blob?
Posted: 2009-06-25T03:04:53-07:00
by Dolax
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;
}
Re: How to import grayscale blob?
Posted: 2011-06-24T09:53:23-07:00
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.
Re: How to import grayscale blob?
Posted: 2011-06-24T10:23:07-07:00
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!
Re: How to import grayscale blob?
Posted: 2011-06-24T10:37:02-07:00
by mika
answering myself: that was a depth problem that was 16 where it should have been 8