zadanie_10
This commit is contained in:
parent
c61aff0e9a
commit
1028f64ba4
@ -19,30 +19,58 @@ PNM* NoiseBilateral::transform()
|
||||
|
||||
sigma_d = getParameter("sigma_d").toInt();
|
||||
sigma_r = getParameter("sigma_r").toInt();
|
||||
radius = sigma_d;
|
||||
radius = sigma_d * 2;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int x=0;x<width;++x) {
|
||||
for (int y=0;y<height;++y) {
|
||||
int r = calcVal(x,y, RChannel);
|
||||
int g = calcVal(x,y, GChannel);
|
||||
int b = calcVal(x,y, BChannel);
|
||||
newImage->setPixel(x, y, QColor(r,g,b).rgb());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
int NoiseBilateral::calcVal(int x, int y, Channel channel)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
math::matrix<float> window = getWindow(x, y, radius, channel, RepeatEdge);
|
||||
|
||||
return 0;
|
||||
int pixel = image->pixel(x,y);
|
||||
|
||||
switch (channel) {
|
||||
case RChannel: pixel = qRed(pixel);
|
||||
case GChannel: pixel = qGreen(pixel);
|
||||
case BChannel: pixel = qBlue(pixel);
|
||||
}
|
||||
|
||||
float sum1 = 0;
|
||||
float sum2 = 0;
|
||||
|
||||
for (int i=0;i<radius;++i) {
|
||||
for (int j=0;j<radius;++j) {
|
||||
int pixelVal = window[i][j];
|
||||
QPoint point1((i - radius/2) + x, (j - radius/2) + y);
|
||||
QPoint point2(x,y);
|
||||
sum1 += pixelVal * colorCloseness(pixelVal, pixel) * spatialCloseness(point1, point2);
|
||||
sum2 += colorCloseness(pixelVal, pixel) * spatialCloseness(point1, point2);
|
||||
}
|
||||
}
|
||||
|
||||
return sum2 != 0 ? sum1 / sum2 : 0;
|
||||
}
|
||||
|
||||
float NoiseBilateral::colorCloseness(int val1, int val2)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
return exp( -(pow(val1 - val2, 2) / (2 * pow(sigma_r, 2))));
|
||||
}
|
||||
|
||||
float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
return exp(
|
||||
-(pow(point1.x() - point2.x(), 2) + pow(point1.y() - point2.y(), 2))
|
||||
/
|
||||
(2 * pow(sigma_d * 2, 2))
|
||||
);
|
||||
}
|
||||
|
@ -17,7 +17,14 @@ PNM* NoiseMedian::transform()
|
||||
|
||||
PNM* newImage = new PNM(width, height, image->format());
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for (int x=0;x<width;++x) {
|
||||
for (int y=0;y<height;++y) {
|
||||
int r = getMedian(x,y, RChannel);
|
||||
int g = getMedian(x,y, GChannel);
|
||||
int b = getMedian(x,y, BChannel);
|
||||
newImage->setPixel(x, y, QColor(r,g,b).rgb());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
@ -25,8 +32,29 @@ PNM* NoiseMedian::transform()
|
||||
int NoiseMedian::getMedian(int x, int y, Channel channel)
|
||||
{
|
||||
int radius = getParameter("radius").toInt();
|
||||
radius = radius * 2 + 1;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
math::matrix<float> window = getWindow(x, y, radius, channel, RepeatEdge);
|
||||
int table_size = radius * radius;
|
||||
int table[table_size];
|
||||
|
||||
return 0;
|
||||
int table_index = 0;
|
||||
|
||||
for (int x=0;x<radius;++x) {
|
||||
for (int y=0;y<radius;++y) {
|
||||
table[table_index] = window[x][y];
|
||||
table_index++;
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(table, table + (table_size - 1));
|
||||
|
||||
int median;
|
||||
|
||||
if (table_size % 2 != 0)
|
||||
median = table[ table_size / 2 ];
|
||||
else
|
||||
median = (table[ (table_size - 1) / 2 ] + table[ table_size / 2 ]) / 2.0;
|
||||
|
||||
return median;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user