Zadanie 11

This commit is contained in:
Sebastian Spaloniak 2020-05-31 12:17:02 +02:00
parent 51b9d65213
commit fdf0bb089a
2 changed files with 117 additions and 5 deletions

View File

@ -14,10 +14,69 @@ Hough::Hough(PNM* img, ImageViewer* super) :
}
PNM* Hough::transform()
{
{
int thetaDensity = getParameter("theta_density").toInt();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int width = image->width(),
height = image->height();
return 0;
PNM* tempImage = new PNM(width, height, QImage::Format_Indexed8);
tempImage = ConversionGrayscale(image).transform();
if (!getParameter("skip_edge_detection").toBool())
{
tempImage = EdgeLaplacian(tempImage).transform();
}
int pmax = (int)sqrt(pow((double)height, 2.0) + pow((double)width, 2.0));
int thetaSize = 180 * thetaDensity;
PNM* newImage = new PNM(thetaSize, pmax * 2 + 1, QImage::Format_Indexed8);
math::matrix<int> hough(thetaSize, pmax * 2 + 1);
for (int i = 0; i < thetaSize; i++)
{
for (int j = 0, len = pmax * 2 + 1; j < len; j++)
{
hough(i, j) = 0;
}
}
double t, r;
int max = 0;
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
QRgb pixel = tempImage->pixel(i, j);
if (qGray(pixel) > 0)
{
for (int k = 0; k < thetaSize; k++)
{
t = ((double)k * 3.14159265359) / (180.0 * thetaDensity);
r = i*cos(t) + j*sin(t);
hough(k, (int)floor(r + pmax))++;
if (hough(k, (int)floor(r + pmax)) > max)
{
max = hough(k, (int)floor(r + pmax));
}
}
}
}
}
for (int i = 0; i < thetaSize; i++)
{
for (int j = 0, len = pmax * 2 + 1; j < len; j++)
{
newImage->setPixel(i, j, (int)(((hough(i, j) * 255)/ max)));
}
}
return newImage;
}

View File

@ -18,13 +18,66 @@ HoughLines::HoughLines(PNM* img, ImageViewer* iv) :
PNM* HoughLines::transform()
{
// Cut of value from the image;
int threshold = getParameter("threshold").toInt();
bool drawWholeLines = getParameter("draw_whole_lines").toBool();
PNM* newImage = new PNM(image->copy());
PNM* tempImage, *binImage;
EdgeLaplacian* edla = new EdgeLaplacian(image);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
edla->setParameter("size", 3);
tempImage = edla->transform();
BinarizationGradient* binar = new BinarizationGradient(tempImage);
binImage = binar->transform();
Hough* hough = new Hough(binImage);
hough->setParameter("theta_density", 3);
hough->setParameter("skip_edge_detection", true);
tempImage = hough->transform();
QPainter* qPainter = new QPainter(newImage);
qPainter->setPen(Qt::red);
int i1 = 0, i2, j1, j2;
for (int t = 0; t < tempImage->width(); t++)
{
for (int r = 0; r < tempImage->height(); r++)
{
QRgb pixel = tempImage->pixel(t, r);
int valPixel = qGray(pixel);
if (valPixel > threshold)
{
int real_rho = r - tempImage->height() / 2;
double rtheta = (t / 3.0)*M_PI / 180.0;
double ctheta = cos(rtheta), stheta = sin(rtheta);
j1 = round(real_rho / stheta);
i2 = newImage->width() - 1;
j2 = round((real_rho - (newImage->width() - 1)*ctheta) / stheta);
qPainter->drawLine(i1, j1, i2, j2);
}
}
}
if (!drawWholeLines == true)
{
for (int i = 0; i < newImage->width(); i++)
{
for (int j = 0; j < newImage->height(); j++)
{
if (qRed(binImage->pixel(i, j)) == 0)
{
newImage->setPixel(i, j, image->pixel(i, j));
}
}
}
}
return newImage;
}