diff --git a/src/core/transformations/edge_roberts.cpp b/src/core/transformations/edge_roberts.cpp index 99a29c8..3d6c360 100644 --- a/src/core/transformations/edge_roberts.cpp +++ b/src/core/transformations/edge_roberts.cpp @@ -33,3 +33,4 @@ void EdgeRoberts::prepareMatrices() g_y[1][1]=0; } + diff --git a/src/core/transformations/edge_sobel.cpp b/src/core/transformations/edge_sobel.cpp index 681c9e0..bf6bb6e 100644 --- a/src/core/transformations/edge_sobel.cpp +++ b/src/core/transformations/edge_sobel.cpp @@ -14,65 +14,67 @@ EdgeSobel::EdgeSobel(PNM* img) : void EdgeSobel::prepareMatrices() { - int size = 3; + 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; - this->g_x = math::matrix(size,size); - this->g_y = math::matrix(size,size); + 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; - - 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()); - for (int x = 0; x < this->image->width(); x++) + int width = x_gradient->rowno(); + int height = x_gradient->colno(); + for (int x = 0; x < width; x++) { - for (int y = 0; y < this->image->height(); y++) + 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; + return x_gradient; } math::matrix* EdgeSobel::rawVerticalDetection() { math::matrix* y_gradient = new math::matrix(this->image->width(), this->image->height()); - for (int x = 0; x < this->image->width(); x++) - { - for (int y = 0; y < this->image->height(); y++) - { - math::matrix temp = getWindow(x, y, 3, LChannel, NullEdge); - y_gradient[x][y] = Convolution::sum(Convolution::join(g_y, temp)); + 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; }