Page 1 of 1
Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T07:07:46-07:00
by kevin.mcguinness
I am trying to read a single channel integer pixel image from memory using the following
Code: Select all
Magick::Image image;
image.read(width, height, "K", Magick::IntegerPixel, data);
...
image.write("out.png");
The in memory image is a label mask, that usually contains just a few low pixel values (mostly
zero, a few patches of 1, 2 .. ) however, when saved the image appears as all zero. I tried
saving to the pgm format and also tried image.type(Magick::GrayscaleType) and
image.colorSpace(Magick::GRAYColorspace) but to no avail. Anyone have any idea what's wrong
here? Im using imagemagick 6.2.4
Thanks,
Kevin
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T07:31:48-07:00
by kevin.mcguinness
Actually this happens with char pixels too.. Just to clarify,
why does this piece of code produce a black image instead of
a white one?
Code: Select all
// Build an in memory grayscale image
int w = 100, h = 100;
int s = w * h;
std::vector<uint8_t> im(s);
// Make all pixels white
for (int i = 0; i < s; i++) im[i] = 255;
try {
// Load it into imagemagick
Magick::Image m;
m.read(w, h, "K", Magick::CharPixel, &im[0]);
// Save it as a png
m.write("test.png");
} catch (Magick::Exception& ex) {
cout << ex.what() << endl;
}
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T07:51:57-07:00
by magick
Try "G" instead of "K". "K" is the black channel whereas "G" is grayscale.
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T07:58:54-07:00
by kevin.mcguinness
Excellent, this works
Isn't "G" also the green channel? Wish that was in the documentation...
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T08:14:45-07:00
by kevin.mcguinness
Actually, this only worked for the pure white image
If i use the same code to make a pure black image (im
= 0), then
using "G" a pink image is produced. If i call m.type(Magick::GrayscaleType)
before read() i get a white image, if i call it after i get a gray image
Whats going on?
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T08:53:54-07:00
by magick
Doh! Not "G", its "I" for intensity. You are right, "G" is for green.
Re: Reading an IntegerPixel grayscale image from memory
Posted: 2007-05-31T09:17:28-07:00
by kevin.mcguinness
Fantastic, thanks!