This commit is contained in:
Dawid_Kreft 2020-05-04 00:09:26 +02:00
parent fd6ca73279
commit ff25696424
6 changed files with 152 additions and 14 deletions

View File

@ -14,5 +14,21 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
void EdgeRoberts::prepareMatrices()
{
int size = 3;
math::matrix<float> mask(size, size);
mask[0][0] = 1;
mask[1][1] = 1;
mask[2][2] = 1;
this->g_x = math::matrix<float>(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!";
}

View File

@ -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<float>(size,size);
g_x[0][0] = 1;
g_x[1][1] = 1;
g_x[2][2] = 1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
}

View File

@ -14,15 +14,47 @@ 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<float>(size,size);
g_y = math::matrix<float>(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<float>* EdgeSobel::rawHorizontalDetection()
{
math::matrix<float>* x_gradient = new math::matrix<float>(this->image->width(), this->image->height());
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int width = x_gradient->rowno();
int height = x_gradient->colno();
for (int x = 0; x < width; x++)
{
for (int y = 0; y < height; y++)
{
math::matrix<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
x_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp));
}
}
return x_gradient;
}
@ -30,7 +62,17 @@ math::matrix<float>* EdgeSobel::rawVerticalDetection()
{
math::matrix<float>* y_gradient = new math::matrix<float>(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<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
y_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp));
}
}
return y_gradient;
}

View File

@ -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 ;
}

View File

@ -34,8 +34,33 @@ PNM* MapHorizon::transform()
}
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
PNM* mapHeight = MapHeight(image).transform();
for (int x = 0; x<width; x++){
for (int y = 0; y<height; y++){
float alfa = 0.0;
int redValue = qRed(mapHeight->pixel(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;
}

View File

@ -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<float>* gx = edgeSobel.rawHorizontalDetection();
math::matrix<float>* 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;
}