Zad6 #6
@ -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<float> BlurGaussian::getMask(int size, Mode)
|
||||
{
|
||||
math::matrix<float> 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;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,24 @@ PNM* BlurLinear::transform()
|
||||
|
||||
math::matrix<float> 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);
|
||||
}
|
||||
|
@ -14,7 +14,15 @@ math::matrix<float> BlurUniform::getMask(int size, Mode)
|
||||
{
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for(int i=0;i<size;i++)
|
||||
{
|
||||
for(int j=0;j<size;j++)
|
||||
{
|
||||
mask[i][j]=1.00;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
@ -22,20 +22,98 @@ math::matrix<float> Convolution::getMask(int size, Mode mode = Normalize)
|
||||
{
|
||||
math::matrix<float> mask(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int x=0; x<size; x++)
|
||||
for (int y=0; y<size; y++)
|
||||
{
|
||||
mask[x][y] = 0;
|
||||
}
|
||||
|
||||
int half=size/2;
|
||||
|
||||
mask[half][half]=1;
|
||||
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
/** Does the convolution process for all pixels using the given mask. */
|
||||
PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
|
||||
PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = CyclicEdge)
|
||||
{
|
||||
int width = image->width(),
|
||||
height = image->height();
|
||||
int size=mask.rowno();
|
||||
|
||||
PNM* newImage = new PNM(width, height, image->format());
|
||||
math::matrix<float> red_window(size, size);
|
||||
math::matrix<float> blue_window(size, size);
|
||||
math::matrix<float> gray_window(size, size);
|
||||
math::matrix<float> green_window(size, size);
|
||||
|
||||
float mask_weight=sum(mask);
|
||||
float red_sum;
|
||||
float green_sum;
|
||||
float blue_sum;
|
||||
float gray_sum;
|
||||
|
||||
|
||||
|
||||
for (int x=0; x<width; x++)
|
||||
for (int y=0; y<height; y++)
|
||||
{
|
||||
|
||||
red_window=getWindow(x,y,size,RChannel,mode);
|
||||
blue_window=getWindow(x,y,size,BChannel,mode);
|
||||
green_window=getWindow(x,y,size,GChannel,mode);
|
||||
//gray_window=getWindow(x,y,size,LChannel,mode);
|
||||
|
||||
|
||||
red_window=join(red_window,mask);
|
||||
blue_window=join(blue_window,mask);
|
||||
green_window=join(green_window,mask);
|
||||
|
||||
//gray_window=join(gray_window,mask);
|
||||
|
||||
red_sum=sum(red_window);
|
||||
green_sum=sum(green_window);
|
||||
blue_sum=sum(blue_window);
|
||||
//gray_sum=sum(gray_window);
|
||||
|
||||
|
||||
if(mask_weight>0)
|
||||
{
|
||||
red_sum=red_sum/mask_weight;
|
||||
blue_sum=blue_sum/mask_weight;
|
||||
green_sum=green_sum/mask_weight;
|
||||
//gray_sum=gray_sum/mask_weight;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(red_sum>=0 && red_sum<=255 && green_sum>=0 && green_sum<=255 && blue_sum>=0 && blue_sum<=255)
|
||||
{
|
||||
newImage->setPixel(x,y, QColor(red_sum,green_sum,blue_sum).rgb());
|
||||
}
|
||||
else if (red_sum>=0 && red_sum<=255 && green_sum>=0 && green_sum<=255)
|
||||
{
|
||||
int old_blue = qBlue(newImage->pixel(x,y));
|
||||
newImage->setPixel(x,y, QColor(red_sum,green_sum,old_blue).rgb());
|
||||
}
|
||||
else if (blue_sum>=0 && blue_sum<=255 && green_sum>=0 && green_sum<=255)
|
||||
{
|
||||
int old_red = qRed(newImage->pixel(x,y));
|
||||
newImage->setPixel(x,y, QColor(old_red,green_sum,blue_sum).rgb());
|
||||
}
|
||||
else if (blue_sum>=0 && blue_sum<=255 && red_sum>=0 && red_sum<=255)
|
||||
{
|
||||
int old_green = qGreen(newImage->pixel(x,y));
|
||||
newImage->setPixel(x,y, QColor(red_sum,old_green,blue_sum).rgb());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return newImage;
|
||||
}
|
||||
@ -48,7 +126,12 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
|
||||
int size = A.rowno();
|
||||
math::matrix<float> C(size, size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int x=0; x<size; x++)
|
||||
for (int y=0; y<size; y++)
|
||||
{
|
||||
C[x][y]=A[x][y]*B[x][y];
|
||||
}
|
||||
|
||||
|
||||
return C;
|
||||
}
|
||||
@ -58,7 +141,15 @@ const float Convolution::sum(const math::matrix<float> A)
|
||||
{
|
||||
float sum = 0.0;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
int size=A.rowno();
|
||||
|
||||
for (int x=0; x<size; x++)
|
||||
for (int y=0; y<size; y++)
|
||||
{
|
||||
sum=sum+A[x][y];
|
||||
}
|
||||
|
||||
|
||||
|
||||
return sum;
|
||||
|
||||
@ -70,8 +161,20 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
|
||||
{
|
||||
int size = A.rowno();
|
||||
math::matrix<float> C(size, size);
|
||||
int counter_i=0;
|
||||
int counter_j=0;
|
||||
|
||||
|
||||
for (int x=size-1; x>=0; x--)
|
||||
{
|
||||
for (int y=size-1; y>=0; y--)
|
||||
{
|
||||
C[x][y]=A[counter_i][counter_j];
|
||||
counter_j++;
|
||||
}
|
||||
counter_i++;
|
||||
}
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return C;
|
||||
}
|
||||
|
@ -99,34 +99,59 @@ QRgb Transformation::getPixel(int x, int y, Mode mode)
|
||||
}
|
||||
|
||||
/** Returns a pixel using the Cyclic mode:
|
||||
* pixel(x,y) = pixel(x%width, y%width);
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
QRgb Transformation::getPixelCyclic(int x, int y)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
int height=image->height();
|
||||
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<float> Transformation::getWindow(int x, int y, int size,
|
||||
Channel channel,
|
||||
Mode mode = RepeatEdge)
|
||||
{
|
||||
math::matrix<float> window(size,size);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
math::matrix<float> 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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user