diff --git a/src/core/transformations/edge_roberts.cpp b/src/core/transformations/edge_roberts.cpp index 0428da9..f57d7de 100644 --- a/src/core/transformations/edge_roberts.cpp +++ b/src/core/transformations/edge_roberts.cpp @@ -14,5 +14,21 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) : void EdgeRoberts::prepareMatrices() { + int size = 3; + math::matrix mask(size, size); + mask[0][0] = 1; + mask[1][1] = 1; + mask[2][2] = 1; + + this->g_x = math::matrix(size,size); + g_x[0][0] = 1; + g_x[1][1] = 1; + g_x[2][2] = 1; + + g_x = mask; + + + + qDebug() << Q_FUNC_INFO << "Not implemented yet!"; } diff --git a/src/core/transformations/edge_roberts.cpp.autosave b/src/core/transformations/edge_roberts.cpp.autosave new file mode 100644 index 0000000..0fc238b --- /dev/null +++ b/src/core/transformations/edge_roberts.cpp.autosave @@ -0,0 +1,32 @@ +#include "edge_roberts.h" + +EdgeRoberts::EdgeRoberts(PNM* img) : + EdgeGradient(img) +{ + prepareMatrices(); +} + +EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) : + EdgeGradient(img, iv) +{ + prepareMatrices(); +} + +void EdgeRoberts::prepareMatrices() +{ + int size = 3; + + + this->g_x = math::matrix(size,size); + g_x[0][0] = 1; + g_x[1][1] = 1; + g_x[2][2] = 1; + + + + + + + qDebug() << Q_FUNC_INFO << "Not implemented yet!"; +} + \ No newline at end of file diff --git a/src/core/transformations/edge_sobel.cpp b/src/core/transformations/edge_sobel.cpp index 6ef4bff..947fc7d 100644 --- a/src/core/transformations/edge_sobel.cpp +++ b/src/core/transformations/edge_sobel.cpp @@ -14,23 +14,65 @@ EdgeSobel::EdgeSobel(PNM* img) : void EdgeSobel::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + qDebug() << Q_FUNC_INFO << "Preparing matrix"; + int size = 3; + g_x = math::matrix(size,size); + g_y = math::matrix(size,size); + + g_x(0, 0) = -1; + g_x(0, 1) = 0; + g_x(0, 2) = 1; + g_x(1, 0) = -2; + g_x(1, 1) = 0; + g_x(1, 2) = 2; + g_x(2, 0) = -1; + g_x(2, 1) = 0; + g_x(2, 2) = 1; + + g_y(0, 0) = -1; + g_y(0, 1) = -2; + g_y(0, 2) = -1; + g_y(1, 0) = 0; + g_y(1, 1) = 0; + g_y(1, 2) = 0; + g_y(2, 0) = 1; + g_y(2, 1) = 2; + g_y(2, 2) = 1; } math::matrix* EdgeSobel::rawHorizontalDetection() { math::matrix* x_gradient = new math::matrix(this->image->width(), this->image->height()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int width = x_gradient->rowno(); + int height = x_gradient->colno(); - return x_gradient; + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + math::matrix temp = getWindow(x, y, 3, LChannel, NullEdge); + x_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp)); + } + } + return x_gradient; } math::matrix* EdgeSobel::rawVerticalDetection() { math::matrix* y_gradient = new math::matrix(this->image->width(), this->image->height()); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int width = y_gradient->rowno(); + int height = y_gradient->colno(); + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + math::matrix temp = getWindow(x, y, 3, LChannel, NullEdge); + y_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp)); + } + } return y_gradient; } diff --git a/src/core/transformations/map_height.cpp b/src/core/transformations/map_height.cpp index 71687d3..ac04762 100644 --- a/src/core/transformations/map_height.cpp +++ b/src/core/transformations/map_height.cpp @@ -1,5 +1,6 @@ #include "map_height.h" - +#include "conversion_grayscale.h" +\ MapHeight::MapHeight(PNM* img) : Transformation(img) { @@ -15,9 +16,8 @@ PNM* MapHeight::transform() int width = image->width(), height = image->height(); - PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); + ConversionGrayscale *conv = new ConversionGrayscale(image); + PNM* img = conv->transform(); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - - return newImage; + return img ; } diff --git a/src/core/transformations/map_horizon.cpp b/src/core/transformations/map_horizon.cpp index ebcef32..2360d47 100644 --- a/src/core/transformations/map_horizon.cpp +++ b/src/core/transformations/map_horizon.cpp @@ -34,8 +34,33 @@ PNM* MapHorizon::transform() } PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); - - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - - return newImage; + PNM* mapHeight = MapHeight(image).transform(); + for (int x = 0; xpixel(x, y)); + for (int n = x + dx; n < width; n = n + dx){ + for (int m = y+ dy ; m < height; m = m+dy) { + if(m >= 0 && n >=0 && n < width && m < height ){ + int redTempValue = qRed(mapHeight->pixel(n, m)); + if (redValue < redTempValue){ + float dis = sqrt(pow(n - x, 2) + pow(m - y, 2)) * scale; + float ra = atan((redTempValue - redValue) / dis) * 180 / 3.14; + if (ra > alfa){ + alfa = ra; + } + } + } + } + } + float delta = alfa - sun_alpha; + if (delta <= 0){ + newImage->setPixel(x, y, 255); + } + else{ + newImage->setPixel(x, y, cos(delta * 3.14 / 180) * 255); + } + } + } + return newImage; } diff --git a/src/core/transformations/map_normal.cpp b/src/core/transformations/map_normal.cpp index 472632b..3d59456 100644 --- a/src/core/transformations/map_normal.cpp +++ b/src/core/transformations/map_normal.cpp @@ -21,8 +21,31 @@ PNM* MapNormal::transform() double strength = getParameter("strength").toDouble(); PNM* newImage = new PNM(width, height, image->format()); + PNM* tempImage = MapHeight(image).transform(); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + EdgeSobel edgeSobel(tempImage); + math::matrix* gx = edgeSobel.rawHorizontalDetection(); + math::matrix* gy = edgeSobel.rawVerticalDetection(); + newImage = new PNM(width, height, QImage::Format_RGB32); + float dx = 0, dy= 0, dz = 0, length = 0; + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + dx = (*gx)(x, y) / 255; + dy = (*gy)(x, y) / 255; + dz = (float)(1.0 / strength); + length = sqrt(pow(dx, 2.0) + pow(dy, 2.0) + pow(dz, 2.0)); + dx = dx/length; + dy = dy/length; + dz = dz/length; + dx = (dx + 1) * (255 / 2); + dy = (dy + 1) * (255 / 2); + dz = (dz + 1) * (255 / 2); + newImage->setPixel(x, y, qRgb(dx, dy, dz)); + } + } return newImage; }