This commit is contained in:
Dawid_Kreft 2020-05-17 23:21:17 +02:00
parent e0c1938fcc
commit 0aba7c500d
7 changed files with 59 additions and 13 deletions

View File

@ -46,4 +46,3 @@ float BlurGaussian::getGauss(int x, int y, float sigma)
float gauss= exp(-(x*x+y*y)/(2*sigma*sigma))/(2*M_PI*sigma*sigma);
return gauss;
}

View File

@ -65,4 +65,3 @@ PNM* ConversionGrayscale::transform()
}
return newImage;
}

View File

@ -181,4 +181,3 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
}
return C;
}

View File

@ -10,9 +10,12 @@ EdgeLaplacian::EdgeLaplacian(PNM* img, ImageViewer* iv) :
{
}
math::matrix<float> EdgeLaplacian::getMask(int, Mode)
math::matrix<float> EdgeLaplacian::getMask(int size , Mode)
{
int size = getParameter("size").toInt();
if( getParameter("size").toInt() > size )
size =getParameter("size").toInt();
math::matrix<float> mask(size, size);
int r=size/2;

View File

@ -12,11 +12,14 @@ EdgeLaplaceOfGauss::EdgeLaplaceOfGauss(PNM* img, ImageViewer* iv) :
{
}
math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
math::matrix<float> EdgeLaplaceOfGauss::getMask(int size, Mode)
{
size = getParameter("size").toInt();
if( getParameter("size").toInt() > size )
size =getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble();
math::matrix<float> mask(size, size);
int r=size/2;

View File

@ -51,7 +51,7 @@ math::matrix<float>* EdgeSobel::rawHorizontalDetection()
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));
(*x_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp));
}
}
@ -71,7 +71,7 @@ math::matrix<float>* EdgeSobel::rawVerticalDetection()
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));
(*y_gradient)(x, y) = Convolution::sum(Convolution::join(g_x, temp));
}
}

View File

@ -17,7 +17,50 @@ PNM* Hough::transform()
{
int thetaDensity = getParameter("theta_density").toInt();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int width = image->width();
int height = image->height();
PNM* tempImage = new PNM(width, height, QImage::Format_Indexed8);
tempImage = ConversionGrayscale(image).transform();
return 0;
if (!getParameter("skip_edge_detection").toBool()) {
tempImage = EdgeLaplacian(tempImage).transform();
}
int pmax =int(sqrt(height*height + width*width));
int thetaSize= 180 * thetaDensity;
int lenght = pmax * 2 + 1;
double theta, p;
int max = 0;
math::matrix<int> hough(thetaSize,lenght);
for (int i = 0; i < thetaSize; i++) {
for (int j = 0 ; j < lenght ; j++) {
hough[i][j] = 0;
}
}
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (qGray(tempImage->pixel(i, j)) > 0) {
for (int k = 0; k < thetaSize; k++) {
theta = (k * 3.14) / (180 * thetaDensity);
p = i*cos(theta) + j*sin(theta);
hough[k][p+pmax]++;
if (hough[k][p+pmax] > max) {
max = hough[k][p+pmax];
}
}
}
}
}
PNM* newImage = new PNM(thetaSize,lenght, QImage::Format_Grayscale8);
for (int i = 0; i < thetaSize; i++) {
for (int j = 0; j < lenght; j++) {
int value = int(((hough[i][j] * 255)/ max));
newImage->setPixel(i, j, QColor(value,value,value).rgb());
}
}
return newImage;
}