0

各ピクセルからRGBを取得しようとしています。しかし、C++コードを実行すると、このような赤い色のシェルに乗ります

55512

55255

55255

期待した 0 から 255 までの数値ではないのはなぜですか?

これは私のコードです

Image image("image_test.jpg");
int w = image.columns();
int h = image.rows();

// get a "pixel cache" for the entire image
PixelPacket *pixels = image.getPixels(0, 0, w, h);

// now you can access single pixels like a vector
int row = 0;
int column = 0;
Color color = pixels[w * row + column];


for(row=0; row<h-1; row++){
          for(column=0; column<w-1; column++){
            Color color = pixels[w * row + column];
            cout<<pixels[w * row + column].red;
            image.syncPixels();
          }
        }
//image.syncPixels();

// write the image to file.
//image.write("test_modified.jpg");
4

1 に答える 1

0

ピクセル パケットをシステムの Quantum Depth から必要な形式に変換するには、少し計算する必要があります。

Image image("image_test.jpg");
int w = image.columns();
int h = image.rows();
// Calc what your range is. See http://www.imagemagick.org/Magick++/Color.html
// There's also other helpful macros, and definitions in ImageMagick's header files
int range = pow(2, image.modulusDepth());
assert(range > 0); // Better do some assertion/error checking here
// get a "pixel cache" for the entire image
PixelPacket *pixels = image.getPixels(0, 0, w, h);

// now you can access single pixels like a vector
int row = 0;
int column = 0;
Color color = pixels[w * row + column];


for(row=0; row<h-1; row++){
  for(column=0; column<w-1; column++){
    Color color = pixels[w * row + column];
      cout << (color.redQuantum() / range) << endl;
    }
}
于 2015-01-26T14:24:03.243 に答える