网络上最小的3D照片效果

The 3D Photo effect - popularized by Facebook, is immensly satisfying to look at. It can make for pretty parallax-like background effects, and it can be partially replicated in 10 minutes with just a few easy steps!

3D照片效果--由Facebook推广,让人看了非常满意。它可以制作出漂亮的视差式背景效果,而且只需几个简单的步骤,就可以在10分钟内部分复制出来

Check out the final effect here:

在此查看最终效果。

Prepare a photo and a depth map

准备一张照片和一张深度图

To produce a 3D Photo effect, we first need a photo and a depth map. Here is an example:

要产生3D照片效果,我们首先需要一张照片和一张深度图。下面是一个例子。

Original photo Depth map
原始照片 深度图

| Original photo

|Original photo

Original photo

原始照片

|

|

Depth map

Depth map

深度图

|

|

Normally you can draw this depth map yourself - basically darker regions indicate greater depths, and whiter regions means closer to the camera. Some newer phones also have depth-sensing capability which can be used to quickly generate depth maps.

通常情况下,你可以自己画出这个深度图--基本上,较深的区域表示深度较大,较白的区域表示离相机较近。一些较新的手机也有深度感应功能,可以用来快速生成深度图。

For this post, however, I tried to find a depth estimation AI model - which led me to this UNet-based model and demo repository. The README provides excellent instructions on how to quickly setup and run the demo locally, taking a random photo of your choice and exporting to a depth map.

然而,在这篇文章中,我试图找到一个深度估计的人工智能模型--这让我找到了这个基于UNet的模型和演示库。README提供了很好的说明,说明如何快速设置并在本地运行该演示,随机拍摄一张你选择的照片并输出到深度图。

This code, however, generate inverted depth maps compared to our requirements. Therefore I made some modifications to demo.py to invert the colors and increase the color contrast so the depths are more pronounced.

然而,与我们的要求相比,这段代码产生了倒置的深度图。因此,我对demo.py 进行了一些修改,以反转颜色并增加颜色对比度,使深度更加明显。

 trans_totensor = transforms.Compose([ transforms.Resize( (256, 256), interpolation=PIL.Image.BILINEAR ), transforms.ToTensor()
]) from PIL import Image, ImageOps, ImageEnhance baseline_output = model(img_tensor).clamp(min=0, max=1)
res = trans_topil(baseline_output[0]) res = ImageOps.invert(res) enhancer = ImageEnhance.Contrast(res)
res = enhancer.enhance(5) res.save(args.output_path+'/'+output_file_name+'_'+args.task+'_'+type+'.png')

Side note: Give...

开通本站会员,查看完整译文。

Accueil - Wiki
Copyright © 2011-2024 iteam. Current version is 2.139.0. UTC+08:00, 2024-12-26 03:25
浙ICP备14020137号-1 $Carte des visiteurs$