Qt QImage 灰度图转单色图

 1 //将灰度图转换为单色图
 2 QImage MainWindow::GrayToFluoImage(const QImage image, int cR, int cG, int cB)
 3 {
 4     quint64 w = image.width();
 5     quint64 h = image.height();
 6     if(image.isNull())
 7     {
 8         return QImage();
 9     }
10     QImage resImage(w, h, QImage::Format_RGB32);
11     //qDebug() << "Color:" << cR << cG << cB;
12     for (qint64 y = 0; y < h; ++y)
13     {
14         for (qint64 x = 0; x < w; ++x)
15         {
16             QRgb dataI1 = image.pixel(x, y);
17             double tM = qGray(dataI1);
18             double tR = (tM / 255.0) * (double)(cR / 255.0);
19             double tG = (tM / 255.0) * (double)(cG / 255.0);
20             double tB = (tM / 255.0) * (double)(cB / 255.0);
21             resImage.setPixel(x, y, qRgb(255*tR, 255*tG, 255*tB));
22         }
23     }
24     return resImage;
25 }
原文地址:https://www.cnblogs.com/ybqjymy/p/13595605.html