Zadanie_12_Jonasz

This commit is contained in:
Jonasz Świtała 2020-05-24 20:26:35 +02:00
parent 33a7f9b2af
commit b11f6cfcdb

View File

@ -24,9 +24,115 @@ PNM* CornerHarris::transform()
int width = image->width(),
height = image->height();
//Krok1 Zdef i wypelij zerami
math::matrix<float> Ixx(width, height);
math::matrix<float> Iyy(width, height);
math::matrix<float> Ixy(width, height);
math::matrix<float> CC(width, height);
math::matrix<float> CNS(width, height);
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
Ixx[x][y]=0;
Iyy[x][y]=0;
Ixy[x][y]=0;
CC[x][y]=0;
CNS[x][y]=0;
}
//Krok 2 skala szarosci
ConversionGrayscale cg(image);
PNM* gray_image=cg.transform();
//Krok 3 rozmyj
BlurGaussian bg(gray_image);
bg.setParameter("size",3);
bg.setParameter("sigma",1.6);
PNM* blur_image=bg.transform();
//Krok 4 sobel
EdgeSobel es(blur_image);
math::matrix<float> *Gx=es.rawHorizontalDetection();
math::matrix<float> *Gy=es.rawVerticalDetection();
//Krok 5 wzorek
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
Ixx[x][y]=(*Gx)[x][y] * (*Gx)[x][y];
Iyy[x][y]=(*Gy)[x][y] * (*Gy)[x][y];
Ixy[x][y]=(*Gx)[x][y] * (*Gy)[x][y];
}
//Krok 6 wzorek
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
float Sxx=0;
float Syy=0;
float Sxy=0;
math::matrix<float> H(2, 2);
for(int z=-1;z<=1;z++) //Znacznik sumy
for(int a=-1;a<=1;a++)
{
Sxx+=Ixx[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
Syy+=Iyy[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
Sxy+=Ixy[x+z][y+a]*BlurGaussian::getGauss(z,a,sigma);
}
Sxx=Sxx/sigma_weight;
Syy=Syy/sigma_weight;
Sxy=Sxy/sigma_weight;
H[0][0]=Sxx;
H[0][1]=Sxy;
H[1][0]=Sxy;
H[1][1]=Syy;
float detH=H[0][0]*H[1][1]-H[0][1]*H[1][0];
//Wyznaczkik + suma po przekatnej kwadratowej
float r = detH - k_param * pow(H[0][0] + H[1][1], 2);
if(r>threshold) CC[x][y]=r;
}
bool search=1;
//Krok 8
while(search==1)
{
search=0;
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
float max=CC[x][y];
if(max > CC[x][y-1] && max > CC[x][y+1] && max > CC[x+1][y-1] && max > CC[x+1][y] && max > CC[x+1][y+1] && max > CC[x-1][y-1] && max > CC[x-1][y] && max > CC[x-1][y+1])
CNS[x][y]=CC[x][y];
else {
if(CC[x][y]>0)
{
CNS[x][y]=0;
search=1;
}
}
}
CC=CNS;
}
PNM* newImage = new PNM(width, height, QImage::Format_Mono);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
//Krok 9
for (int x=1; x<width-1; x++)
for (int y=1; y<height-1; y++)
{
if(CC[x][y]==0) newImage->setPixel(x,y,0);
else newImage->setPixel(x,y,1);
}
return newImage;
}