Merge branch 'Dawid_zad_9' of s452126/lpo-projekt2020 into master
This commit is contained in:
commit
e0c1938fcc
@ -33,3 +33,4 @@ void EdgeRoberts::prepareMatrices()
|
||||
g_y[1][1]=0;
|
||||
|
||||
}
|
||||
|
||||
|
@ -15,48 +15,46 @@ EdgeSobel::EdgeSobel(PNM* img) :
|
||||
void EdgeSobel::prepareMatrices()
|
||||
{
|
||||
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;
|
||||
|
||||
this->g_x = math::matrix<float>(size,size);
|
||||
this->g_y = math::matrix<float>(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<float>* EdgeSobel::rawHorizontalDetection()
|
||||
{
|
||||
math::matrix<float>* x_gradient = new math::matrix<float>(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<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
|
||||
x_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return x_gradient;
|
||||
}
|
||||
|
||||
@ -64,15 +62,19 @@ math::matrix<float>* EdgeSobel::rawVerticalDetection()
|
||||
{
|
||||
math::matrix<float>* y_gradient = new math::matrix<float>(this->image->width(), this->image->height());
|
||||
|
||||
for (int x = 0; x < this->image->width(); x++)
|
||||
|
||||
int width = y_gradient->rowno();
|
||||
int height = y_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<float> temp = getWindow(x, y, 3, LChannel, NullEdge);
|
||||
y_gradient[x][y] = Convolution::sum(Convolution::join(g_y, temp));
|
||||
y_gradient[x][y] = Convolution::sum(Convolution::join(g_x, temp));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return y_gradient;
|
||||
}
|
||||
|
@ -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 ;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user