本文整理汇总了C++中qGray函数的典型用法代码示例。如果您正苦于以下问题:C++ qGray函数的具体用法?C++ qGray怎么用?C++ qGray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了qGray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: diff_images
void diff_images(QImage *image1, QImage *image2, QString fileName)
{
// TODO: Check images size
QImage* image3 = new QImage(image1->size(), QImage::Format_RGB32);
for (int i = 0; i < image1->size().width(); i++) {
for (int j = 0; j < image1->size().height(); j++) {
int p1 = qGray(image1->pixel(i,j));
int p2 = qGray(image2->pixel(i,j));
int p3 = p1-p2;
double fSigma = 0.4 * 25.0;
double diff = (static_cast<double>(p3)+ fSigma) * 255.0 / (2.0 * fSigma);
if (diff < 0.0) diff = 0;
if (diff > 255.5) diff = 255;
p3 = diff;
image3->setPixel(i,j,qRgb(p3,p3,p3));
}
}
QImageWriter* imageDiff = new QImageWriter();
imageDiff->setFileName(fileName);
imageDiff->write(*image3);
delete image3;
delete imageDiff;
}
示例2: ii
void KIconEffect::toGray(QImage &img, float value)
{
if (value == 0.0) {
return;
}
KIEImgEdit ii(img);
QRgb *data = ii.data;
QRgb *end = data + ii.pixels;
unsigned char gray;
if (value == 1.0) {
while (data != end) {
gray = qGray(*data);
*data = qRgba(gray, gray, gray, qAlpha(*data));
++data;
}
} else {
unsigned char val = (unsigned char)(255.0 * value);
while (data != end) {
gray = qGray(*data);
*data = qRgba((val * gray + (0xFF - val) * qRed(*data)) >> 8,
(val * gray + (0xFF - val) * qGreen(*data)) >> 8,
(val * gray + (0xFF - val) * qBlue(*data)) >> 8,
qAlpha(*data));
++data;
}
}
}
示例3: qGray
void UIMachineView::dimImage(QImage &img)
{
for (int y = 0; y < img.height(); ++ y)
{
if (y % 2)
{
if (img.depth() == 32)
{
for (int x = 0; x < img.width(); ++ x)
{
int gray = qGray(img.pixel (x, y)) / 2;
img.setPixel(x, y, qRgb (gray, gray, gray));
}
}
else
{
::memset(img.scanLine (y), 0, img.bytesPerLine());
}
}
else
{
if (img.depth() == 32)
{
for (int x = 0; x < img.width(); ++ x)
{
int gray = (2 * qGray (img.pixel (x, y))) / 3;
img.setPixel(x, y, qRgb (gray, gray, gray));
}
}
}
}
}
示例4: threshold_img
void sliders_group::update_img() {
// slider->setValue(value);
int i, j ;
// this->setTitle(QString::number(value));
QImage threshold_img(*img);
for (i = 0; i < img->width(); i++) {
for (j = 0; j < img->height(); j++) {
int pixel_intensity = qGray(img->pixel(i,j));
threshold_img.setPixel(i,j,qRgb(0,0,0));
if (pixel_intensity > slider1_value) {
threshold_img.setPixel(i,j,qRgb(255/2,0,0));
}
if (pixel_intensity > slider2_value) {
int th_pixel_intensity = qGray(img->pixel(i,j));
threshold_img.setPixel(i,j,qRgb(th_pixel_intensity,th_pixel_intensity,255/2));
}
}
}
threshold_img_label->setPixmap(QPixmap::fromImage(threshold_img));
}
示例5: if
bool WBMPReader::writeImage(QImage image)
{
if (image.format() != QImage::Format_Mono)
image = image.convertToFormat(QImage::Format_Mono);
if (image.colorTable().at(0) == image.colorTable().at(1)) {
// degenerate image: actually blank.
image.fill((qGray(image.colorTable().at(0)) < 128) ? 0 : 1);
} else if (qGray(image.colorTable().at(0)) > qGray(image.colorTable().at(1))) {
// Conform to WBMP's convention about black and white
image.invertPixels();
}
hdr.type = 0;
hdr.format = 0;
hdr.width = image.width();
hdr.height = image.height();
if (!writeWBMPHeader(iodev, hdr))
return false;
if (!writeWBMPData(iodev, image))
return false;
return true;
}
示例6: qGray
int Widget::getConnectedComponentLabeling()
{
int i, j;
int currlabel = 1;
int label;
int a[4];
for(j=1; j<rsltImg.height()-1; j++){
for(i=1; i<rsltImg.width()-1; i++){
// 8 connected
if( qGray(rsltImg.pixel(i,j)) != 0 )
{
a[0] = qGray(rsltImg.pixel(i-1,j-1));
a[1] = qGray(rsltImg.pixel(i,j-1));
a[2] = qGray(rsltImg.pixel(i+1,j-1));
a[3] = qGray(rsltImg.pixel(i-1,j));
label = MyMin(a);
if(label != 0 && label != 255){
rsltImg.setPixel(i, j, qRgb(label, label, label));
}
else{
rsltImg.setPixel(i, j, qRgb(currlabel, currlabel, currlabel));
currlabel++;
}
}
}
}
return (currlabel-1);
}
示例7: qDebug
void CustomizeThemeDialog::toggleCustomColors(bool b)
{
qDebug() << Q_FUNC_INFO << b;
SettingsPrivate *settings = SettingsPrivate::instance();
settings->setCustomColors(b);
for (int i = 0; i < customColorsGridLayout->rowCount(); i++) {
for (int j = 0; j < customColorsGridLayout->columnCount(); j++) {
QLayoutItem *item = customColorsGridLayout->itemAtPosition(i, j);
if (item->widget()) {
item->widget()->setEnabled(b);
}
}
}
if (b) {
qDebug() << Q_FUNC_INFO << settings->customColors(QPalette::Base) << settings->customColors(QPalette::Highlight);
bgPrimaryColorWidget->setColor(settings->customColors(QPalette::Base));
selectedItemColorWidget->setColor(settings->customColors(QPalette::Highlight));
} else {
QColor base = style()->standardPalette().base().color();
QColor highlight = style()->standardPalette().highlight().color();
int gray = qGray(base.rgb());
bgPrimaryColorWidget->setColor(QColor(gray, gray, gray));
gray = qGray(highlight.rgb());
selectedItemColorWidget->setColor(QColor(gray, gray, gray));
QApplication::setPalette(style()->standardPalette());
}
}
示例8: Q_D
//-----------------------------------------------------------------------------
QVariant ctkVTKColorTransferFunction::maxValue()const
{
Q_D(const ctkVTKColorTransferFunction);
if (d->ColorTransferFunction.GetPointer() == 0)
{
//Q_ASSERT(d->ColorTransferFunction.GetPointer());
logger.warn("no ColorTransferFunction");
return -1;
}
double rgb[3];
QColor minValue = QColor::fromRgbF(0.,0.,0.);
for (int i = 0; i < this->count(); ++i)
{
d->ColorTransferFunction->GetColor(i, rgb);
Q_ASSERT(rgb[0] >= 0. && rgb[0] <= 1. &&
rgb[1] >= 0. && rgb[1] <= 1. &&
rgb[2] >= 0. && rgb[2] <= 1.);
QColor color = QColor::fromRgbF(rgb[0], rgb[1], rgb[2]);
if ( qGray(color.red(), color.green(), color.blue()) >
qGray(minValue.red(), minValue.green(), minValue.blue()))
{
minValue = color;
}
}
return minValue;
}
示例9: if
int Etude::verifierToleranceNiveauxDeGris(const QRgb& couleurCourante, const QRgb& couleurReference,
const int& seuilToleranceNiveauxDeGris) const
{
if (qGray(couleurCourante) < (qGray(couleurReference) - seuilToleranceNiveauxDeGris))
return NIVEAU_DE_GRIS_INFERIEUR;
else if (qGray(couleurCourante) > (qGray(couleurReference) + seuilToleranceNiveauxDeGris))
return NIVEAU_DE_GRIS_SUPERIEUR;
return NIVEAU_DE_GRIS_COMPATIBLE;
}
示例10: window
/** Returns a size x size part of the image centered around (x,y) */
math::matrix<double> Transformation::getWindow(int x, int y, int size,
Channel channel,
Mode mode = RepeatEdge)
{
math::matrix<double> window(size, size);
int columnCount = floor(size/2);
int a = 0;
int b = 0;
if(size % 2 == 0)
{
for (int i = -columnCount; i < columnCount; i++)
{
for (int j = -columnCount; j < columnCount; j++)
{
if(channel == RChannel)
window(a, b) = qRed(getPixel(x + i, y + j, mode));
else if(channel == GChannel)
window(a, b) = qGreen(getPixel(x + i, y + j, mode));
else if(channel == BChannel)
window(a, b) = qBlue(getPixel(x + i, y + j, mode));
else if(channel == LChannel)
window(a, b) = qGray(getPixel(x + i, y + j, mode));
b++;
}
a++;
b = 0;
}
}
else
{
for (int i = -columnCount; i <= columnCount; i++)
{
for (int j = -columnCount; j <= columnCount; j++)
{
if(channel == RChannel)
window(a, b) = qRed(getPixel(x + i, y + j, mode));
else if(channel == GChannel)
window(a, b) = qGreen(getPixel(x + i, y + j, mode));
else if(channel == BChannel)
window(a, b) = qBlue(getPixel(x + i, y + j, mode));
else if(channel == LChannel)
window(a, b) = qGray(getPixel(x + i, y + j, mode));
b++;
}
a++;
b = 0;
}
}
return window;
}
示例11: QImage
QImage Pdf::binarization(QImage image){
QImage bw = QImage(image.width(), image.height(), QImage::Format_MonoLSB);
QVector<QRgb> ct(2);
ct[0] = qRgb(255, 255, 255);
ct[1] = qRgb(0, 0, 0);
bw.setColorTable(ct);
bw.fill(0);
float thresh = 128;
float new_thresh = 0;
while (thresh != new_thresh) {
float sum_black = 0;
float sum_white = 0;
int num_black = 0;
int num_white = 0;
new_thresh = thresh;
for (int x = 0; x < image.width(); x++){
for (int y = 0; y < image.height(); y++) {
QRgb c = image.pixel(x, y);
float g = qGray(c);
if (g < thresh) {
sum_black += g;
num_black++;
}
else {
sum_white += g;
num_white++;
}
}
}
thresh = (sum_black/num_black + sum_white/num_white)/2.0;
}
int stride = (bw.width() + 7) / 8;
uchar* p = bw.bits();
for (int y = 0; y < bw.height(); ++y) {
p = bw.scanLine(y);
for (int x = 0; x < stride; ++x) {
int temp = 0;
for (int i = 0; i < 8; i++) {
if (x*8 + i >= bw.width()) continue;
QRgb c = image.pixel(x*8 + i, y);
float g = qGray(c);
temp += ((g<thresh) ? 1:0)<<i;
}
*p++ = temp;
}
}
return bw;
}
示例12: qGray
int Sobel::calculateSobel(ushort x, ushort y)
{
int pixels[9]; //Pixels around the scoped pixel
//get the pixel values
// 0 1 2
// 3 4 5
// 6 7 8
pixels[0] = qGray(image->pixel(x - 1, y - 1));
pixels[1] = qGray(image->pixel(x, y - 1));
pixels[2] = qGray(image->pixel(x + 1, y - 1));
pixels[3] = qGray(image->pixel(x - 1, y));
//pixels[4] is not needed
pixels[5] = qGray(image->pixel(x + 1, y));
pixels[6] = qGray(image->pixel(x - 1, y + 1));
pixels[7] = qGray(image->pixel(x, y + 1));
pixels[8] = qGray(image->pixel(x + 1, y + 1));
//TODO Check if optimization is needed
int hsobel = pixels[0] + (pixels[3] * 2) + pixels[6]
- pixels[2] - (pixels[5] * 2) - pixels[8];
int vsobel = pixels[0] + (pixels[1] * 2) + pixels[3]
- pixels[6] - (pixels[7] * 2) - pixels[8];
int res = vsobel + hsobel;
if(res < 0) {res *= -1;}
return res;
}
示例13: with
/*
Code from http://www.dewtell.com/code/cpp/sobel.htm
Given image in source place Sobel edges in dest.
Grayscale sort of, with (255,255,255) as brightest edge.
sobelDestination should be same size and depth as source.
*/
QImage BlurDetect::sobelEdgeDetect(const QImage& source) {
QImage sobelEdges(source.size(), source.format());
int GX[3][3];
int GY[3][3];
/* 3x3 GX Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
GX[0][0] = -1; GX[0][1] = 0; GX[0][2] = 1;
GX[1][0] = -2; GX[1][1] = 0; GX[1][2] = 2;
GX[2][0] = -1; GX[2][1] = 0; GX[2][2] = 1;
/* 3x3 GY Sobel mask. Ref: www.cee.hw.ac.uk/hipr/html/sobel.html */
GY[0][0] = 1; GY[0][1] = 2; GY[0][2] = 1;
GY[1][0] = 0; GY[1][1] = 0; GY[1][2] = 0;
GY[2][0] = -1; GY[2][1] = -2; GY[2][2] = -1;
int width = source.width();
int height = source.height();
int I, J;
long sumX, sumY;
int SUM;
QRgb color;
for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if ( y == 0 || y >= height-1 || x == 0 || x >= width-1 ) {
SUM = 0;
}
else {
sumX = 0;
sumY = 0;
/*-------X and Y GRADIENT APPROXIMATION------*/
for(I=-1; I<=1; I++) {
for(J=-1; J<=1; J++) {
color = source.pixel(x+I, y+J);
sumX += qGray(color) * GX[I+1][J+1];
sumY += qGray(color) * GY[I+1][J+1];
}
}
SUM = abs(sumX) + abs(sumY); /*---GRADIENT MAGNITUDE APPROXIMATION (Myler p.218)----*/
if (SUM > 255) {
SUM = 255;
}
}
sobelEdges.setPixel(x,y,qRgb(SUM, SUM, SUM));
}
}
return sobelEdges;
}
示例14: calcMsePsnr
void calcMsePsnr(double* mse, double* psnr, QImage *image1, QImage *image2, QSize size) {
double P = 0;
for (int i = 0; i < size.width(); i++) {
for (int j = 0; j < size.height(); j++) {
int pixel1 = qGray(image1->pixel(i,j));
int pixel2 = qGray(image2->pixel(i,j));
double SQ = pixel1-pixel2;
P += SQ*SQ;
}
}
P /= size.width()*size.height();
*mse = sqrt(P);
*psnr = 10 * log10(65025./((*mse) * (*mse)));
}
示例15: qGray
QVector<Line> Converter::convert(const QImage &image, Modes mode/*, int left, int top, int right, int bottom*/){
QVector<Line> result;
int left = 0,top = 0,right = image.width(),bottom = image.height();
for( int i = left; i < right; ++i){
for( int j = top; j < bottom; ++j){
Line p;
p.x1 = p.x2 = i;
p.y1 = p.y2 = j;
p.z1 = qGray(image.pixel(i,j));
p.c = p.z1;
QVector<int> v;
if(i!=left) v.push_back(qGray(image.pixel(i-1,j)));
if(i < right-1) v.push_back(qGray(image.pixel(i+1,j)));
if(j!=top) v.push_back(qGray(image.pixel(i,j-1)));
if(j < bottom-1) v.push_back(qGray(image.pixel(i,j+1)));
if(i!=left && j!= top) v.push_back(qGray(image.pixel(i-1,j-1)));
if(i < right-1 && j!=top) v.push_back(qGray(image.pixel(i+1,j-1)));
if(j < bottom-1 && i!=left) v.push_back(qGray(image.pixel(i-1,j+1)));
if(i < right-1 && j < bottom-1) v.push_back(qGray(image.pixel(i+1,j+1)));
int min = *(std::min_element(v.begin(),v.end()));
if(min < qGray(image.pixel(i,j))){
p.z2 = p.z1 - min;
}else{
p.z2 = p.z1;
}
result.push_back(p);
}
}
switch (mode) {
case ISO:
rotate(result, 3.1415/180*35.2,3.1415/4,-3.1415/4);
break;
case BOTTOM:
rotate(result, 3.1415/180*90,0,0);
break;
case LEFT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, 3.1415/180*90,0);
break;
case RIGHT:
rotate(result, 3.1415/180*90,0,0);
rotate(result, 0, -3.1415/180*90,0);
break;
default:
break;
}
return result;
}