1
0

Zadanie4-fixes.

This commit is contained in:
Jarosław Wieczorek 2021-04-10 13:21:24 +02:00
parent d35a7488cf
commit 0df9ade576
4 changed files with 54 additions and 26 deletions

View File

@ -1,4 +1,5 @@
#include "blur_linear.h" #include "blur_linear.h"
#include <iostream>
BlurLinear::BlurLinear(PNM* img) : BlurLinear::BlurLinear(PNM* img) :
Convolution(img) Convolution(img)
@ -18,21 +19,30 @@ PNM* BlurLinear::transform()
math::matrix<float> mask(maskSize, maskSize); math::matrix<float> mask(maskSize, maskSize);
int maskValCount = 0; int temp = 0;
for (int i=0; i < maskSize; i++) for (int x = 0; x < maskSize; x++)
{ {
for (int j=0; j < maskSize; j++) for (int y = 0; y < maskSize; y++)
{ {
std::cout << "value " << tmpMask.at(temp).toDouble() << std::endl;
mask(x, y) = tmpMask.at(temp).toDouble();
temp++;
}
}
float sum_mask = sum(mask);
if (normalize) if (normalize)
{ {
mask[i][j] = tmpMask.at(maskValCount).toDouble() / Convolution::sum(mask); if (sum_mask == 0){
maskValCount++; sum_mask = 1.0;
} }
else for (int x = 0; x < maskSize; x++)
{ {
mask[i][j] = tmpMask.at(maskValCount).toDouble(); for (int y = 0; y < maskSize; y++)
maskValCount++; {
mask(x, y) = mask(x, y) / sum_mask;
} }
} }
} }

View File

@ -52,6 +52,10 @@ 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());
float weight = Convolution::sum(mask); float weight = Convolution::sum(mask);
if (weight == 0)
{
weight = 1.0;
}
math::matrix<float> reflection = Convolution::reflection(mask); math::matrix<float> reflection = Convolution::reflection(mask);
for (int x=0; x < width ; x++) for (int x=0; x < width ; x++)

View File

@ -1,4 +1,5 @@
#include "blur_linear.h" #include "blur_linear.h"
#include <iostream>
BlurLinear::BlurLinear(PNM* img) : BlurLinear::BlurLinear(PNM* img) :
Convolution(img) Convolution(img)
@ -18,21 +19,30 @@ PNM* BlurLinear::transform()
math::matrix<float> mask(maskSize, maskSize); math::matrix<float> mask(maskSize, maskSize);
int maskValCount = 0; int temp = 0;
for (int i=0; i < maskSize; i++) for (int x = 0; x < maskSize; x++)
{ {
for (int j=0; j < maskSize; j++) for (int y = 0; y < maskSize; y++)
{ {
std::cout << "value " << tmpMask.at(temp).toDouble() << std::endl;
mask(x, y) = tmpMask.at(temp).toDouble();
temp++;
}
}
float sum_mask = sum(mask);
if (normalize) if (normalize)
{ {
mask[i][j] = tmpMask.at(maskValCount).toDouble() / Convolution::sum(mask); if (sum_mask == 0){
maskValCount++; sum_mask = 1.0;
} }
else for (int x = 0; x < maskSize; x++)
{ {
mask[i][j] = tmpMask.at(maskValCount).toDouble(); for (int y = 0; y < maskSize; y++)
maskValCount++; {
mask(x, y) = mask(x, y) / sum_mask;
} }
} }
} }

View File

@ -52,6 +52,10 @@ 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());
float weight = Convolution::sum(mask); float weight = Convolution::sum(mask);
if (weight == 0)
{
weight = 1.0;
}
math::matrix<float> reflection = Convolution::reflection(mask); math::matrix<float> reflection = Convolution::reflection(mask);
for (int x=0; x < width ; x++) for (int x=0; x < width ; x++)