用弗洛伊德 - 斯坦伯格抖动不工作 [英] Using Floyd–Steinberg dithering not working

查看:205
本文介绍了用弗洛伊德 - 斯坦伯格抖动不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现Floyd算法,但似乎它不工作。

我用的是伪code从维基百科的算法 没有弗洛伊德 http://img15.hostingpics.net/pics/298623Capturedcran20140226165024.png

与弗洛伊德 http://img15.hostingpics.net/pics/968250Capturedcran20140226165035.png

这是我的code:

 模板<>
图片< UBYTE> *图片< UBYTE> :: floydSteinberg()const的
{
    图片< UBYTE> * TMP =新图片< UBYTE>(这 - >宽度,这 - >高度);

    的for(int i = 0; I<宽*高;我++)
            tmp->数组[我] =这 - >数组[我]


    对于(INT Y = 0; Y<这 - >高度; Y ++){

        对于(INT X = 1; X<这 - >宽度; X ++){

            UBYTE oldpixel = tmp->像素(x,y)基
            UBYTE newpixel =(oldpixel> 128)? 255:0;
            tmp->像素(x,y)的= newpixel;
            UBYTE propagationErreur = oldpixel  -  newpixel;

            tmp->像素(x + 1,y)的= tmp->像素(x + 1,y)的+ 7.0 / 16 * propagationErreur;
            tmp->像素(x-1,Y + 1)= tmp->像素(x-1,Y + 1)+ 3.0 / 16 * propagationErreur;
            tmp->像素(X,Y + 1)= tmp->像素(X,Y + 1)+ 5.0 / 16 * propagationErreur;
            tmp->像素(x + 1,Y + 1)= tmp->像素(x + 1,Y + 1)+ 1.0 / 16 * propagationErreur;

        }
    }


    返回TMP;
}
 

解决方案

  UBYTE newpixel =(oldpixel> 128)? 0:255;
 

必须

  UBYTE newpixel =(oldpixel> 128)? 255:0;
 

另一个可能的问题:我建议propagationErreur应签署类型

I'm trying to implement the floyd algorithm but it seems it doesn't works.

I used the pseudocode algorithm from wikipedia without floyd http://img15.hostingpics.net/pics/298623Capturedcran20140226165024.png

with floyd http://img15.hostingpics.net/pics/968250Capturedcran20140226165035.png

This is my code :

template<>
Image<ubyte>* Image<ubyte>::floydSteinberg() const
{
    Image<ubyte>* tmp = new Image<ubyte>(this->width, this->height);

    for (int i=0; i < width*height; i++)
            tmp->array[i]= this->array[i];


    for (int y = 0; y< this->height; y++){

        for (int x = 1; x<this->width; x++){

            ubyte oldpixel = tmp->pixel(x, y);
            ubyte newpixel  = (oldpixel > 128) ? 255 : 0;
            tmp->pixel(x,y) = newpixel;
            ubyte propagationErreur  = oldpixel - newpixel;

            tmp->pixel(x+1,y) =tmp->pixel(x+1,y) + 7.0/16 * propagationErreur;
            tmp->pixel(x-1,y+1) = tmp->pixel(x-1,y+1)  + 3.0/16 * propagationErreur ;
            tmp->pixel(x,y+1) = tmp->pixel(x,y+1)  + 5.0/16 * propagationErreur ;
            tmp->pixel(x+1,y+1) = tmp->pixel(x+1,y+1)  + 1.0/16 * propagationErreur ;

        }
    }


    return tmp;
}

解决方案

ubyte newpixel  = (oldpixel > 128) ? 0 : 255;

must be

ubyte newpixel  = (oldpixel > 128) ? 255 : 0;

Another possible issue: I suggest that propagationErreur should be signed type

这篇关于用弗洛伊德 - 斯坦伯格抖动不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆