Zadanie 11
This commit is contained in:
parent
51b9d65213
commit
fdf0bb089a
@ -17,7 +17,66 @@ 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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user