//浮点算法:Gray=R*0.3+G*0.59+B*0.11
void MainWindow::toGrayFloat(QImage *image, QImage *ImageBetter)
{
int height = image->height();
int width = image->width();
QRgb rgb00,rgb01;
int ta = 0, tr = 0, tg = 0, tb = 0;
for(int i = 0; i < width; i ++){
for(int j = 0; j < height; j ++){
rgb00 = image->pixel(i,j);//获取rgb
ta = (rgb00 >> 24) & 0xff;
tr = (rgb00 >> 16) & 0xff; // r = qRed(rgb00);
tg = (rgb00 >> 8) & 0xff; // g = qGreen(rgb00)
tb = rgb00 & 0xff; //b = qBlue(rgb00);
int gray = tr*0.3+tg*0.59+tb*0.11;
ImageBetter->setPixel(i,j,qRgb(gray,gray,gray));
}
}
}
//整数方法:Gray=(R*30+G*59+B*11)/100
void MainWindow::toGrayInt(QImage *image, QImage *ImageBetter)
{
int height = image->height();
int width = image->width();
QRgb rgb00,rgb01;
int ta = 0, tr = 0, tg = 0, tb = 0;
for(int i = 0; i < width; i ++){
for(int j = 0; j < height; j ++){
rgb00 = image->pixel(i,j);//获取rgb
ta = (rgb00 >> 24) & 0xff;
tr = (rgb00 >> 16) & 0xff; // r = qRed(rgb00);
tg = (rgb00 >> 8) & 0xff; // g = qGreen(rgb00)
tb = rgb00 & 0xff; //b = qBlue(rgb00);
int gray = (tr*30+tg*59+tb*11)/100;
ImageBetter->setPixel(i,j,qRgb(gray,gray,gray));
}
}
}
//.移位方法:Gray =(R*76+G*151+B*28)>>8;
void MainWindow::toGrayDisplacement(QImage *image, QImage *ImageBetter)
{
int height = image->height();
int width = image->width();
QRgb rgb00,rgb01;
int ta = 0, tr = 0, tg = 0, tb = 0;
for(int i = 0; i < width; i ++){
for(int j = 0; j < height; j ++){
rgb00 = image->pixel(i,j);//获取rgb
ta = (rgb00 >> 24) & 0xff;//
tr = (rgb00 >> 16) & 0xff; // r = qRed(rgb00);
tg = (rgb00 >> 8) & 0xff; // g = qGreen(rgb00);
tb = rgb00 & 0xff; //b = qBlue(rgb00);
int gray = (tr*76+tg*151+tb*28)>>8;
ImageBetter->setPixel(i,j,qRgb(gray,gray,gray));
}
}
}
//.平均值法:Gray=(R+G+B)/3;
void MainWindow::toGrayAverage(QImage *image, QImage *ImageBetter)
{
int height = image->height();
int width = image->width();
QRgb rgb00,rgb01;
int ta = 0, tr = 0, tg = 0, tb = 0;
for(int i = 0; i < width; i ++){
for(int j = 0; j < height; j ++){
rgb00 = image->pixel(i,j);//获取rgb
ta = (rgb00 >> 24) & 0xff;//
tr = (rgb00 >> 16) & 0xff; // r = qRed(rgb00);
tg = (rgb00 >> 8) & 0xff; // g = qGreen(rgb00);
tb = rgb00 & 0xff; //b = qBlue(rgb00);
int gray = (tr+tg+tb)/3;
ImageBetter->setPixel(i,j,qRgb(gray,gray,gray));
}
}
}
图像灰度化的四种方法
原创
©著作权归作者所有:来自51CTO博客作者303103757q的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
继承的四种方法
四种继承函数原型的方法
javascript 学习 -
终止线程的四种方法
正常运行结束 程序运行结束,线程自动结束。使用退出标志退出线程 一般 run()方法执行完,线程就会正常结束,然而,常常有些线程是伺服线程。它们需要
ide 阻塞状态 数据 java i++ -
创建线程的四种方法
第一种,继承Thread类创建线程,重写run方法。【通过观察Thread类源码,发现Th
多线程 i++ 线程池 执行时间 -
java循环判断条件符合就删除元素
一、Windows下GO开发环境的搭建及体验 使用GO前需要先搭建GO的开发环境,之前是在DEBIAN下安装了GO环境,现在WINDOWS用用看,作个简单的记录。下载解压安装/解压Golang,到下载地址:https://www.golangtc.com/download 找到对应的版本,我这里使用的是:Download and in
java循环判断条件符合就删除元素 windows golang go开发环境搭建 for循环