Zadanie 9
This commit is contained in:
parent
e03241451e
commit
b78ce3902b
@ -1,27 +1,62 @@
|
||||
#include "edge_sobel.h"
|
||||
|
||||
EdgeSobel::EdgeSobel(PNM* img, ImageViewer* iv) :
|
||||
EdgeGradient(img, iv)
|
||||
EdgeGradient(img, iv)
|
||||
{
|
||||
prepareMatrices();
|
||||
}
|
||||
|
||||
EdgeSobel::EdgeSobel(PNM* img) :
|
||||
EdgeGradient(img)
|
||||
EdgeGradient(img)
|
||||
{
|
||||
prepareMatrices();
|
||||
}
|
||||
|
||||
void EdgeSobel::prepareMatrices()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
math::matrix<float> gx(3, 3);
|
||||
math::matrix<float> gy(3, 3);
|
||||
|
||||
g_x = gx;
|
||||
g_y = gy;
|
||||
|
||||
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(),
|
||||
height = x_gradient->colno();
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
math::matrix<float> window = getWindow(x, y, 3, LChannel, NullEdge);
|
||||
(*x_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, window));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return x_gradient;
|
||||
}
|
||||
@ -30,7 +65,18 @@ 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(),
|
||||
height = y_gradient->colno();
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
math::matrix<float> window = getWindow(x, y, 3, LChannel, NullEdge);
|
||||
(*y_gradient)(x, y) = Convolution::sum(Convolution::join(g_y, window));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return y_gradient;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "map_height.h"
|
||||
#include "conversion_grayscale.h"
|
||||
|
||||
MapHeight::MapHeight(PNM* img) :
|
||||
Transformation(img)
|
||||
@ -15,9 +16,9 @@ PNM* MapHeight::transform()
|
||||
int width = image->width(),
|
||||
height = image->height();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
newImage = ConversionGrayscale(image).transform();
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
@ -33,9 +33,31 @@ PNM* MapHorizon::transform()
|
||||
dy = -1;
|
||||
}
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Indexed8);
|
||||
PNM* mapHeight = MapHeight(image).transform();
|
||||
for (int x = 0; x<width; x++){
|
||||
for (int y = 0; y<height; y++){
|
||||
float alfa = 0.0;
|
||||
int ch = qRed(mapHeight->pixel(x, y));
|
||||
for (int n = x + dx, m = y + dy; n < width && m < height && n >= 0 && m >= 0; n += dx, m += dy){
|
||||
int rh = qRed(mapHeight->pixel(n, m));
|
||||
if (ch < rh){
|
||||
float dis = sqrt(pow(n - x, 2) + pow(m - y, 2)) * scale;
|
||||
float ra = atan((rh - ch) / 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;
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
#include "map_height.h"
|
||||
|
||||
MapNormal::MapNormal(PNM* img) :
|
||||
Convolution(img)
|
||||
Convolution(img)
|
||||
{
|
||||
}
|
||||
|
||||
MapNormal::MapNormal(PNM* img, ImageViewer* iv) :
|
||||
Convolution(img, iv)
|
||||
Convolution(img, iv)
|
||||
{
|
||||
}
|
||||
|
||||
@ -22,7 +22,38 @@ PNM* MapNormal::transform()
|
||||
|
||||
PNM* newImage = new PNM(width, height, image->format());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
PNM* tempImage = MapHeight(image).transform();
|
||||
|
||||
EdgeSobel sobel(tempImage);
|
||||
math::matrix<float>* gx = sobel.rawHorizontalDetection();
|
||||
math::matrix<float>* gy = sobel.rawVerticalDetection();
|
||||
|
||||
newImage = new PNM(width, height, QImage::Format_RGB32);
|
||||
float dzStart = (float)(1.0 / strength);
|
||||
|
||||
float dx, dy, dz, len;
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
for (int y = 0; y < height; y++)
|
||||
{
|
||||
dx = (*gx)(x, y) / 255.0;
|
||||
dy = (*gy)(x, y) / 255.0;
|
||||
dz = dzStart;
|
||||
|
||||
len = sqrt(pow(dx, 2.0) + pow(dy, 2.0) + pow(dz, 2.0));
|
||||
|
||||
dx /= len;
|
||||
dy /= len;
|
||||
dz /= len;
|
||||
|
||||
dx = (dx + 1.0) * (255.0 / 2.0);
|
||||
dy = (dy + 1.0) * (255.0 / 2.0);
|
||||
dz = (dz + 1.0) * (255.0 / 2.0);
|
||||
|
||||
newImage->setPixel(x, y, qRgb(dx, dy, dz));
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user