简体   繁体   English

将图像读取到数组或矩阵

[英]Reading image to an array or matrix

I am a newbie to c++. 我是C ++的新手。 I am using it for image processing. 我正在使用它进行图像处理。 My basic idea is to load an image and store the pixel values or intensities into a matrix or an array, so that i can perform further manipulations on them. 我的基本想法是加载图像并将像素值或强度存储到矩阵或数组中,以便我可以对它们执行进一步的操作。

So, what i have done so far is 所以,到目前为止我所做的是

  QPixmap pixmap("lena.bmp");
  pixmap = pixmap.copy(512,512,128,128);
  pixmap = pixmap.scaled(32,32);
  QImage image = pixmap.toImage();
  QRgb col;

  int g;
  int width = pixmap.width();
  int height = pixmap.height();
  matrix<double> m(width,height);

for (int j = 0; j < m.size2(); j++)
{
    for (int i = 0; i < m.size1(); i++)
    {
        col = image.pixel(i,j);
        g = qGray(col);

        image.setPixel(i,j,qRgb(g,g,g));
        m(i,j) = (image.pixel(i,j));

    }
}

for instance here i use Qpixmap in Qt for reading image and use boost to generate a matrix with the data. 例如,在这里我在Qt中使用Qpixmap读取图像,并使用boost生成具有数据的矩阵。

But is there any other simpler way to read the image and to store it in a matrix? 但是,还有其他更简单的方法可以读取图像并将其存储在矩阵中吗? and perform manipulations and then display the new manipulated matrix as an image? 并执行操作,然后将新的操作矩阵显示为图像?

You could use OpenCV library, where images are by default represented as matrixes. 您可以使用OpenCV库,默认情况下,图像以矩阵形式表示。 OpenCV is very popular for image manipulation, and has many features. OpenCV在图像处理中非常流行,并且具有许多功能。 You can grab an example of loading image to matrix in OpenCV here: http://docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html 您可以在以下示例中获取在OpenCV中将图像加载到矩阵中的示例: http : //docs.opencv.org/doc/tutorials/introduction/display_image/display_image.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM