I'm quite new to Magic++. I try to create some geometry depending on a color/luminance value of an image file at a certain position.
To test my code I simply built a loop to read out pixels at a certain uv position.
My testimage is a simple checker image with 10 tiles (5 black 5 white) in one row and 10 rows.
The image is 1000 pixels in square. This means the first black square goes from 0,0 ot 100,100.
Okay if I now check the pixel color for 19,59 I get a full white what is definitly not correct.
At position 20, 60 I get the correct value of black. Again at 21, 61 the result is wrong.
I suppose my code is somehow wrong. Maybe anyone can give me a hint? Thanks a lot.
Code: Select all
#include <Magick++.h>
#include <string>
#include <iostream>
using namespace std;
using namespace Magick;
int main( int /*argc*/, char ** argv)
{
// Initialize ImageMagick install location for Windows
InitializeMagick(*argv);
try {
Image image("C:/daten/Test/sourceimages/checker.tif");
// Ensure that there are no other references to this image.
image.modifyImage();
// Set the image type to TrueColor DirectClass representation.
image.type(TrueColorType);
int rows = image.rows() - 1;
int columns = image.columns() - 1;
fprintf(stdout, "col %d row %d\n", image.rows(), image.columns());
const MagickLib::PixelPacket *pixel_cache = image.getConstPixels(0,0,columns,rows);
int column = columns / 2;
int row = rows / 2;
int x = 19;
int y = 59;
const MagickLib::PixelPacket *pixel = pixel_cache+x*y+x;
float value = (pixel->red + pixel->green + pixel->blue) / 3.0 / 65535;
fprintf(stdout, "Final Value: %f at coord: %d %d red: %d green: %d, blue: %d \n", value, x, y, pixel->red, pixel->green, pixel->blue );
x = 20;
y = 60;
pixel = pixel_cache+x*y+x;
value = (pixel->red + pixel->green + pixel->blue) / 3.0 / 65535;
fprintf(stdout, "Final Value: %f at coord: %d %d red: %d green: %d, blue: %d \n", value, x, y, pixel->red, pixel->green, pixel->blue );
}
catch( exception &error_ )
{
cout << "Caught exception: " << error_.what() << endl;
return 1;
}
return 0;
}