Zadanie 02 - Podstawowe operacje punktowe
This commit is contained in:
parent
8acd5f738c
commit
a957e224f7
@ -12,8 +12,6 @@ ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) :
|
||||
|
||||
PNM* ConversionGrayscale::transform()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
int width = image->width();
|
||||
int height = image->height();
|
||||
|
||||
@ -21,11 +19,32 @@ PNM* ConversionGrayscale::transform()
|
||||
|
||||
if (image->format() == QImage::Format_Mono)
|
||||
{
|
||||
|
||||
}
|
||||
else // if (image->format() == QImage::Format_RGB32)
|
||||
// Iterate over image space
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
|
||||
QColor color = QColor::fromRgb(image->pixel(x, y)); // Getting the pixel(x,y) value
|
||||
if (color == Qt::black) {
|
||||
newImage->setPixel(x, y, PIXEL_VAL_MAX);
|
||||
}
|
||||
if (color == Qt::white) {
|
||||
newImage->setPixel(x, y, PIXEL_VAL_MIN);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Iterate over image space
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
QRgb pixel = image->pixel(x, y); // Getting the pixel(x,y) value
|
||||
int sum = 0;
|
||||
sum += qRed(pixel) * 0.3;
|
||||
sum += qGreen(pixel) * 0.6;
|
||||
sum += qBlue(pixel) * 0.1;
|
||||
newImage->setPixel(x, y, QColor(sum, sum, sum).rgb());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "correction.h"
|
||||
#include <math.h>
|
||||
|
||||
Correction::Correction(PNM* img) :
|
||||
Transformation(img)
|
||||
@ -10,6 +11,11 @@ Correction::Correction(PNM* img, ImageViewer* iv) :
|
||||
{
|
||||
}
|
||||
|
||||
float transformValue(int value, float shift, float factor, float gamma) {
|
||||
float val = pow(((value + shift) * factor), gamma);
|
||||
return val > 255 ? 255 : val;
|
||||
}
|
||||
|
||||
PNM* Correction::transform()
|
||||
{
|
||||
float shift = getParameter("shift").toFloat();
|
||||
@ -21,7 +27,47 @@ PNM* Correction::transform()
|
||||
|
||||
PNM* newImage = new PNM(width, height, image->format());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
float values[256];
|
||||
for (int i = 0; i < 255; i++) {
|
||||
values[i] = i;
|
||||
}
|
||||
|
||||
// Iterate over image space
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
|
||||
QRgb pixel = image->pixel(x, y); // Getting the pixel(x,y) value
|
||||
|
||||
int r = qRed(pixel); // Get the 0-255 value of the R channel
|
||||
int g = qGreen(pixel); // Get the 0-255 value of the G channel
|
||||
int b = qBlue(pixel); // Get the 0-255 value of the B channel
|
||||
|
||||
if (values[r] != r) {
|
||||
r = values[r];
|
||||
}
|
||||
else {
|
||||
values[r] = transformValue(r, shift, factor, gamma);
|
||||
}
|
||||
|
||||
if (values[g] != g) {
|
||||
g = values[g];
|
||||
|
||||
}
|
||||
else {
|
||||
values[g] = transformValue(g, shift, factor, gamma);
|
||||
}
|
||||
|
||||
if (values[b] != b) {
|
||||
b = values[b];
|
||||
}
|
||||
else {
|
||||
values[b] = transformValue(b, shift, factor, gamma);
|
||||
}
|
||||
|
||||
QColor newPixel = QColor(r, g, b);
|
||||
newImage->setPixel(x, y, newPixel.rgb());
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user