我在 pgm 中有图像
使用此功能后:
void convertWithDithering(array_type& pixelgray)
{
int oldpixel;
int newpixel;
int quant_error;
for (int y = 0; y< HEIGHT-1; y++){
for (int x = 1; x<WIDTH-1; x++){
oldpixel = pixelgray[x][y];
newpixel = (oldpixel > 128) ? 0 : 1;
pixelgray[x][y] = newpixel;
quant_error = oldpixel - newpixel;
pixelgray[x+1][y] = pixelgray[x+1][y] + 7/16 * quant_error;
pixelgray[x-1][y+1] = pixelgray[x-1][y+1] + 3/16 * quant_error;
pixelgray[x ][y+1]=pixelgray[x ][y+1]+ 5/16 * quant_error;
pixelgray[x+1][y+1] = pixelgray[x+1][y+1]+ 1/16 * quant_error;
}
}
}
我有这个
我想只用黑白颜色获得相同的图像