diff --git a/src/core/transformations/blur_gaussian.cpp b/src/core/transformations/blur_gaussian.cpp index 3eba6e4..758f178 100644 --- a/src/core/transformations/blur_gaussian.cpp +++ b/src/core/transformations/blur_gaussian.cpp @@ -1,4 +1,6 @@ +#define _USE_MATH_DEFINES #include "blur_gaussian.h" +#include BlurGaussian::BlurGaussian(PNM* img) : Convolution(img) @@ -25,15 +27,18 @@ math::matrix BlurGaussian::getMask(int size, Mode) { math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int half = size / 2; + for (int x=0;x mask(maskSize, maskSize); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + double maskSum = 0.0; + if (normalize) { + for (int i=0;i BlurUniform::getMask(int size, Mode) { math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int x=0; x Convolution::getMask(int size, Mode mode = Normalize) { math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0; i mask, Mode mode = RepeatEdge) PNM* newImage = new PNM(width, height, image->format()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + float weight = sum(mask); + + for (int x=0; xsetPixel(x, y, QColor(r,g,b).rgb()); + } + } + + return newImage; } +int Convolution::getOneChannelPixel(math::matrix& mask, int x, int y, Mode mode, Channel channel, float weight) { + math::matrix window = getWindow(x, y, mask.colsize(), channel, mode); + float summed = sum(join(window, mask)); + if (weight != 0) + summed /= weight; + + if (summed < 0) + summed = 0; + else if (summed > 255) + summed = 255; + return summed; +} + /** Joins to matrices by multiplying the A[i,j] with B[i,j]. * Warning! Both Matrices must be squares with the same size! */ @@ -48,7 +80,11 @@ const math::matrix Convolution::join(math::matrix A, math::matrix< int size = A.rowno(); math::matrix C(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0; i Convolution::join(math::matrix A, math::matrix< /** Sums all of the matrixes elements */ const float Convolution::sum(const math::matrix A) { - float sum = 0.0; - - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - - return sum; - + return A.sum(); } @@ -71,7 +102,11 @@ const math::matrix Convolution::reflection(const math::matrix A) int size = A.rowno(); math::matrix C(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for (int i=0; i join(math::matrix, math::matrix); const float sum(math::matrix); const math::matrix reflection(math::matrix); + int getOneChannelPixel(math::matrix& mask, int x, int y, Mode mode, Channel channel, float weight); }; #endif // CONVOLUTION_H diff --git a/src/core/transformations/transformation.cpp b/src/core/transformations/transformation.cpp index 18a3e0a..ae72f3c 100644 --- a/src/core/transformations/transformation.cpp +++ b/src/core/transformations/transformation.cpp @@ -103,9 +103,9 @@ QRgb Transformation::getPixel(int x, int y, Mode mode) */ QRgb Transformation::getPixelCyclic(int x, int y) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - - return image->pixel(x,y); + int width = image->size().width(); + int height = image->size().height(); + return image->pixel(x % width,y % height); } /** @@ -114,7 +114,12 @@ QRgb Transformation::getPixelCyclic(int x, int y) */ QRgb Transformation::getPixelNull(int x, int y) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + const QRgb blackPixel = qRgb(0, 0, 0); + + int width = image->size().width(); + int height = image->size().height(); + if (x >= width || x < 0 || y >= height || y < 0) + return blackPixel; return image->pixel(x,y); } @@ -126,8 +131,14 @@ QRgb Transformation::getPixelNull(int x, int y) */ QRgb Transformation::getPixelRepeat(int x, int y) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int width = image->size().width(); + int height = image->size().height(); + if (x >= width) x = width - 1; + if (x < 0) x = 0; + + if (y >= height) y = height - 1; + if (y < 0) y = 0; return image->pixel(x,y); } @@ -138,7 +149,20 @@ math::matrix Transformation::getWindow(int x, int y, int size, { math::matrix window(size,size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int half = size/2; + for (int i=0; i