如何填充 Image 中的像素间隙

时间:2021-06-23 10:04:36

标签: image opencv python-imaging-library image-resizing

我正在为汽车生成阴影,但由于 CNN 提供固定大小的输出,并且它还返回像素化输出,因为我将其调整为较小的大小。因此,我试图通过从调整大小的图像中应用阴影并将其应用于原始图像来将图像恢复到原始大小。

算法;

  1. 原始图像大小(1024、768、4)[无阴影]。
  2. 将原始图像 [无阴影] 调整为 (768, 512, 4) 并使用 GAN 模型生成阴影,该模型将返回大小为 (768, 512, 4) 的图像 [有阴影]。
  3. 现在因为 about 图像是像素化的(因为调整了大小)。我正在尝试移除 (768, 512, 4) 大小图像的阴影并将其应用于大小 (1024, 768, 4) 的原始图像。
  4. 但是,当我调整阴影大小然后将其应用于原始图像时,它输出的结果如下所示。

基本上,我试图去除汽车和阴影之间的阴影边界。

enter image description here

Original Input image (1024, 768, 4)

Resized Input image (768, 512, 4)

Resized Output image (768, 512, 4)

1 个答案:

答案 0 :(得分:0)

@Vishal T,如果使用 RGBA 图像尝试合并

alphaComposited = Image.alpha_composite(car, shadow)

https://pythontic.com/image-processing/pillow/alpha-composite

如果是 RGB 图像,请尝试

Image.composite

https://www.geeksforgeeks.org/python-pil-composite-method/

让我知道它是如何为您服务的。我在类似的工作中遇到了类似的问题。祝你好运:)

相关问题