简体   繁体   English

如何在netpbm图像中绘制平滑像素?

[英]How can I draw smooth pixels in a netpbm image?

I just wrote a small netpbm parser and I am having fun with it, drawing mostly parametric equations. 我只是写了一个小netpbm解析器,我很开心,主要绘制了参数方程式。 They look OK for a first time thing, but how can I expand upon this and have something that looks legit? 他们第一次看起来不错,但是我如何扩展它并拥有看起来合法的东西? This picture is how my method recreated the Arctic Monkeys logo which was just 这张照片是我的方法如何重新创建了北极猴子徽标

0.5[cos(19t) - cos(21t)] (I was trying to plot both cosines first before superpositioning them) 0.5[cos(19t) - cos(21t)] (我想先绘制两个余弦,然后再进行叠加) 在此处输入图片说明

It obviously looks very "crispy" and sharp. 它显然看起来非常“酥脆”且锋利。 I used as small of a step size as I could without it taking forever to finish. 我使用了尽可能小的步长,而无需花费很多时间来完成。 (0.0005, takes < 5 sec) (0.0005,耗时<5秒)

The only idea I had was that when drawing a white pixel, I should also draw its immediate neighbors with some slightly lighter gray. 我唯一的想法是,当绘制白色像素时,我还应使用稍微浅一些的灰色绘制其直接邻居。 And then draw the neighbors of THOSE pixels with even lighter gray. 然后用更浅的灰色绘制THOSE像素的邻居。 Almost like the white color is "dissolving" or "dissipating". 几乎像白色是“溶解”或“消散”。

I didn't try to implement this because it felt like a really bad way to do it and I am not even sure it'd produce anything near the desirable effect so I thought I'd ask first. 我没有尝试实现它,因为这样做确实感觉很糟糕,我什至不确定它会产生任何接近理想效果的东西,所以我想我先问一下。

EDIT: here's a sample code that draws just a small spiral 编辑:这是一个示例代码,仅绘制了一个小螺旋

the draw loop: 绘制循环:

for (int t = 0; t < 6 * M_PI; t += 0.0005)
    {
        double r = t;
        new_x = 10 * r * cosf(0.1 * M_PI * t);
        new_y = -10 * r * sinf(0.1 * M_PI * t);
        img.SetPixel(new_x + img.img_width / 2, new_y + img.img_height / 2, 255);
    }

//img is a PPM image with magic number P5 (binary grayscale)

SetPixel: SetPixel:

void PPMimage::SetPixel(const uint16_t x, const uint16_t y, const uint16_t pixelVal)
{
    assert(pixelVal >= 0 && pixelVal <= max_greys && "pixelVal larger than image's maximum max_grey\n%d");
    assert(x >= 0 && x < img_width && "X value larger than image width\n");
    assert(y >= 0 && y < img_height && "Y value larger than image height\n");


    img_raster[y * img_width + x] = pixelVal;
}

This is what this code produces 这就是这段代码产生的

在此处输入图片说明

A very basic form of antialiasing for a scatter plot (made of points rather than lines) can be achieved by applying something like stochastic rounding: consider the brush to be a pixel-sized square (but note the severe limitations of this model), centered at the non-integer coordinates of the plotted point, and compute its overlap with the four pixels that share the corner closest to that point. 散点图 (由点而不是线组成)的一种非常基本的抗锯齿形式可以通过应用随机舍入来实现:将画笔视为像素大小的正方形(但请注意此模型的严格限制 ),居中在绘制点的非整数坐标处,并计算其与共享最接近该点的角的四个像素的重叠度。 Treat that overlap fraction as a grayscale fraction and set each pixel to the largest value for a large number of points approximating a line, or do alpha blending for a small number of discrete points. 将重叠部分视为灰度部分,并将大量像素逼近一条线,将每个像素设置为最大值 ,或者对少量离散点进行alpha 混合

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM