Zadanie 04

This commit is contained in:
Sebastian Spaloniak 2020-05-05 17:13:07 +02:00
parent c724f79b2f
commit 25062ac7fc
5 changed files with 161 additions and 19 deletions

View File

@ -25,15 +25,32 @@ math::matrix<float> BlurGaussian::getMask(int size, Mode)
{
math::matrix<float> mask(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
Mode mode = RepeatEdge;
for (int i = 0; i<size; i++)
{
for (int j = 0; j<size; j++)
{
mask(i, j) = getGauss(i-radius, j-radius, sigma);
}
}
return mask;
}
float BlurGaussian::getGauss(int x, int y, float sigma)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
{
float pi = 3.14159265359f;
float e = 2.718281828459f;
return 0;
float g1 = (1 / (2 * pi*pow(sigma,2)));
float p1 = pow(x ,2) + pow(y ,2);
float p2 = (2 * pow(sigma, 2));
float g2 = pow(e,(-(p1) / p2));
float gauss = g1*g2;
return gauss;
}

View File

@ -18,7 +18,21 @@ PNM* BlurLinear::transform()
math::matrix<float> mask(maskSize, maskSize);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int curr = 0;
for (int i = 0; i < maskSize; i++)
{
for (int j = 0; j < maskSize; j++)
{
mask(i, j) = tmpMask.at(curr).toDouble();
if (normalize)
{
mask(i, j) = mask(i, j) / sum(mask);
}
curr++;
}
}
return convolute(mask, RepeatEdge);
}

View File

@ -14,7 +14,13 @@ math::matrix<float> BlurUniform::getMask(int size, Mode)
{
math::matrix<float> mask(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for (int i = size; i-- != 0;)
{
for (int j = size; j-- != 0;)
{
mask(i, j) = 1;
}
}
return mask;
}

View File

@ -22,7 +22,14 @@ math::matrix<float> Convolution::getMask(int size, Mode mode = Normalize)
{
math::matrix<float> mask(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for (int x = 0; x < size; x++)
{
for (int y = 0 ; y < size; y++)
{
mask(x, y) = 0;
}
}
mask(size / 2, size / 2) = 1;
return mask;
}
@ -35,7 +42,49 @@ PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
PNM* newImage = new PNM(width, height, image->format());
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
float weight = sum(mask);
QVector < Channel > cha;
if (image->format() == QImage::Format_Indexed8)
{
cha.push_back(LChannel);
}
else
{
cha.push_back(RChannel);
cha.push_back(GChannel);
cha.push_back(BChannel);
}
float result[3];
for (int x = 0; x<width; x++)
{
for (int y = 0; y<height; y++)
{
for (int c = 0; c<cha.size(); c++)
{
math::matrix<float> accum = join(mask, getWindow(x, y, mask.rowno(), cha[c], mode));
result[c] = sum(accum);
if (weight != 0) {
result[c] /= weight;
}
if (result[c] > 255) {
result[c] = 255;
}
else if (result[c] < 0) {
result[c] = 0;
}
}
if (image->format() == QImage::Format_Indexed8) {
newImage->setPixel(x, y, result[0]);
}
else {
newImage->setPixel(x, y, qRgb(result[0], result[1], result[2]));
}
}
}
return newImage;
}
@ -48,7 +97,13 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
int size = A.rowno();
math::matrix<float> C(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
C(x, y) = A(x, y) * B(x, y);
}
}
return C;
}
@ -57,11 +112,15 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
const float Convolution::sum(const math::matrix<float> A)
{
float sum = 0.0;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for (int i = 0; i < A.rowno(); i++)
{
for (int j = 0; j < A.colno(); j++)
{
sum += A(i, j);
}
}
return sum;
}
@ -71,7 +130,14 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
int size = A.rowno();
math::matrix<float> C(size, size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
for (int x = 0; x < size; x++)
{
for (int y = 0; y < size; y++)
{
C(size - x, size - y) = A(x, y);
}
}
return C;
}

View File

@ -103,7 +103,8 @@ QRgb Transformation::getPixel(int x, int y, Mode mode)
*/
QRgb Transformation::getPixelCyclic(int x, int y)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
x = image->width() % x;
y = image->height() % y;
return image->pixel(x,y);
}
@ -114,9 +115,14 @@ QRgb Transformation::getPixelCyclic(int x, int y)
*/
QRgb Transformation::getPixelNull(int x, int y)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return image->pixel(x,y);
if (x >= image->width() || x < 0 || y >= image->height() || y < 0)
{
return qRgb(0, 0, 0);
}
else
{
return image->pixel(x, y);
}
}
/**
@ -126,7 +132,23 @@ QRgb Transformation::getPixelNull(int x, int y)
*/
QRgb Transformation::getPixelRepeat(int x, int y)
{
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
if (x < 0)
{
x = 0;
}
else if (x >= image->width())
{
x = image->width() - 1;
}
if (y < 0)
{
y = 0;
}
else if (y >= image->height())
{
y = image->height() - 1;
}
return image->pixel(x,y);
}
@ -138,7 +160,24 @@ math::matrix<float> Transformation::getWindow(int x, int y, int size,
{
math::matrix<float> window(size,size);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int xNew = x - size / 2;
int yNew = y - size / 2;
for (int i = 0; i < size; i++)
{
for (int j = 0; j < size; j++)
{
QRgb col = getPixel(xNew + i, yNew + j, mode);
if (channel == RChannel) {
window(i, j) = qRed(col);
} else if (channel == GChannel) {
window(i, j) = qGreen(col);
} else {
window(i, j) = qBlue(col);
}
}
}
return window;
}