小编Qua*_*ndo的帖子

如何用图像的中值有效地填充RGB numpy数组?

我有RGB图像已经重新调整,以便较长的边缘变为256像素,现在我想用该图像的中间RGB值填充边框,因此生成的图像总是256x256像素.

这段代码已经可以使用,但我相信可以有一种更简单,更优雅的方法:

img = loadAndFitImage(filePath, maxSideLength=256, upscale=True)
shp = img.shape
#the shp in this case is typically (256,123,3) or (99,256,3)

leftPad = (256 - shp[0]) / 2
rightPad = 256 - shp[0] - leftPad
topPad = (256 - shp[1]) / 2
bottomPad = 256 - shp[1] - topPad

# this part looks like there might be a way to do it with one median call instead of 3:
median = (np.median(img[:, :, 0]),np.median(img[:, :, 1]),np.median(img[:, :, 2]))

img = np.lib.pad(img, …
Run Code Online (Sandbox Code Playgroud)

python numpy image-processing

5
推荐指数
2
解决办法
6390
查看次数

使用三次贝塞尔曲线作为直线:控制点必须位于何处才能获得 t 的等距间距

当三次贝塞尔曲线的两个控制点都位于曲线两个端点之间的线上时,生成的曲线将是直线。在我的情况下,问题是我得到的不同 t 曲线上点的实际间距根据控制点在该线上的位置而有所不同。

如果我使用 p1 和 p2 之间的 lerp 计算两个控制点的位置,如下所示:

controlPoint1 = endPoint1.lerp(endPoint2,a);
controlPoint2 = endPoint1.lerp(endPoint2,b);
Run Code Online (Sandbox Code Playgroud)

必须有 a,b 的一种配置,其中间距实际上是等距的。我尝试了 0.25/0.75、0.3333/0.6666、0.5/0.5,但这些似乎都没有削减它。

math geometry bezier

4
推荐指数
1
解决办法
2669
查看次数

标签 统计

bezier ×1

geometry ×1

image-processing ×1

math ×1

numpy ×1

python ×1