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
How to import grayscale blob?
Re: How to import grayscale blob?
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?
Hello magick,magick wrote:Look for Magick++/tests/readWriteBlob.cpp in the ImageMagick source distribution as an example of how to read images from a blob.
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?
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?
Yes, I read the tutorial as well as the documentation.magick wrote:Have you read http://www.imagemagick.org/Magick++/tut ... torial.pdf? There is a brief section on blobs there.
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.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.
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?
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.
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?
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!
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?
answering myself: that was a depth problem that was 16 where it should have been 8