diff --git a/src/core/transformations/edge_gradient.cpp b/src/core/transformations/edge_gradient.cpp index a36a5b8..d9e87d7 100644 --- a/src/core/transformations/edge_gradient.cpp +++ b/src/core/transformations/edge_gradient.cpp @@ -22,10 +22,43 @@ PNM* EdgeGradient::horizontalDetection() PNM* EdgeGradient::transform() { + 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;iwidth();i++) + { + for(int j=0;jheight();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)); + +} + + diff --git a/src/core/transformations/edge_gradient.h b/src/core/transformations/edge_gradient.h index 331ccc1..158d64a 100644 --- a/src/core/transformations/edge_gradient.h +++ b/src/core/transformations/edge_gradient.h @@ -10,6 +10,7 @@ public: EdgeGradient(PNM*, ImageViewer*); virtual PNM* transform(); + static float getEdgeValue(int, int); PNM* verticalDetection(); PNM* horizontalDetection(); diff --git a/src/core/transformations/edge_laplacian.cpp b/src/core/transformations/edge_laplacian.cpp index 8c26718..9d7714c 100644 --- a/src/core/transformations/edge_laplacian.cpp +++ b/src/core/transformations/edge_laplacian.cpp @@ -14,8 +14,15 @@ math::matrix EdgeLaplacian::getMask(int, Mode) { int size = getParameter("size").toInt(); math::matrix mask(size, size); + int r=size/2; + + for (int x=0; x EdgeLaplaceOfGauss::getMask(int, Mode) double sigma = getParameter("sigma").toDouble(); math::matrix mask(size, size); + int r=size/2; + + for(int i=0;ig_x = math::matrix(size,size); + this->g_y = math::matrix(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; + + + + } diff --git a/src/core/transformations/edge_roberts.cpp b/src/core/transformations/edge_roberts.cpp index 0428da9..99a29c8 100644 --- a/src/core/transformations/edge_roberts.cpp +++ b/src/core/transformations/edge_roberts.cpp @@ -14,5 +14,22 @@ EdgeRoberts::EdgeRoberts(PNM* img, ImageViewer* iv) : void EdgeRoberts::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + + int size = 2; + + + this->g_x = math::matrix(size,size); + this->g_y = math::matrix(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; + } diff --git a/src/core/transformations/edge_sobel.cpp b/src/core/transformations/edge_sobel.cpp index 6ef4bff..d99a057 100644 --- a/src/core/transformations/edge_sobel.cpp +++ b/src/core/transformations/edge_sobel.cpp @@ -14,7 +14,33 @@ EdgeSobel::EdgeSobel(PNM* img) : void EdgeSobel::prepareMatrices() { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int size = 3; + + + this->g_x = math::matrix(size,size); + this->g_y = math::matrix(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* EdgeSobel::rawHorizontalDetection() diff --git a/src/core/transformations/edge_zero.cpp b/src/core/transformations/edge_zero.cpp index 541943f..b180705 100644 --- a/src/core/transformations/edge_zero.cpp +++ b/src/core/transformations/edge_zero.cpp @@ -20,11 +20,66 @@ PNM* EdgeZeroCrossing::transform() int size = getParameter("size").toInt(); double sigma = getParameter("sigma").toDouble(); int t = getParameter("threshold").toInt(); + int v = 128; + int r=size/2; 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 wR = gaussImage->getWindow(x,y,size,RChannel,CyclicEdge); + math::matrix wB = gaussImage->getWindow(x,y,size,BChannel,CyclicEdge); + math::matrix 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; } +float EdgeZeroCrossing::maxValue(math::matrix mask, int size) +{ + float max=mask[0][0]; + + for (int x=0; x max) + max=mask[x][y]; + + return max; +} + +float EdgeZeroCrossing::minValue(math::matrix mask, int size) +{ + float min=mask[0][0]; + + for (int x=0; x mask, int size); + float minValue(math::matrix mask, int size); }; #endif // EDGE_ZERO_H