我正在尝试实现floyd算法,但似乎它不起作用。
我使用了维基百科的伪代码算法 没有弗洛伊德http://img15.hostingpics.net/pics/298623Capturedcran20140226165024.png
with floyd http://img15.hostingpics.net/pics/968250Capturedcran20140226165035.png
这是我的代码:
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;
}
答案 0 :(得分:3)
ubyte newpixel = (oldpixel > 128) ? 0 : 255;
必须是
ubyte newpixel = (oldpixel > 128) ? 255 : 0;
另一个可能的问题:我建议传播Erreur应该是签名类型