zadanie-4
This commit is contained in:
parent
648df434f5
commit
11269543b1
@ -1,4 +1,6 @@
|
|||||||
|
#define _USE_MATH_DEFINES
|
||||||
#include "blur_gaussian.h"
|
#include "blur_gaussian.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
BlurGaussian::BlurGaussian(PNM* img) :
|
BlurGaussian::BlurGaussian(PNM* img) :
|
||||||
Convolution(img)
|
Convolution(img)
|
||||||
@ -25,15 +27,18 @@ math::matrix<float> BlurGaussian::getMask(int size, Mode)
|
|||||||
{
|
{
|
||||||
math::matrix<float> mask(size, size);
|
math::matrix<float> mask(size, size);
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int half = size / 2;
|
||||||
|
for (int x=0;x<size;++x) {
|
||||||
|
for (int y=0;y<size;++y) {
|
||||||
|
mask[x][y] = getGauss(x - half, y - half, sigma);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
float BlurGaussian::getGauss(int x, int y, float sigma)
|
float BlurGaussian::getGauss(int x, int y, float sigma)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
return exp(-((pow(x, 2.0) + pow(y, 2.0)) / 2 * pow(sigma, 2.0))) / (2 * M_PI * pow(sigma, 2.0));
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,22 @@ PNM* BlurLinear::transform()
|
|||||||
|
|
||||||
math::matrix<float> mask(maskSize, maskSize);
|
math::matrix<float> mask(maskSize, maskSize);
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
double maskSum = 0.0;
|
||||||
|
if (normalize) {
|
||||||
|
for (int i=0;i<tmpMask.size();++i) {
|
||||||
|
maskSum += tmpMask.at(i).toDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int x=0;x<maskSize;++x) {
|
||||||
|
for (int y=0;y<maskSize;++y) {
|
||||||
|
double val = tmpMask.at((x * maskSize) + y).toDouble();
|
||||||
|
if (normalize && maskSum != 0.0) {
|
||||||
|
val /= maskSum;
|
||||||
|
}
|
||||||
|
mask[x][y] = val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return convolute(mask, RepeatEdge);
|
return convolute(mask, RepeatEdge);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,11 @@ math::matrix<float> BlurUniform::getMask(int size, Mode)
|
|||||||
{
|
{
|
||||||
math::matrix<float> mask(size, size);
|
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] = 1.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,15 @@ math::matrix<float> Convolution::getMask(int size, Mode mode = Normalize)
|
|||||||
{
|
{
|
||||||
math::matrix<float> mask(size, size);
|
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) {
|
||||||
|
|
||||||
|
if (i / 2 == size / 2)
|
||||||
|
mask[i][j] = 1;
|
||||||
|
else
|
||||||
|
mask[i][j] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
@ -35,11 +43,35 @@ PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
|
|||||||
|
|
||||||
PNM* newImage = new PNM(width, height, image->format());
|
PNM* newImage = new PNM(width, height, image->format());
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
float weight = sum(mask);
|
||||||
|
|
||||||
|
for (int x=0; x<width; ++x) {
|
||||||
|
for (int y=0; y<height; ++y) {
|
||||||
|
int r = getOneChannelPixel(mask, x, y, mode, RChannel, weight);
|
||||||
|
int g = getOneChannelPixel(mask, x, y, mode, GChannel, weight);
|
||||||
|
int b = getOneChannelPixel(mask, x, y, mode, BChannel, weight);
|
||||||
|
newImage->setPixel(x, y, QColor(r,g,b).rgb());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return newImage;
|
return newImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Convolution::getOneChannelPixel(math::matrix<float>& mask, int x, int y, Mode mode, Channel channel, float weight) {
|
||||||
|
math::matrix<float> window = getWindow(x, y, mask.colsize(), channel, mode);
|
||||||
|
float summed = sum(join(window, mask));
|
||||||
|
if (weight != 0)
|
||||||
|
summed /= weight;
|
||||||
|
|
||||||
|
if (summed < 0)
|
||||||
|
summed = 0;
|
||||||
|
else if (summed > 255)
|
||||||
|
summed = 255;
|
||||||
|
return summed;
|
||||||
|
}
|
||||||
|
|
||||||
/** Joins to matrices by multiplying the A[i,j] with B[i,j].
|
/** Joins to matrices by multiplying the A[i,j] with B[i,j].
|
||||||
* Warning! Both Matrices must be squares with the same size!
|
* Warning! Both Matrices must be squares with the same size!
|
||||||
*/
|
*/
|
||||||
@ -48,7 +80,11 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
|
|||||||
int size = A.rowno();
|
int size = A.rowno();
|
||||||
math::matrix<float> C(size, size);
|
math::matrix<float> C(size, size);
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
for (int i=0; i<size; ++i) {
|
||||||
|
for (int j=0; j<size; ++j) {
|
||||||
|
C[i][j] = A[i][j] * B[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
@ -56,12 +92,7 @@ const math::matrix<float> Convolution::join(math::matrix<float> A, math::matrix<
|
|||||||
/** Sums all of the matrixes elements */
|
/** Sums all of the matrixes elements */
|
||||||
const float Convolution::sum(const math::matrix<float> A)
|
const float Convolution::sum(const math::matrix<float> A)
|
||||||
{
|
{
|
||||||
float sum = 0.0;
|
return A.sum();
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
|
||||||
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -71,7 +102,11 @@ const math::matrix<float> Convolution::reflection(const math::matrix<float> A)
|
|||||||
int size = A.rowno();
|
int size = A.rowno();
|
||||||
math::matrix<float> C(size, size);
|
math::matrix<float> C(size, size);
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
for (int i=0; i<size; ++i) {
|
||||||
|
for (int j=0; j<size; ++j) {
|
||||||
|
C[size - i][size - j] = A[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return C;
|
return C;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ protected:
|
|||||||
const math::matrix<float> join(math::matrix<float>, math::matrix<float>);
|
const math::matrix<float> join(math::matrix<float>, math::matrix<float>);
|
||||||
const float sum(math::matrix<float>);
|
const float sum(math::matrix<float>);
|
||||||
const math::matrix<float> reflection(math::matrix<float>);
|
const math::matrix<float> reflection(math::matrix<float>);
|
||||||
|
int getOneChannelPixel(math::matrix<float>& mask, int x, int y, Mode mode, Channel channel, float weight);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONVOLUTION_H
|
#endif // CONVOLUTION_H
|
||||||
|
@ -103,9 +103,9 @@ QRgb Transformation::getPixel(int x, int y, Mode mode)
|
|||||||
*/
|
*/
|
||||||
QRgb Transformation::getPixelCyclic(int x, int y)
|
QRgb Transformation::getPixelCyclic(int x, int y)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int width = image->size().width();
|
||||||
|
int height = image->size().height();
|
||||||
return image->pixel(x,y);
|
return image->pixel(x % width,y % height);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,7 +114,12 @@ QRgb Transformation::getPixelCyclic(int x, int y)
|
|||||||
*/
|
*/
|
||||||
QRgb Transformation::getPixelNull(int x, int y)
|
QRgb Transformation::getPixelNull(int x, int y)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
const QRgb blackPixel = qRgb(0, 0, 0);
|
||||||
|
|
||||||
|
int width = image->size().width();
|
||||||
|
int height = image->size().height();
|
||||||
|
if (x >= width || x < 0 || y >= height || y < 0)
|
||||||
|
return blackPixel;
|
||||||
|
|
||||||
return image->pixel(x,y);
|
return image->pixel(x,y);
|
||||||
}
|
}
|
||||||
@ -126,8 +131,14 @@ QRgb Transformation::getPixelNull(int x, int y)
|
|||||||
*/
|
*/
|
||||||
QRgb Transformation::getPixelRepeat(int x, int y)
|
QRgb Transformation::getPixelRepeat(int x, int y)
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int width = image->size().width();
|
||||||
|
int height = image->size().height();
|
||||||
|
|
||||||
|
if (x >= width) x = width - 1;
|
||||||
|
if (x < 0) x = 0;
|
||||||
|
|
||||||
|
if (y >= height) y = height - 1;
|
||||||
|
if (y < 0) y = 0;
|
||||||
return image->pixel(x,y);
|
return image->pixel(x,y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +149,20 @@ math::matrix<float> Transformation::getWindow(int x, int y, int size,
|
|||||||
{
|
{
|
||||||
math::matrix<float> window(size,size);
|
math::matrix<float> window(size,size);
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
int half = size/2;
|
||||||
|
for (int i=0; i<size; ++i) {
|
||||||
|
for (int j=0; j<size; ++j) {
|
||||||
|
QRgb pixel = getPixel(x + (i - half),y + (j - half), mode);
|
||||||
|
int pixelVal;
|
||||||
|
switch (channel) {
|
||||||
|
case RChannel: pixelVal = qRed(pixel); break;
|
||||||
|
case GChannel: pixelVal = qGreen(pixel); break;
|
||||||
|
case BChannel: pixelVal = qBlue(pixel); break;
|
||||||
|
case LChannel: pixelVal = qGray(pixel); break;
|
||||||
|
}
|
||||||
|
window[i][j] = pixelVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user