uv mapping works bad on low resolution (warning: lot of images)

旧城冷巷雨未停 提交于 2019-12-22 12:55:02

问题


TL;DR: is there a way to scale down both UV map and texture without losing the quality of the produced result?

Full story:

I'm trying to develop a simple rendering engine which would take UV map from .EXR file, put a texture on it and serve to the client. Whole process looks like this:

from PIL import Image
import numpy as np

texture = Image.open("texture.png")
texture_array = np.asarray(txt).transpose(1, 0, 2) 

# assume reading EXR file and grabbing only R and G channels from it
uv = read_exr()
# scale indexes to texture size
uv[..., 0] *= texture.size[0]
uv[..., 1] *= texture.size[1]
map = uv.astype('uint16')
# use numpy indexing to produce the result
result = texture_array[map[..., 0], map[..., 1]]

# downsample for smoother image
image = Image.fromarray(result, "RGB").resize((2048, 2048), Image.LANCZOS)

Produced image is a shirt and texture is in fact a fabric scan. The UV is actually composed from several files since each part of the shirt may have different options.

Everything works fine on high resolution but I thought of making a "preview" version to show on the webpage. Now the problem is when I try to scale the UV and texture down the result only looks decent for fabric with big patterns. E.g. fabric with a lot of thin lines produces moire-like effects. Below are examples of high resolution result scaled down by browser (this is acceptable):

and result composed of UV and texture which were scaled down programmatically (this is no way):

Here's how I scale both texture and UV:

from scipy.ndimage.interpolation import zoom

uv = zoom(uv, [0.25, 0.25, 1], order=1) # higher order produces negative values
texture = texture.resize((1024, 1024), Image.LANCZOS)

I also tried using cv2 for UV scaling but it gives the same result.

It's critical to be able to build this thumbnail version, since compose of high resolution version takes few seconds and thumbnail builds in a split second. Unfortunately I can't prerender all the possible combinations due to high amount of different options.

I wonder if there're some tricks to make the low resolution result look better, ideally to look the same as the downsampled "original" image. I would really appreciate any ideas, since I don't know much about image processing and couldn't find any decent solution so far.

Here's what I tried with no luck already:

  1. Blur the texture a little bit of gaussian blur + UnsharpMask. Helps with moire, but kills the tone of fabric:

  1. Use original-sized texture (no downsample): result looks too sharp and also has moire-like effect; looks awful for lot of other fabrics

来源:https://stackoverflow.com/questions/39153484/uv-mapping-works-bad-on-low-resolution-warning-lot-of-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!