Merge branch 'master' into Zadanie_01_Dawid

This commit is contained in:
Dawid_Kreft 2020-03-19 11:42:10 +01:00
commit ca19e6fe34
3 changed files with 94 additions and 3 deletions

View File

@ -1,4 +1,6 @@
#include "conversion_grayscale.h" #include "conversion_grayscale.h"
#include<QDebug>
ConversionGrayscale::ConversionGrayscale(PNM* img) : ConversionGrayscale::ConversionGrayscale(PNM* img) :
Transformation(img) Transformation(img)
@ -12,19 +14,53 @@ ConversionGrayscale::ConversionGrayscale(PNM* img, ImageViewer* iv) :
PNM* ConversionGrayscale::transform() PNM* ConversionGrayscale::transform()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int width = image->width(); int width = image->width();
int height = image->height(); int height = image->height();
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
if (image->format() == QImage::Format_Mono) 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) 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()); 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; return newImage;
} }

View File

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