Giter VIP home page Giter VIP logo

sphericalharmonics's Introduction

SphericalHarmonics

Spherical harmonics for radiance maps in Python (numpy).

I wrote this code because I found it was difficult to obtain coefficients for a radiance map from existing libraries (especially in Python).

Features:

  • Obtain coefficients for a radiance map (in equirectangular format)
  • Numpy vectorised for efficiency
  • Windowing function for reducing ringing artefacts
  • Reconstruct radiance map from coefficients
  • Obtain diffuse BRDF coefficients
  • Render a diffuse map (given radiance map coefficients)
  • Supports an arbitrary number of bands
  • Plot the spherical harmonics in a figure
  • Render a ground truth diffuse map to compare with.

The ground truth diffuse map can be a little slow to compute, so I've added the ability to render the diffuse values at a low resolution while sampling the high resolution source image. After rendering at a low resolution, I increase the resolution (so it's easier to see) using Lanczos interpolation. I found doing it this way was the most efficient while also producing high quality ground truth images.

Usage

python sphericalHarmonics.py [string filename.ext] [int nBands]

Example: python sphericalHarmonics.py radianceMap.exr 2

See the main function to see examples of functions you can utilise in your own code.

References

Things TODO if people want it (and if I can be bothered):

  • Support other formats (e.g. cubemap, angular map, etc.)
  • Change, remove, or support other modules (e.g. I use imageio for reading HDR images, cv2 for resizing, etc.)
  • More optimisations
  • Other windowing methods
  • Other visualisations
  • Restructure code
  • etc.

Dependencies

You can use pip to install the modules I've used. The only gotcha is with imageio. By default it does not provide OpenEXR support. To add OpenEXR support to imageio, see here: https://imageio.readthedocs.io/en/stable/format_exr-fi.html#exr-fi

Update: The website above appears to not work. Run the following in python (after installing imageio): imageio.plugins.freeimage.download()

License

MIT License

Copyright (c) 2018 Andrew Chalmers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

sphericalharmonics's People

Contributors

chalmersgit avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.