QRgb **matrice_pixel = new QRgb*[height];
for (int i = 0; i <height; i++){
matrice_pixel[i] = new QRgb[width];
}
/// Getting the colors
for ( int i=0; i<height; i++ ) {
uchar *p = source.scanLine(i);
for (int j = 0; j< width;j ++) {
int blue = int(*p++);
int green = int(*p++);
int red = int(*p++);
int alpha = int(*p++);
QRgb rgbValue = qRgba(red,green,blue, alpha);
matrice_pixel[i][j] = rgbValue;
}
for (int x = 1; x<width ;++x)
{
for (int y= 1; y< height; ++y)
{
int red = 0, green = 0, blue = 0;
//multiply every value of the filter with corresponding image pixel
for(int kernelX = 0; kernelX < kernelWidth; kernelX++)
{
for(int kernelY = 0; kernelY < kernelHeight; kernelY++){
red += qRed(matrice_pixel[x][ y] ) * kernel[kernelX][kernelY];
green += qGreen(matrice_pixel[x][y]) * kernel[kernelX][kernelY];
blue += qBlue(matrice_pixel[x] [ y]) * kernel[kernelX][kernelY];
}
//truncate values smaller than zero and larger than 255
red = qMin(qMax(int(factor * red + bias), 0), 255);
green= qMin(qMax(int(factor * green + bias), 0), 255);
blue= qMin(qMax(int(factor * blue + bias), 0), 255);
QRgb rgbValue = qRgb(red,green,blue);
img.setPixel(x,y, rgbValue);
}
}
}
QRgb **matrice_pixel = new QRgb*[height];
for (int i = 0; i <height; i++){
matrice_pixel[i] = new QRgb[width];
}
/// Getting the colors
for ( int i=0; i<height; i++ ) {
uchar *p = source.scanLine(i);
for (int j = 0; j< width;j ++) {
int blue = int(*p++);
int green = int(*p++);
int red = int(*p++);
int alpha = int(*p++);
QRgb rgbValue = qRgba(red,green,blue, alpha);
matrice_pixel[i][j] = rgbValue;
}
for (int x = 1; x<width ;++x)
{
for (int y= 1; y< height; ++y)
{
int red = 0, green = 0, blue = 0;
//multiply every value of the filter with corresponding image pixel
for(int kernelX = 0; kernelX < kernelWidth; kernelX++)
{
for(int kernelY = 0; kernelY < kernelHeight; kernelY++){
red += qRed(matrice_pixel[x][ y] ) * kernel[kernelX][kernelY];
green += qGreen(matrice_pixel[x][y]) * kernel[kernelX][kernelY];
blue += qBlue(matrice_pixel[x] [ y]) * kernel[kernelX][kernelY];
}
//truncate values smaller than zero and larger than 255
red = qMin(qMax(int(factor * red + bias), 0), 255);
green= qMin(qMax(int(factor * green + bias), 0), 255);
blue= qMin(qMax(int(factor * blue + bias), 0), 255);
QRgb rgbValue = qRgb(red,green,blue);
img.setPixel(x,y, rgbValue);
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks