1
0
lpo-image-processing/04/do_sprawdzenia/cpp/blur_linear.cpp

51 lines
1.1 KiB
C++
Raw Normal View History

2021-03-20 17:56:06 +01:00
#include "blur_linear.h"
2021-04-10 13:21:24 +02:00
#include <iostream>
2021-03-20 17:56:06 +01:00
BlurLinear::BlurLinear(PNM* img) :
Convolution(img)
{
}
BlurLinear::BlurLinear(PNM* img, ImageViewer* iv) :
Convolution(img, iv)
{
}
PNM* BlurLinear::transform()
{
int maskSize = getParameter("size").toInt();
QList<QVariant> tmpMask = getParameter("mask").toList();
bool normalize = getParameter("normalize").toBool();
math::matrix<float> mask(maskSize, maskSize);
2021-04-10 13:21:24 +02:00
int temp = 0;
2021-03-20 17:56:06 +01:00
2021-04-10 13:21:24 +02:00
for (int x = 0; x < maskSize; x++)
2021-03-20 17:56:06 +01:00
{
2021-04-10 13:21:24 +02:00
for (int y = 0; y < maskSize; y++)
2021-03-20 17:56:06 +01:00
{
2021-04-10 13:21:24 +02:00
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;
2021-03-20 17:56:06 +01:00
}
2021-04-10 13:21:24 +02:00
for (int x = 0; x < maskSize; x++)
2021-03-20 17:56:06 +01:00
{
2021-04-10 13:21:24 +02:00
for (int y = 0; y < maskSize; y++)
{
mask(x, y) = mask(x, y) / sum_mask;
}
2021-03-20 17:56:06 +01:00
}
}
return convolute(mask, RepeatEdge);
}