zadanie - 11 (harris)
This commit is contained in:
parent
bee9d1f89c
commit
1e1c4c2a5e
@ -26,7 +26,101 @@ PNM* CornerHarris::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!";
|
math::matrix<float> xx(width, height);
|
||||||
|
math::matrix<float> yy(width, height);
|
||||||
|
math::matrix<float> 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++) {
|
||||||
|
xx(x,y) = yy(x,y) = xy(x,y) = cornerCandidates(x,y) = 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++) {
|
||||||
|
xx(i,j) = (*Gx)(i,j) * (*Gx)(i,j);
|
||||||
|
yy(i,j) = (*Gy)(i,j) * (*Gy)(i,j);
|
||||||
|
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 Sxx = 0, Syy = 0, Sxy = 0;
|
||||||
|
|
||||||
|
for (int k = -1; k < 2; k++)
|
||||||
|
for (int l = -1; l < 2; l++) {
|
||||||
|
float gauss = BlurGaussian::getGauss(k,l,sigma);
|
||||||
|
Sxx = Sxx + xx(i+k, j+l)*gauss;
|
||||||
|
Syy = Syy + yy(i+k, j+l)*gauss;
|
||||||
|
Sxy = Sxy + xy(i+k, j+l)*gauss;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sxx = Sxx/sigma_weight;
|
||||||
|
Syy = Syy/sigma_weight;
|
||||||
|
Sxy = Sxy/sigma_weight;
|
||||||
|
|
||||||
|
math::matrix<float> H(2,2);
|
||||||
|
H(0,0) = Sxx;
|
||||||
|
H(0,1) = H(1,0) = Sxy;
|
||||||
|
H(1,1) = Syy;
|
||||||
|
|
||||||
|
float detH = H(0,0)*H(1,1) - H(0,1)*H(1,0);
|
||||||
|
float trH = H(0,0) + H(1,1);
|
||||||
|
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;
|
||||||
|
|
||||||
|
for (int k = -1; k < 2; k++)
|
||||||
|
for (int l = -1; l < 2; l++) {
|
||||||
|
if ((k!=0 || l!=0) && cornerCandidates(i+k, j+l) >= cornerCandidates(i,j))
|
||||||
|
max = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max)
|
||||||
|
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;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
@ -32,15 +32,11 @@ math::matrix<float>* EdgeSobel::rawHorizontalDetection()
|
|||||||
int height = image->height();
|
int height = image->height();
|
||||||
math::matrix<float>* x_gradient = new math::matrix<float>(width, height);
|
math::matrix<float>* x_gradient = new math::matrix<float>(width, height);
|
||||||
|
|
||||||
PNM* newImage = convolute(g_x, RepeatEdge);
|
for (int x = 0; x < width; x++)
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
for (int x=0;x<width;++x) {
|
(*x_gradient)(x,y) = sum(join(g_x, getWindow(x, y, 3, LChannel, RepeatEdge)));
|
||||||
for (int y=0;y<height;++y) {
|
|
||||||
(*x_gradient)[x][y] = qGray(newImage->pixel(x,y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete newImage;
|
|
||||||
return x_gradient;
|
return x_gradient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,15 +46,10 @@ math::matrix<float>* EdgeSobel::rawVerticalDetection()
|
|||||||
int height = image->height();
|
int height = image->height();
|
||||||
math::matrix<float>* y_gradient = new math::matrix<float>(width, height);
|
math::matrix<float>* y_gradient = new math::matrix<float>(width, height);
|
||||||
|
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
PNM* newImage = convolute(g_y, RepeatEdge);
|
for (int y = 0; y < height; y++) {
|
||||||
|
(*y_gradient)(x,y) = sum(join(g_y, getWindow(x, y, 3, LChannel, RepeatEdge)));
|
||||||
for (int x=0;x<width;++x) {
|
|
||||||
for (int y=0;y<height;++y) {
|
|
||||||
(*y_gradient)[x][y] = qGray(newImage->pixel(x,y));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
delete newImage;
|
|
||||||
return y_gradient;
|
return y_gradient;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user