Merge branch 'Zadanie_06_Dawid' of s452126/lpo-projekt2020 into master
This commit is contained in:
commit
17f063074c
@ -21,28 +21,73 @@ PNM* NoiseBilateral::transform()
|
||||
sigma_r = getParameter("sigma_r").toInt();
|
||||
radius = sigma_d;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
for(int x = 0 ; x < width; x++){
|
||||
for (int y = 0 ; y < height; y++) {
|
||||
|
||||
int g = calcVal(x,y, GChannel);
|
||||
int r = calcVal(x,y, RChannel);
|
||||
int b = calcVal(x,y, BChannel);
|
||||
newImage->setPixel(x,y,QColor(r,g,b).rgba());
|
||||
}
|
||||
}
|
||||
|
||||
return newImage;
|
||||
}
|
||||
|
||||
int NoiseBilateral::calcVal(int x, int y, Channel channel)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
double sumNumerator = 0;
|
||||
double sumDenominator = 0;
|
||||
|
||||
return 0;
|
||||
double colorClosenes = 0;
|
||||
double spatialClosennes = 0;
|
||||
int colorValue;
|
||||
int colorValueRef;
|
||||
|
||||
for ( int i = x- radius ; i <= x+radius ; i++) {
|
||||
for ( int j = y- radius ; j <= y+radius ; j++) {
|
||||
|
||||
if ( i+radius >= image->width() ||
|
||||
i-radius < 0 ||
|
||||
j+radius >= image->height() ||
|
||||
j-radius < 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channel==LChannel){
|
||||
colorValue = qAlpha(image->pixel(i,j));
|
||||
colorValueRef = qAlpha(image->pixel(x,y));
|
||||
}
|
||||
if (channel==RChannel){
|
||||
colorValue = (qRed(image->pixel(i,j)));
|
||||
colorValueRef = qRed(image->pixel(x,y));
|
||||
}
|
||||
if (channel==GChannel){
|
||||
colorValueRef = qGreen(image->pixel(x,y));
|
||||
colorValue = (qGreen(image->pixel(i,j)));
|
||||
}
|
||||
if (channel==BChannel){
|
||||
colorValueRef = qBlue(image->pixel(x,y));
|
||||
colorValue = ( qBlue(image->pixel(i,j)));
|
||||
}
|
||||
|
||||
colorClosenes = colorCloseness(colorValue,colorValueRef);
|
||||
spatialClosennes = spatialCloseness( QPoint(i,j),QPoint(x,y));
|
||||
|
||||
sumNumerator = sumNumerator +( colorValue* colorClosenes * spatialClosennes);
|
||||
sumDenominator =sumDenominator + ( colorClosenes * spatialClosennes);
|
||||
|
||||
}
|
||||
}
|
||||
return sumNumerator/sumDenominator;
|
||||
}
|
||||
|
||||
float NoiseBilateral::colorCloseness(int val1, int val2)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
return exp(-(((val1-val2)^2)/(2*sigma_r^2)));
|
||||
}
|
||||
|
||||
float NoiseBilateral::spatialCloseness(QPoint point1, QPoint point2)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
|
||||
return 0;
|
||||
return exp(-((point1.x() - point2.x())^2 + ( point1.y() - point2.y())^2)/(2*sigma_d^2));
|
||||
}
|
||||
|
@ -17,16 +17,57 @@ 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 g = getMedian(x,y, GChannel);
|
||||
int r = getMedian(x,y, RChannel);
|
||||
int b = getMedian(x,y, BChannel);
|
||||
newImage->setPixel(x,y,QColor(r,g,b).rgba());
|
||||
}
|
||||
}
|
||||
return newImage;
|
||||
}
|
||||
|
||||
int NoiseMedian::getMedian(int x, int y, Channel channel)
|
||||
{
|
||||
int radius = getParameter("radius").toInt();
|
||||
QSet<int> set;
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Not implemented yet!";
|
||||
QList<int> list = QList<int>::fromSet(set);
|
||||
std::sort(list.begin(), list.end());
|
||||
|
||||
return 0;
|
||||
|
||||
for ( int i = x- radius ; i <= x+radius ; i++) {
|
||||
for ( int j = y- radius ; j <= y+radius ; j++) {
|
||||
|
||||
if ( i+radius >= image->width() ||
|
||||
i-radius < 0 ||
|
||||
j+radius >= image->height() ||
|
||||
j-radius < 0 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (channel==LChannel) set.insert(qAlpha(image->pixel(i,j)));
|
||||
if (channel==RChannel) set.insert(qRed(image->pixel(i,j)));
|
||||
if (channel==GChannel) set.insert(qGreen(image->pixel(i,j)));
|
||||
if (channel==BChannel) set.insert( qBlue(image->pixel(i,j)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
QList<int> data = QList<int>::fromSet(set);
|
||||
std::sort(data.begin(), data.end());
|
||||
int result =0 ;
|
||||
|
||||
if( data.size() %2 == 1){
|
||||
result = data.at(data.size()/2);
|
||||
}else if(data.size()>3){
|
||||
int first_med = data.at((data.size()/2 )-1);
|
||||
int sec_dem = data.at((data.size()/2 ));
|
||||
result = (first_med+sec_dem)/2;
|
||||
}
|
||||
data.clear();
|
||||
set.clear();
|
||||
return result;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user