Zadanie 2 Jonasz #4

Merged
s452117 merged 1 commits from Zadanie_2_Jonasz into Added_specifiction.doc 2020-03-15 12:53:09 +01:00
3 changed files with 94 additions and 3 deletions
Showing only changes of commit be93356b0b - Show all commits

View File

@ -1,4 +1,6 @@
#include "conversion_grayscale.h"
#include<QDebug>
ConversionGrayscale::ConversionGrayscale(PNM* img) :
Transformation(img)
@ -12,19 +14,53 @@ ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) :
PNM* ConversionGrayscale::transform()
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
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++)
{
QRgb pixel = image->pixel(x,y);
int v = qGray(pixel);
if(v>128)
{
v=PIXEL_VAL_MAX;
}
else
{
v=PIXEL_VAL_MIN;
}
newImage->setPixel(x,y, QColor(v,v,v).rgb());
}
}
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);
double r = (double) qRed(pixel);
double g =(double) qGreen(pixel);
double b =(double) qBlue(pixel);
double p=((r*0.3)+(g*0.6)+(b*0.1));
newImage->setPixel(x,y, QColor(p,p,p).rgb());
}
}

View File

@ -21,7 +21,60 @@ PNM* Correction::transform()
PNM* newImage = new PNM(width, height, image->format());
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for(int i=0; i<PIXEL_VAL_MAX+1; i++) LUT[i]=-1;
if (image->format() == QImage::Format_Mono)
{
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
QRgb pixel = image->pixel(x,y);
int v = qGray(pixel);
if(LUT[v]==-1)
{
temp=pow(((v+shift)*factor),gamma);
if(temp>255) temp=255;
if(temp<0) temp=0;
LUT[v]=(int)temp;
}
newImage->setPixel(x,y, QColor(LUT[v],LUT[v],LUT[v]).rgb());
}
}
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);
rgb[0] = qRed(pixel);
rgb[1] = qGreen(pixel);
rgb[2] = qBlue(pixel);
for(int i=0;i<3;i++)
{
if(LUT[rgb[i]]==-1)
{
temp=pow(((rgb[i]+shift)*factor),gamma);
if(temp>255) temp=255;
if(temp<0) temp=0;
LUT[rgb[i]]=(int)temp;
}
}
newImage->setPixel(x,y, QColor(LUT[rgb[0]],LUT[rgb[1]],LUT[rgb[2]]).rgb());
}
}
return newImage;
}

View File

@ -13,6 +13,8 @@ public:
private:
int LUT[PIXEL_VAL_MAX+1];
int rgb[3];
float temp;
};
#endif // CORRECTION_H