Exemplo n.º 1
0
int NoiseBilateral::calcVal(int x, int y, Channel channel)
{
    math::matrix<float> window = getWindow(x, y, (radius*2)+1, channel, RepeatEdge);

    int size = window.rowno();
    float numeratorSum = 0, denominatorSum = 0;
    int v;
    int pixel = image->pixel(x, y);

    if (channel == RChannel) v = qRed(pixel);
    if (channel == GChannel) v = qGreen(pixel);
    if (channel == BChannel) v = qBlue(pixel);
    if (channel == LChannel) v = qGray(pixel);

    for (int x=0; x<size; x++)
         for (int y=0; y<size; y++)
         {
             float numerator = window(x, y) * colorCloseness(window(x, y), v) * spatialCloseness(QPoint(x - radius, y - radius), QPoint(x, y));
             float denominator = colorCloseness(window(x, y), v) * spatialCloseness(QPoint(x - radius, y - radius), QPoint(x, y));
             numeratorSum = numeratorSum + numerator;
             denominatorSum = denominatorSum + denominator;
         }

    return numeratorSum / denominatorSum;
}
int NoiseBilateral::calcVal(int x, int y, Channel channel)
{
    Mode mode = RepeatEdge;
    math::matrix<float> win = getWindow(x,y,radius*2+1,channel,mode);
    int tempx,tempy,temp;

    float licz, mian, temp1, temp2;
    licz=mian=0;
    tempx = win.rowno();
    tempy = win.colno();
    for(int i=0;i<tempx;i++){
        for(int j=0;j<tempy;j++){

            if(channel == RChannel){
                temp = qRed(image->pixel(x, y));
            }else if(channel == GChannel){
                temp = qGreen(image->pixel(x, y));
            }else if(channel == BChannel){
                temp = qBlue(image->pixel(x, y));
            }else{
                temp = qGray(image->pixel(x, y));
            }

            int px = x + (i - (int)((radius * 2 + 1) / 2));
            if (px <= 0) px = 0;
            if (px >= image->width()) px = image->width();
            int py = y + (j - (int)((radius * 2 + 1) / 2));
            if (py <= 0) py = 0;
            if (py >= image->height()) py = image->height();

            temp1 = win(i,j)*colorCloseness(win(i,j),temp)*spatialCloseness(QPoint(px, py), QPoint(x, y));
            temp2 = colorCloseness(win(i,j),temp)*spatialCloseness(QPoint(px, py), QPoint(x, y));
            licz+=temp1;
            mian+=temp2;
        }
    }
    return (int) licz/mian;
}