zadanie-9

This commit is contained in:
Patrycjusz Mania 2021-06-03 13:08:56 +02:00
parent 424df7fc49
commit cf79d13cc8

View File

@ -2,6 +2,7 @@
#include "conversion_grayscale.h"
#include "edge_laplacian.h"
#include <math.h>
Hough::Hough(PNM* img) :
Transformation(img)
@ -16,8 +17,47 @@ Hough::Hough(PNM* img, ImageViewer* super) :
PNM* Hough::transform()
{
int thetaDensity = getParameter("theta_density").toInt();
bool skip_edge = getParameter("skip_edge_detection").toBool();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
PNM* newImage = new PNM(image->width(), image->height(), QImage::Format_Grayscale8);
float diagonal = sqrt(pow(image->width(), 2) + pow(image->height(), 2));
float thetaSize = 180 * thetaDensity;
return 0;
ConversionGrayscale gray(image);
newImage = gray.transform();
if (skip_edge == false) {
EdgeLaplacian laplacian(newImage);
laplacian.setParameter("size", 5);
newImage = laplacian.transform();
}
int width = thetaSize;
int height = (diagonal * 2) + 1;
PNM* resultImage = new PNM(width, height, QImage::Format_Grayscale8);
math::matrix<float> hought(width, height, 0.0);
math::matrix<float> theta(width, height);
for (int x=0;x<image->width();++x) {
for (int y=0;y<image->height();++y) {
if (qGray(newImage->pixel(x,y)) > 0) {
for (int k = 0; k < thetaSize; ++k) {
float theta = (k * M_PI) / (thetaDensity * 180.0);
float p = (x * cos(theta)) + (y * sin(theta));
hought[k][(int)(diagonal + p)]++;
}
}
}
}
float maxHough = 255 / hought.max();
for (int x=0;x<width;++x) {
for (int y=0;y<height;++y) {
hought[x][y] *= maxHough;
resultImage->setPixel(x,y, QColor(hought[x][y], hought[x][y], hought[x][y]).rgb());
}
}
delete newImage;
return resultImage;
}