zadanie-5
This commit is contained in:
parent
11269543b1
commit
729014c9c8
@ -39,6 +39,6 @@ math::matrix<float> BlurGaussian::getMask(int size, Mode)
|
||||
|
||||
float BlurGaussian::getGauss(int x, int y, float sigma)
|
||||
{
|
||||
return exp(-((pow(x, 2.0) + pow(y, 2.0)) / 2 * pow(sigma, 2.0))) / (2 * M_PI * pow(sigma, 2.0));
|
||||
return exp(-((pow(x, 2.0) + pow(y, 2.0)) / (2 * pow(sigma, 2.0)))) / (2 * M_PI * pow(sigma, 2.0));
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "edge_gradient.h"
|
||||
#include <math.h>
|
||||
|
||||
EdgeGradient::EdgeGradient(PNM* img, ImageViewer* iv) :
|
||||
Convolution(img, iv)
|
||||
@ -24,8 +25,27 @@ PNM* EdgeGradient::transform()
|
||||
{
|
||||
PNM* newImage = new PNM(image->width(), image->height(), image->format());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
PNM* horizontal = horizontalDetection();
|
||||
PNM* vertical = verticalDetection();
|
||||
|
||||
for (int x=0;x<image->width();++x) {
|
||||
for (int y=0;y<image->height();++y) {
|
||||
int horizontalPixel = horizontal->pixel(x,y);
|
||||
int verticalPixel = vertical->pixel(x,y);
|
||||
|
||||
int r = sqrt(pow(qRed(horizontalPixel), 2.0) + pow(qRed(verticalPixel), 2.0));
|
||||
int g = sqrt(pow(qGreen(horizontalPixel), 2.0) + pow(qGreen(verticalPixel), 2.0));
|
||||
int b = sqrt(pow(qBlue(horizontalPixel), 2.0) + pow(qBlue(verticalPixel), 2.0));
|
||||
|
||||
newImage->setPixel(x, y, QColor(limit(r),limit(g),limit(b)).rgb());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
int EdgeGradient::limit(int value) {
|
||||
if (value < 0) return 0;
|
||||
if (value > 255) return 255;
|
||||
return value;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
|
||||
protected:
|
||||
virtual void prepareMatrices() = 0;
|
||||
int limit(int value);
|
||||
math::matrix<float> g_x,
|
||||
g_y;
|
||||
};
|
||||
|
@ -15,7 +15,14 @@ math::matrix<float> EdgeLaplacian::getMask(int, Mode)
|
||||
int size = getParameter("size").toInt();
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int i=0;i<size;++i) {
|
||||
for (int j=0;j<size;++j) {
|
||||
if (i == size/2 && j == size/2)
|
||||
mask[i][j] = (size*size) - 1;
|
||||
else
|
||||
mask[i][j] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "edge_laplacian_of_gauss.h"
|
||||
|
||||
#include <math.h>
|
||||
#include "blur_gaussian.h"
|
||||
|
||||
EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img) :
|
||||
@ -12,23 +12,28 @@ EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img, ImageViewer* iv) :
|
||||
{
|
||||
}
|
||||
|
||||
math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
|
||||
math::matrix<float> EdgeLaplaceOfGauss::getMask(int size, float sigma, Mode)
|
||||
{
|
||||
if (size == 0)
|
||||
size = getParameter("size").toInt();
|
||||
double sigma = getParameter("sigma").toDouble();
|
||||
if (sigma == 0)
|
||||
sigma = getParameter("sigma").toDouble();
|
||||
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int i=0;i<size;++i) {
|
||||
for (int j=0;j<size;++j) {
|
||||
mask[i][j] = getLoG(i - (size/2.0), j - (size/2.0), sigma);
|
||||
}
|
||||
}
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
float EdgeLaplaceOfGauss::getLoG(int x, int y, float s)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
float gauss = BlurGaussian::getGauss(x,y,s);
|
||||
return ((pow(x,2.0) + pow(y,2.0) - 2) * gauss) / pow(s,2.0);
|
||||
}
|
||||
|
||||
int EdgeLaplaceOfGauss::getSize()
|
||||
|
@ -9,7 +9,7 @@ public:
|
||||
EdgeLaplaceOfGauss(PNM*);
|
||||
EdgeLaplaceOfGauss(PNM*, ImageViewer*);
|
||||
|
||||
virtual math::matrix<float> getMask(int, Mode);
|
||||
virtual math::matrix<float> getMask(int, float, Mode);
|
||||
|
||||
static float getLoG(int, int, float);
|
||||
int getSize();
|
||||
|
@ -14,6 +14,15 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) :
|
||||
|
||||
void EdgePrewitt::prepareMatrices()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
float array_x[9] = {-1,0,1,
|
||||
-1,0,1,
|
||||
-1,0,1};
|
||||
|
||||
float array_y[9] = {-1,-1,-1,
|
||||
0,0,0,
|
||||
1,1,1};
|
||||
|
||||
g_x = math::matrix<float>(3,3, array_x);
|
||||
g_y = math::matrix<float>(3,3, array_y);
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "edge_roberts.h"
|
||||
#include <math.h>
|
||||
|
||||
EdgeRoberts::EdgeRoberts(PNM* img) :
|
||||
EdgeGradient(img)
|
||||
@ -14,5 +15,15 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
|
||||
|
||||
void EdgeRoberts::prepareMatrices()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
g_x = math::matrix<float>(2,2);
|
||||
g_x[0][0] = 1;
|
||||
g_x[0][1] = 0;
|
||||
g_x[1][0] = 0;
|
||||
g_x[1][1] = -1;
|
||||
|
||||
g_y = math::matrix<float>(2,2);
|
||||
g_y[0][0] = 0;
|
||||
g_y[0][1] = 1;
|
||||
g_y[1][0] = -1;
|
||||
g_y[1][1] = 0;
|
||||
}
|
||||
|
@ -14,7 +14,16 @@ EdgeSobel::EdgeSobel(PNM* img) :
|
||||
|
||||
void EdgeSobel::prepareMatrices()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
float array_x[9] = {-1,0,1,
|
||||
-2,0,2,
|
||||
-1,0,1};
|
||||
|
||||
float array_y[9] = {-1,-2,-1,
|
||||
0,0,0,
|
||||
1,2,1};
|
||||
|
||||
g_x = math::matrix<float>(3,3, array_x);
|
||||
g_y = math::matrix<float>(3,3, array_y);
|
||||
}
|
||||
|
||||
math::matrix<float>* EdgeSobel::rawHorizontalDetection()
|
||||
|
@ -22,8 +22,24 @@ PNM* EdgeZeroCrossing::transform()
|
||||
int t = getParameter("threshold").toInt();
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
|
||||
EdgeLaplaceOfGauss log(newImage);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
int v0 = 128;
|
||||
|
||||
for (int x=0;x<width;++x) {
|
||||
for (int y=0;y<height;++y) {
|
||||
float lapsjan = EdgeLaplaceOfGauss::getLoG(x,y, sigma) * v0;
|
||||
math::matrix<float> mask = log.getMask(size, sigma, RepeatEdge);
|
||||
|
||||
float max = mask.max();
|
||||
float min = mask.min();
|
||||
|
||||
if (min < v0 - t && max > v0 + t)
|
||||
newImage->setPixel(x,y, QColor(lapsjan, lapsjan, lapsjan).rgb());
|
||||
else
|
||||
newImage->setPixel(x,y, QColor(0, 0, 0).rgb());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user