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 <iostream>
BlurLinear::BlurLinear(PNM* img) :
Convolution(img)
@ -18,23 +19,32 @@ PNM* BlurLinear::transform()
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++)
{
if (normalize)
{
mask[i][j] = tmpMask.at(maskValCount).toDouble() / Convolution::sum(mask);
maskValCount++;
}
else
{
mask[i][j] = tmpMask.at(maskValCount).toDouble();
maskValCount++;
}
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 (sum_mask == 0){
sum_mask = 1.0;
}
for (int x = 0; x < maskSize; x++)
{
for (int y = 0; y < maskSize; y++)
{
mask(x, y) = mask(x, y) / sum_mask;
}
}
}
return convolute(mask, RepeatEdge);
}

View File

@ -52,6 +52,10 @@ PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
PNM* newImage = new PNM(width, height, image->format());
float weight = Convolution::sum(mask);
if (weight == 0)
{
weight = 1.0;
}
math::matrix<float> reflection = Convolution::reflection(mask);
for (int x=0; x < width ; x++)

View File

@ -1,4 +1,5 @@
#include "blur_linear.h"
#include <iostream>
BlurLinear::BlurLinear(PNM* img) :
Convolution(img)
@ -18,23 +19,32 @@ PNM* BlurLinear::transform()
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++)
{
if (normalize)
{
mask[i][j] = tmpMask.at(maskValCount).toDouble() / Convolution::sum(mask);
maskValCount++;
}
else
{
mask[i][j] = tmpMask.at(maskValCount).toDouble();
maskValCount++;
}
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 (sum_mask == 0){
sum_mask = 1.0;
}
for (int x = 0; x < maskSize; x++)
{
for (int y = 0; y < maskSize; y++)
{
mask(x, y) = mask(x, y) / sum_mask;
}
}
}
return convolute(mask, RepeatEdge);
}

View File

@ -52,6 +52,10 @@ PNM* Convolution::convolute(math::matrix<float> mask, Mode mode = RepeatEdge)
PNM* newImage = new PNM(width, height, image->format());
float weight = Convolution::sum(mask);
if (weight == 0)
{
weight = 1.0;
}
math::matrix<float> reflection = Convolution::reflection(mask);
for (int x=0; x < width ; x++)