如何在图像之间执行线性插值

发布于 2024-09-14 10:01:12 字数 310 浏览 13 评论 0原文

我正在阅读 论文,讨论在图像合成中使用 lerp 函数。 lerp 到底是什么?如果给你两张图像作为输入,你将如何使用一张图像来合成图像?

I'm reading a paper that talks about using a lerp function in image synthesis. What exactly is a lerp and how would you synthesize an image using one if you are given two images as inputs?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隔纱相望 2024-09-21 10:01:12

“lerp”只是一种估计中间值的方法。例如,如果一个值为 10,下一个值为 8,则“lerp”函数可能返回 9。有多种方法可以进行估计 - 线性、三角等。最简单的线性方式,您只需采用 < code>(距值 1 的距离 * 值 1) + (距值 2 的距离 * 值 2) 其中距离范围从 0 到 1。

在图像处理中,这是通过像素之间的颜色值来完成的。例如,如果您放大到超过 100%,您将使用 lerp 函数来确定在代表部分像素的区域中绘制什么。

我应该补充一点,我看过那篇文章,它引用了柏林噪音。在这种类型的算法中,lerp'ing 函数被广泛用于计算存在数据的点之间的值,这些数据可以传递到柏林或分形算法中以生成该中间点的值。

'lerp'ing is just a way to guestimate an intermediary value. For example, if one value was 10, and the next was 8, a 'lerp' function might return 9. There's several ways to make the estimation - linear, trigonomic, etc. At its simplest, linear, you're just taking (distance from value 1 * value 1) + (distance from value 2 * value 2) where distance ranges from 0 to 1.

In image processing, this is done with the color values between pixels. If you are zooming in past 100%, for example, you'd use a lerp function to determine what to draw in the areas that represent partial pixels.

I should add, I looked at that article, and it references Perlin noise. In that type of algorithm, lerp'ing functions are used quite extensively to calculate values in between points where data exists that can be passed into the perlin or fractal algoritm to generate a value for that intermediary point.

假装爱人 2024-09-21 10:01:12

到底什么是 lerp 以及

lerp(factor, a, b) = Factor*a + (1.0 - Factor)*b

,其中 Factor 在 [0, 1.0] 范围内,

请参阅 维基百科

如果给你两张图像作为输入,你会如何使用一张图像合成一张图像?

您需要两个大小相等的源图像(src1、src2)和目标图像(dst)。加上插值因子。

然后对于每个像素(RGB 颜色):

dst[x][y].r = lerp(factor, src1[x][y].r, src2[x][y].r)
dst[x][y].g = lerp(factor, src1[x][y].g, src2[x][y].g)
dst[x][y].b = lerp(factor, src1[x][y].b, src2[x][y].b)

What exactly is a lerp and

lerp(factor, a, b) = factor*a + (1.0 - factor)*b

where factor is in range [0, 1.0]

See wikipedia

how would you synthesize an image using one if you are given two images as inputs?

You need two source images (src1, src2) and destination image (dst) of equal size. Plus interpolation factor.

Then for every pixel do (RGB color):

dst[x][y].r = lerp(factor, src1[x][y].r, src2[x][y].r)
dst[x][y].g = lerp(factor, src1[x][y].g, src2[x][y].g)
dst[x][y].b = lerp(factor, src1[x][y].b, src2[x][y].b)
独闯女儿国 2024-09-21 10:01:12

你会如何合成它?通过使用该功能。该函数将为您提供任意像素处给定输入的输出。不过,对两个图像进行插值没有任何意义,您可能对使用插值来调整大小感兴趣。它还有一些有趣的特性。 sinc 插值器相当于使图像通过频率空间中的砖墙低通滤波器。

对于两个图像,您的函数将执行某种加法或求平均值,无论您感兴趣什么。如果您正在合成某些内容,插值相当于通过低通滤波器运行它。例如,如果两个图像以不同的速率采样,并且您希望将一个图像放在另一个图像之上,则您需要将较低的速率插值到较高速率的采样图像上。

How would you synthesize it? By using the function. The function would give you the output for given inputs at any pixel. Interpolating two images doesn't make any sense though, you're probably interested in using interpolation for resizing. It also has some interesting properties. A sinc interpolator is equivalent to running the image through a brick wall low-pass filter in Frequency space.

For two images, your function would perform some sort of addition or averaging, whatever you're interested in. If you're synthesizing something, interpolation is equivalent to running it through a low pass filter. For instance, if two images are sampled at different rates and you want to put one on top of the other, you'd want to interpolate the lower rate over the higher rate sampled image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文