Zadanie4-fixes.
This commit is contained in:
parent
d35a7488cf
commit
0df9ade576
@ -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);
|
||||
}
|
||||
|
@ -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++)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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++)
|
||||
|
Loading…
Reference in New Issue
Block a user