diff --git a/src/core/transformations/blur_gaussian.cpp b/src/core/transformations/blur_gaussian.cpp index 3eba6e4..af4903e 100644 --- a/src/core/transformations/blur_gaussian.cpp +++ b/src/core/transformations/blur_gaussian.cpp @@ -18,22 +18,32 @@ PNM* BlurGaussian::transform() radius = (size/2)+1; sigma = getParameter("sigma").toDouble(); - return convolute(getMask(size, Normalize), RepeatEdge); + return convolute(getMask(size, Normalize), CyclicEdge); } math::matrix BlurGaussian::getMask(int size, Mode) { math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + if(size%2!=0) radius=size/2; + + + for(int i=-radius;i<=radius;i++) + { + for(int j=-radius;j<=radius;j++) + { + + mask[i+radius][j+radius]=getGauss(i,j,sigma); + } + } return mask; } float BlurGaussian::getGauss(int x, int y, float sigma) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; - return 0; + float gauss= exp(-(x*x+y*y)/(2*sigma*sigma))/(2*M_PI*sigma*sigma); + return gauss; } diff --git a/src/core/transformations/blur_linear.cpp b/src/core/transformations/blur_linear.cpp index c24f9e8..5c2f84f 100644 --- a/src/core/transformations/blur_linear.cpp +++ b/src/core/transformations/blur_linear.cpp @@ -13,12 +13,29 @@ BlurLinear::BlurLinear(PNM* img, ImageViewer* iv) : PNM* BlurLinear::transform() { int maskSize = getParameter("size").toInt(); - QList tmpMask = getParameter("mask").toList(); - bool normalize = getParameter("normalize").toBool(); + QList tmpMask = getParameter("mask").toList(); + bool normalize = getParameter("normalize").toBool(); - math::matrix mask(maskSize, maskSize); + math::matrix mask(maskSize, maskSize); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int index = 0; + float sum = 0; + for (int x = 0; x < maskSize; x++) { + for (int y = 0; y < maskSize; y++) { + mask[x][y] = tmpMask.at(index).toDouble(); + index++; + sum = sum + mask[x][y]; + } + } - return convolute(mask, RepeatEdge); + if(normalize == true && sum != 0.0 ){ + + for (int x = 0; x < maskSize; x++) { + for (int y = 0; y < maskSize; y++) { + mask[x][y] = mask[x][y] / sum; + + } + } + } + return convolute(mask, CyclicEdge); } diff --git a/src/core/transformations/blur_uniform.cpp b/src/core/transformations/blur_uniform.cpp index 36604c4..fb199cc 100644 --- a/src/core/transformations/blur_uniform.cpp +++ b/src/core/transformations/blur_uniform.cpp @@ -14,7 +14,15 @@ math::matrix BlurUniform::getMask(int size, Mode) { math::matrix mask(size, size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + for(int i=0;iheight(); + int width=image->width(); + + /* + if(x>width) x=x%width; + if(y>height) y=y%height; + if(x<0) x=width-x; + if(y<0) y=height-y; + */ + + x=(width+(x%width))%width; + y=(height+(y%height))%height; return image->pixel(x,y); } -/** - * Returns a given pixel - * If the pixel is out of image boundaries Black is returned; - */ + QRgb Transformation::getPixelNull(int x, int y) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + int height=image->height(); + int width=image->width(); - return image->pixel(x,y); + QRgb pixel = image->pixel(x,y); + + if(x>width || x<0 || y>height || y<0) + { + int v=PIXEL_VAL_MAX; + image->setPixel(x,y, QColor(v,v,v).rgb()); + } + + return pixel; } -/** - * Returns given pixel. - * If the pixel is out of image boundaries - * the nearest edge pixel is given - */ + QRgb Transformation::getPixelRepeat(int x, int y) { - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + + int height=image->height(); + int width=image->width(); + + + if(x>width) x=width; + if(y>height) y=height; + if(x<0) x=0; + if(y<0) y=0; + + return image->pixel(x,y); } @@ -136,9 +161,26 @@ math::matrix Transformation::getWindow(int x, int y, int size, Channel channel, Mode mode = RepeatEdge) { - math::matrix window(size,size); - qDebug() << Q_FUNC_INFO << "Not implemented yet!"; + math::matrix window(size,size); + int temp,r; + + + r=size/2; + + for(int i=-r;i<=r;i++) + { + for(int j=-r;j<=r;j++) + { + + if(channel==RChannel) temp = qRed(getPixel(x+i,y+j, CyclicEdge)); + if(channel==GChannel) temp = qGreen (getPixel(x+i,y+j, CyclicEdge)); + if(channel==BChannel) temp = qBlue(getPixel(x+i,y+j, CyclicEdge)); + //if(channel==LChannel) temp= qGray(getPixel(i,j, mode)); + + window[i+r][j+r]=temp; + } + } return window; }