|
|
Greeting,
continuing experiments with Python (which continues to piss me off), I
decided to write small program to convert image heightfields into
triangle meshes. My may intention was to improve quality for
heightfields having both small image size and low bit depth - I supposed
that converting them into meshes will make POVRay interpolate
nonexisting data, thus improving visual appearance.
Attached is my test image 1.test grey 001.png, used as a heightfield
(with "smooth" on) for rendering 2.heightfield.jpg. Since the source is
only 64 * 64 pixels, result looks... well, correspondingly.
Next, I created my converter (attached as img2mesh.01.004.py.bz2) and
used it to convert the same source into triangle mesh. Rendering result
is attached as 3.img2mesh.01.004.jpg and, as you can see, it's clearer
but full of holes. After that I finally took a look at POVRay docs, that
say that POVRay internally uses 4 pixels for 2 triangles, just like my
program (never read docs before doing something yourself - it's
discouraging!), except for I didn't do force connection of square
corners, that lead to a holes. Instead of fixing it (I find fixing
discouraging too), I simply invented different approach - using 4 pixels
for 4 triangles (don't tell me if this is described somewhere already),
that lead to a completely different program, attached as
img2mesh.02.001.py.bz2), which provides output like attached
4.img2mesh.02.001.jpg.
The latter looks to me significantly better than POVRay heightfield
rendering (not to mention my first attempt), although I plan some
additional explorations (artifacts on flat surfaces are still
unexplained, and I even start to suspect POVRay roundoff errors).
Meanwhile, I hope someone will find this tiny utility useful, and
probably even come with new ideas.
Prerequisites:
1) Python (I used 3.12 but previous versions of Python 3 are supposed to
be fine). Seem to be preinstalled on many computers nowadays (that's how
I got it, for example). My program is equipped with minimal GUI, using
tkinter, which seem to be redistributed with all standard Python
distributions, so doesn't require separate download.
2) Pillow for reading images. As a simple image reading library, pillow
is distributed everywhere; at worst, it takes few seconds to download
and no seconds to install and configure.
So, have a day.
Ilya
Post a reply to this message
Attachments:
Download '1.test grey 001.png' (2 KB)
Download '2.heightfield.jpg' (9 KB)
Download 'img2mesh.01.004.py.bz2.zip' (3 KB)
Download '3.img2mesh.01.004.jpg' (14 KB)
Download 'img2mesh.02.001.py.bz2.zip' (2 KB)
Download '4.img2mesh.02.001.jpg' (10 KB)
Preview of image '1.test grey 001.png'
Preview of image '2.heightfield.jpg'
Preview of image '3.img2mesh.01.004.jpg'
Preview of image '4.img2mesh.02.001.jpg'
|
|