Zadanie 11 - lines

This commit is contained in:
Dawid_Kreft 2020-05-18 00:12:00 +02:00
parent 354eba6479
commit 33a7f9b2af
2 changed files with 64 additions and 3 deletions

View File

@ -17,8 +17,42 @@ PNM* BinarizationGradient::transform()
PNM* newImage = new PNM(width, height, QImage::Format_Mono); PNM* newImage = new PNM(width, height, QImage::Format_Mono);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int Gmax = 0;
int numerator = 0;
int denominator = 0;
for(int x=1; x<width-1; x++){
for(int y=1; y<height-1; y++){
int t = (qRed(image->pixel(x,y)) + qGreen(image->pixel(x,y)) + qBlue(image->pixel(x,y))) / 3;
int Gxa = (qRed(image->pixel(x-1,y)) + qGreen(image->pixel(x-1,y)) + qBlue(image->pixel(x-1,y))) / 3;
int Gxb = (qRed(image->pixel(x+1,y)) + qGreen(image->pixel(x+1,y)) + qBlue(image->pixel(x+1,y))) / 3;
int Gya = (qRed(image->pixel(x,y+1)) + qGreen(image->pixel(x,y+1)) + qBlue(image->pixel(x,y+1))) / 3;
int Gyb= (qRed(image->pixel(x,y-1)) + qGreen(image->pixel(x,y-1)) + qBlue(image->pixel(x,y-1))) / 3;
int Gx = Gxa - Gxb;
int Gy = Gya - Gyb;
if (Gx > Gy) Gmax = Gx;
else Gmax = Gy;
numerator += t * Gmax;
denominator += Gmax;
}
}
int T = numerator/denominator;
// create new image
for(int i=0; i<width; i++){
for(int j=0; j<height; j++){
QRgb pixel = image->pixel(i,j);
int tempValue = (qRed(pixel) + qGreen(pixel) + qBlue(pixel)) / 3;
if ( tempValue > T ){
newImage->setPixel(i, j, Qt::color1);
}
else {
newImage->setPixel(i, j, Qt::color0);
}
}
}
return newImage; return newImage;
} }

View File

@ -24,7 +24,34 @@ PNM* HoughLines::transform()
PNM* newImage = new PNM(image->copy()); PNM* newImage = new PNM(image->copy());
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; // step 1
EdgeLaplacian* edgeLA = new EdgeLaplacian(image);
edgeLA->setParameter("size", 3);
PNM* tempImage = edgeLA->transform();
// step 2
BinarizationGradient* binarizationGradient = new BinarizationGradient(tempImage);
PNM* binImage = binarizationGradient->transform();
// step 3
Hough* hough = new Hough(binImage);
hough->setParameter("theta_density", 3);
hough->setParameter("skip_edge_detection", true);
tempImage = hough->transform();
// step 4
QPainter p(newImage);
p.setPen(Qt::red);
for(int i=0; i < tempImage->width(); i++) {
for(int j=0; j < tempImage->height(); j++) {
if(qGray(tempImage->pixel(i, j)) > threshold) {
double rtheta = ((double)i/3.0)*M_PI/180.0;
int rrho = j - tempImage->height()/2;
p.drawLine(0, round(rrho/sin(rtheta)), newImage->width()-1, round((rrho - (newImage->width()-1)*cos(rtheta))/sin(rtheta)));
}
if (!drawWholeLines == true){
if (qRed(binImage->pixel(i, j)) == 0){
newImage->setPixel(i, j, image->pixel(i, j));
}
}
}
}
return newImage; return newImage;
} }