zadanie 11
This commit is contained in:
parent
1028f64ba4
commit
a6f2f2346a
@ -26,7 +26,111 @@ PNM* CornerHarris::transform()
|
||||
|
||||
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
math::matrix<float> matrix_xx(width, height);
|
||||
math::matrix<float> matrix_yy(width, height);
|
||||
math::matrix<float> matrix_xy(width, height);
|
||||
math::matrix<float> cornerCandidates(width, height);
|
||||
math::matrix<float> cornerNonmaxSuppress(width, height);
|
||||
|
||||
for (int x = 0; x < width; x++)
|
||||
for (int y = 0; y < height; y++) {
|
||||
matrix_xx(x,y) = 0;
|
||||
matrix_yy(x,y) = 0;
|
||||
matrix_xy(x,y) = 0;
|
||||
cornerCandidates(x,y) = 0;
|
||||
cornerNonmaxSuppress(x,y) = 0;
|
||||
}
|
||||
|
||||
ConversionGrayscale conversionGrayscale(image);
|
||||
image = conversionGrayscale.transform();
|
||||
|
||||
BlurGaussian blurGaussian(image);
|
||||
blurGaussian.setParameter("size", 3);
|
||||
blurGaussian.setParameter("sigma", 1.0);
|
||||
image = blurGaussian.transform();
|
||||
|
||||
EdgeSobel edgeSobel(image);
|
||||
math::matrix<float>* Gx = edgeSobel.rawHorizontalDetection();
|
||||
math::matrix<float>* Gy = edgeSobel.rawVerticalDetection();
|
||||
|
||||
for (int i = 0; i < width; i++){
|
||||
for (int j = 0; j < height; j++) {
|
||||
matrix_xx(i,j) = (*Gx)(i,j) * (*Gx)(i,j);
|
||||
matrix_yy(i,j) = (*Gy)(i,j) * (*Gy)(i,j);
|
||||
matrix_xy(i,j) = (*Gx)(i,j) * (*Gy)(i,j);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 1; i < width - 1; i++){
|
||||
for (int j = 1; j < height - 1; j++) {
|
||||
|
||||
float summa_xx = 0, summa_yy = 0, summa_xy = 0;
|
||||
|
||||
for (int k = -1; k < 2; k++)
|
||||
for (int l = -1; l < 2; l++) {
|
||||
float gauss = BlurGaussian::getGauss(k,l,sigma);
|
||||
summa_xx = summa_xx + matrix_xx(i+k, j+l)*gauss;
|
||||
summa_yy = summa_yy + matrix_yy(i+k, j+l)*gauss;
|
||||
summa_xy = summa_xy + matrix_xy(i+k, j+l)*gauss;
|
||||
}
|
||||
|
||||
summa_xx = summa_xx/sigma_weight;
|
||||
summa_yy = summa_yy/sigma_weight;
|
||||
summa_xy = summa_xy/sigma_weight;
|
||||
|
||||
math::matrix<float> H(2,2);
|
||||
H(0,0) = summa_xx;
|
||||
H(0,1) = H(1,0) = summa_xy;
|
||||
H(1,1) = summa_yy;
|
||||
|
||||
float detH = summa_xx*summa_yy - summa_xy*summa_xy;
|
||||
float trH = summa_xx + summa_yy;
|
||||
float r = detH - k_param * pow(trH, 2);
|
||||
|
||||
if (r > threshold)
|
||||
cornerCandidates(i,j) = r;
|
||||
}
|
||||
}
|
||||
|
||||
bool search = true;
|
||||
|
||||
while (search) {
|
||||
search = false;
|
||||
for (int i = 1; i < width - 1; i++)
|
||||
for (int j = 1; j < height - 1; j++) {
|
||||
|
||||
bool max = true;
|
||||
|
||||
|
||||
|
||||
if (
|
||||
cornerCandidates(i-1, j-1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i, j-1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i+1, j-1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i+1, j) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i+1, j+1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i, j+1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i-1, j+1) < cornerCandidates(i,j) &&
|
||||
cornerCandidates(i-1, j) < cornerCandidates(i,j)
|
||||
)
|
||||
cornerNonmaxSuppress(i,j) = cornerCandidates(i,j);
|
||||
else {
|
||||
if (cornerCandidates(i,j) > 0)
|
||||
search = true;
|
||||
cornerNonmaxSuppress(i,j) = 0;
|
||||
}
|
||||
}
|
||||
cornerCandidates = cornerNonmaxSuppress;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < width; i++)
|
||||
for (int j = 0; j < height; j++) {
|
||||
if (cornerCandidates(i,j) == 0)
|
||||
newImage->setPixel(i,j,Qt::color0);
|
||||
else
|
||||
newImage->setPixel(i,j,Qt::color1);
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user