使用弗洛伊德-斯坦伯格抖动不起作用
Using Floyd–Steinberg dithering not working
我正在尝试实现弗洛伊德算法,但似乎不起作用。
我使用了维基百科中的伪代码算法没有弗洛伊德 http://img15.hostingpics.net/pics/298623Capturedcran20140226165024.png
与弗洛伊德·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;
}
ubyte newpixel = (oldpixel > 128) ? 0 : 255;
必须是
ubyte newpixel = (oldpixel > 128) ? 255 : 0;
另一个可能的问题:我建议传播Erreur应该是有符号的类型
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- 将QIcon添加到QTableView单元格
- 当用户在qtablewidget中输入单元格时,如何获得信号?C++
- 为什么瓦尔格林德在不释放恶意内存后没有报告任何问题?
- 带有框架的 QGraphicsTextItem 的 QPropertyAnimation 会使文本抖动
- 在C++中去抖动
- 创建一个棋盘格或"Interweave"两个链接列表。IE 更改两个链表的指针
- 查找矩阵中单元格的相邻元素
- 瓦尔格林德的内存泄漏使用新的
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- C++:在多个线程中访问同一数组/向量的不同单元格是否会产生数据竞赛?
- C++程序什么都不做,但瓦尔格林德显示内存分配
- 赫尔格林德和atomic_flag
- Q维德格特关闭事件(..)未使用 QProcess::terminate() 调用
- 删除堆后对瓦尔格林德错误感到困惑
- 终端如何在 shell 提示符下以编程方式阻止退格,以便您无法在其上退格,例如 $ 表示 bash 或 C:\blah\>
- 当我使用需要计算数组单元格地址的模板时,奇怪的C++行为
- 我可以将艾根·莱文伯格·马夸特与线性方程和常数雅可比矩阵一起使用吗?
- 使用弗洛伊德-斯坦伯格抖动不起作用
- 艾森伯格-麦奎尔算法分割错误的实现:C中的11