Zadanie_08_Jonasz

This commit is contained in:
Jonasz Świtała 2020-04-27 01:12:34 +02:00
parent 17f063074c
commit 886566e620
9 changed files with 188 additions and 10 deletions

View File

@ -22,10 +22,43 @@ PNM* EdgeGradient::horizontalDetection()
PNM* EdgeGradient::transform() PNM* EdgeGradient::transform()
{ {
PNM* newImage = new PNM(image->width(), image->height(), image->format()); PNM* newImage = new PNM(image->width(), image->height(), image->format());
PNM* imageX;
imageX=verticalDetection();
PNM* imageY;
imageY=horizontalDetection();
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return newImage;
for(int i=0;i<image->width();i++)
{
for(int j=0;j<image->height();j++)
{
float imageX_red = qRed(imageX->pixel(i,j));
float imageX_green = qGreen(imageX->pixel(i,j));
float imageX_blue = qBlue(imageX->pixel(i,j));
float imageY_red = qRed(imageY->pixel(i,j));
float imageY_green = qGreen(imageY->pixel(i,j));
float imageY_blue = qBlue(imageY->pixel(i,j));
float ImageNew_red=getEdgeValue(imageX_red, imageY_red);
float ImageNew_green=getEdgeValue(imageX_green, imageY_green);
float ImageNew_blue=getEdgeValue(imageX_blue, imageY_blue);
newImage->setPixel(i,j, QColor(ImageNew_red, ImageNew_green, ImageNew_blue).rgb());
}
}
return newImage;
} }
float EdgeGradient::getEdgeValue(int x, int y)
{
return sqrt(pow(x,2)+pow(y,2));
}

View File

@ -10,6 +10,7 @@ public:
EdgeGradient(PNM*, ImageViewer*); EdgeGradient(PNM*, ImageViewer*);
virtual PNM* transform(); virtual PNM* transform();
static float getEdgeValue(int, int);
PNM* verticalDetection(); PNM* verticalDetection();
PNM* horizontalDetection(); PNM* horizontalDetection();

View File

@ -14,8 +14,15 @@ math::matrix<float> EdgeLaplacian::getMask(int, Mode)
{ {
int size = getParameter("size").toInt(); int size = getParameter("size").toInt();
math::matrix<float> mask(size, size); math::matrix<float> mask(size, size);
int r=size/2;
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
mask[x][y]=-1;
mask[r][r]=(size*size)-1;
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask; return mask;
} }

View File

@ -18,17 +18,24 @@ math::matrix<float> EdgeLaplaceOfGauss::getMask(int, Mode)
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
math::matrix<float> mask(size, size); math::matrix<float> mask(size, size);
int r=size/2;
for(int i=0;i<size;i++)
for(int j=0;j<size;j++)
mask[i][j]=getLoG(i-r, j-r, sigma);
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return mask; return mask;
} }
float EdgeLaplaceOfGauss::getLoG(int x, int y, float s) float EdgeLaplaceOfGauss::getLoG(int x, int y, float s)
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
return 0; float results;
results=(((pow(x,2)+pow(y,2))-2)/pow(s,2))*BlurGaussian::getGauss(x,y,s);
return results;
} }
int EdgeLaplaceOfGauss::getSize() int EdgeLaplaceOfGauss::getSize()

View File

@ -14,6 +14,36 @@ EdgePrewitt::EdgePrewitt(PNM*img, ImageViewer* iv) :
void EdgePrewitt::prepareMatrices() void EdgePrewitt::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int size = 3;
this->g_x = math::matrix<float>(size,size);
this->g_y = math::matrix<float>(size,size);
g_x[0][0]=-1;
g_x[0][1]=0;
g_x[0][2]=1;
g_x[1][0]=-1;
g_x[1][1]=0;
g_x[1][2]=1;
g_x[2][0]=-1;
g_x[2][1]=-0;
g_x[2][2]=1;
g_y[0][0]=-1;
g_y[0][1]=-1;
g_y[0][2]=-1;
g_y[1][0]=0;
g_y[1][1]=0;
g_y[1][2]=0;
g_y[2][0]=1;
g_y[2][1]=1;
g_y[2][2]=1;
} }

View File

@ -14,5 +14,22 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) :
void EdgeRoberts::prepareMatrices() void EdgeRoberts::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
int size = 2;
this->g_x = math::matrix<float>(size,size);
this->g_y = math::matrix<float>(size,size);
g_x[0][0]=1;
g_x[0][1]=0;
g_x[1][0]=0;
g_x[1][1]=-1;
g_y[0][0]=0;
g_y[0][1]=1;
g_y[1][0]=-1;
g_y[1][1]=0;
} }

View File

@ -14,7 +14,33 @@ EdgeSobel::EdgeSobel(PNM* img) :
void EdgeSobel::prepareMatrices() void EdgeSobel::prepareMatrices()
{ {
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; int size = 3;
this->g_x = math::matrix<float>(size,size);
this->g_y = math::matrix<float>(size,size);
g_x[0][0]=-1;
g_x[0][1]=0;
g_x[0][2]=1;
g_x[1][0]=-2;
g_x[1][1]=0;
g_x[1][2]=2;
g_x[2][0]=-1;
g_x[2][1]=-0;
g_x[2][2]=1;
g_y[0][0]=-1;
g_y[0][1]=-2;
g_y[0][2]=-1;
g_y[1][0]=0;
g_y[1][1]=0;
g_y[1][2]=0;
g_y[2][0]=1;
g_y[2][1]=2;
g_y[2][2]=1;
} }
math::matrix<float>* EdgeSobel::rawHorizontalDetection() math::matrix<float>* EdgeSobel::rawHorizontalDetection()

View File

@ -20,11 +20,66 @@ PNM* EdgeZeroCrossing::transform()
int size = getParameter("size").toInt(); int size = getParameter("size").toInt();
double sigma = getParameter("sigma").toDouble(); double sigma = getParameter("sigma").toDouble();
int t = getParameter("threshold").toInt(); int t = getParameter("threshold").toInt();
int v = 128;
int r=size/2;
PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8); PNM* newImage = new PNM(width, height, QImage::Format_Grayscale8);
qDebug() << Q_FUNC_INFO << "Not implemented yet!"; EdgeLaplaceOfGauss * gaussImage = new EdgeLaplaceOfGauss(image);
for (int x=0; x<width; x++)
for (int y=0; y<height; y++)
{
math::matrix<float> wR = gaussImage->getWindow(x,y,size,RChannel,CyclicEdge);
math::matrix<float> wB = gaussImage->getWindow(x,y,size,BChannel,CyclicEdge);
math::matrix<float> wG = gaussImage->getWindow(x,y,size,GChannel,CyclicEdge);
float maxR=maxValue(wR,size);
float maxG=maxValue(wG,size);
float maxB=maxValue(wB,size);
float minR=minValue(wR,size);
float minG=minValue(wG,size);
float minB=minValue(wB,size);
if (minR < v-t && maxR > v+t)
newImage->setPixel(x, y,gaussImage->getPixel(x,y,CyclicEdge));
else if (minG < v-t && maxG>v+t)
newImage->setPixel(x, y, gaussImage->getPixel(x,y,CyclicEdge));
else if (minB < v-t && maxB > v+t)
newImage->setPixel(x, y, gaussImage->getPixel(x,y,CyclicEdge));
else
{
newImage->setPixel(x, y, 0);
}
}
return newImage; return newImage;
} }
float EdgeZeroCrossing::maxValue(math::matrix<float> mask, int size)
{
float max=mask[0][0];
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
if (mask[x][y] > max)
max=mask[x][y];
return max;
}
float EdgeZeroCrossing::minValue(math::matrix<float> mask, int size)
{
float min=mask[0][0];
for (int x=0; x<size; x++)
for (int y=0; y<size; y++)
if (mask[x][y] < min)
min=mask[x][y];
return min;
}

View File

@ -10,6 +10,8 @@ public:
EdgeZeroCrossing(PNM*, ImageViewer*); EdgeZeroCrossing(PNM*, ImageViewer*);
virtual PNM* transform(); virtual PNM* transform();
float maxValue(math::matrix<float> mask, int size);
float minValue(math::matrix<float> mask, int size);
}; };
#endif // EDGE_ZERO_H #endif // EDGE_ZERO_H