Zadanie 2
This commit is contained in:
parent
5fae6770e5
commit
9278aa08db
@ -1,3 +1,4 @@
|
|||||||
# Rozwiązania laboratoria 03
|
# Rozwiązania laboratoria 02
|
||||||
|
|
||||||
# Znajdują się w katalogu ./02/do_sprawdzenia/cpp/mysimplegimp
|
Cały kod znajduje się w katalogu głównym ,,app/cpp/mysimplegimp''
|
||||||
|
Zmienieone pliki projektu dla zadania lab02 znajdują się w katalogu ,,02/do_sprawdzenia''
|
||||||
|
53
02/do_sprawdzenia/conversion_grayscale.cpp
Normal file
53
02/do_sprawdzenia/conversion_grayscale.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
#include "conversion_grayscale.h"
|
||||||
|
#include <QDebug>
|
||||||
|
#include <iostream>
|
||||||
|
ConversionGrayscale::ConversionGrayscale(PNM* img) :
|
||||||
|
Transformation(img)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) :
|
||||||
|
Transformation(img, iv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PNM* ConversionGrayscale::transform()
|
||||||
|
{
|
||||||
|
int width = image->width();
|
||||||
|
int height = image->height();
|
||||||
|
|
||||||
|
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
|
||||||
|
|
||||||
|
if (image->format() == QImage::Format_Mono)
|
||||||
|
{
|
||||||
|
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
|
||||||
|
newImage->setPixel(x,y, color == Qt::white ? PIXEL_VAL_MAX : PIXEL_VAL_MIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else // if (image->format() == QImage::Format_RGB32)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
double r = qRed(pixel)*0.3;
|
||||||
|
double g = qGreen(pixel)*0.6;
|
||||||
|
double b = qBlue(pixel)*0.1;
|
||||||
|
QColor newPixel = QColor(r+g+b,r+g+b,r+g+b);
|
||||||
|
newImage->setPixel(x,y, newPixel.rgb());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newImage;
|
||||||
|
}
|
60
02/do_sprawdzenia/correction.cpp
Normal file
60
02/do_sprawdzenia/correction.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include "correction.h"
|
||||||
|
|
||||||
|
Correction::Correction(PNM* img) :
|
||||||
|
Transformation(img)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Correction::Correction(PNM* img, ImageViewer* iv) :
|
||||||
|
Transformation(img, iv)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PNM* Correction::transform()
|
||||||
|
{
|
||||||
|
float shift = getParameter("shift").toFloat();
|
||||||
|
float factor = getParameter("factor").toFloat();
|
||||||
|
float gamma = getParameter("gamma").toFloat();
|
||||||
|
|
||||||
|
int width = image->width();
|
||||||
|
int height = image->height();
|
||||||
|
|
||||||
|
PNM* newImage = new PNM(width, height, image->format());
|
||||||
|
|
||||||
|
for(unsigned int i=0; i<sizeof(LUT)/sizeof(LUT[0]); i++) {
|
||||||
|
|
||||||
|
// Adjusted Value
|
||||||
|
float adjustedValue = 0;
|
||||||
|
|
||||||
|
// shift value
|
||||||
|
adjustedValue = i + shift;
|
||||||
|
|
||||||
|
// multiply by factor
|
||||||
|
adjustedValue = adjustedValue * factor;
|
||||||
|
|
||||||
|
// power by gamma
|
||||||
|
adjustedValue = pow(adjustedValue, gamma);
|
||||||
|
|
||||||
|
// if adjusted value is bigger than 255, will be set to 255
|
||||||
|
if (adjustedValue > PIXEL_VAL_MAX) adjustedValue = PIXEL_VAL_MAX;
|
||||||
|
// if adjusted value is smaller than 0, will be set to 0
|
||||||
|
if (adjustedValue < PIXEL_VAL_MIN) adjustedValue = PIXEL_VAL_MIN;
|
||||||
|
|
||||||
|
//Fill LUT table
|
||||||
|
LUT[i] = adjustedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new pixels
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
QRgb pixel = image->pixel(x,y);
|
||||||
|
int r = qRed(pixel);
|
||||||
|
int g = qGreen(pixel);
|
||||||
|
int b = qBlue(pixel);
|
||||||
|
QColor newPixel = QColor(LUT[r], LUT[g], LUT[b]);
|
||||||
|
newImage->setPixel(x, y, newPixel.rgb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newImage;
|
||||||
|
}
|
BIN
02/do_sprawdzenia/pic1.png
Normal file
BIN
02/do_sprawdzenia/pic1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 260 KiB |
BIN
02/do_sprawdzenia/pic2.png
Normal file
BIN
02/do_sprawdzenia/pic2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 549 KiB |
BIN
02/do_sprawdzenia/pic3.png
Normal file
BIN
02/do_sprawdzenia/pic3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 98 KiB |
BIN
02/do_sprawdzenia/pic4.png
Normal file
BIN
02/do_sprawdzenia/pic4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 143 KiB |
@ -21,7 +21,40 @@ PNM* Correction::transform()
|
|||||||
|
|
||||||
PNM* newImage = new PNM(width, height, image->format());
|
PNM* newImage = new PNM(width, height, image->format());
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
for(unsigned int i=0; i<sizeof(LUT)/sizeof(LUT[0]); i++) {
|
||||||
|
|
||||||
|
// Adjusted Value
|
||||||
|
float adjustedValue = 0;
|
||||||
|
|
||||||
|
// shift value
|
||||||
|
adjustedValue = i + shift;
|
||||||
|
|
||||||
|
// multiply by factor
|
||||||
|
adjustedValue = adjustedValue * factor;
|
||||||
|
|
||||||
|
// power by gamma
|
||||||
|
adjustedValue = pow(adjustedValue, gamma);
|
||||||
|
|
||||||
|
// if adjusted value is bigger than 255, will be set to 255
|
||||||
|
if (adjustedValue > PIXEL_VAL_MAX) adjustedValue = PIXEL_VAL_MAX;
|
||||||
|
// if adjusted value is smaller than 0, will be set to 0
|
||||||
|
if (adjustedValue < PIXEL_VAL_MIN) adjustedValue = PIXEL_VAL_MIN;
|
||||||
|
|
||||||
|
//Fill LUT table
|
||||||
|
LUT[i] = adjustedValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new pixels
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
QRgb pixel = image->pixel(x,y);
|
||||||
|
int r = qRed(pixel);
|
||||||
|
int g = qGreen(pixel);
|
||||||
|
int b = qBlue(pixel);
|
||||||
|
QColor newPixel = QColor(LUT[r], LUT[g], LUT[b]);
|
||||||
|
newImage->setPixel(x, y, newPixel.rgb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user