Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

HDR is a library that handles RAW image format written with Golang

License

NotificationsYou must be signed in to change notification settings

mdouchement/hdr

Repository files navigation

GoDocGo Report CardLicense

HDR is a library that handles RAW image format written with Golang.Here some rendering examples.

It aims to provide tools to readHDR files and convert it to a LDR (Low Dynamic Range, aka PNG/JPEG/etc.) in animage.Image object.

Documentations:

Supported codecs (file formats)

  • Radiance RGBE/XYZE
  • PFM, Portable FloatMap file format
  • TIFF usingmdouchement/tiff
  • CRAD, homemade HDR file format

Supported tone mapping operators

Read thisdocumentation to find what TMO use.

Read thisdocumentation to understand what is a TMO.

  • Linear
  • Logarithmic
  • Drago '03 - Adaptive logarithmic mapping for displaying high contrast scenes
  • Durand - Fast bilateral filtering for the display of high-dynamic-range images
  • Reinhard '05 - Photographic tone reproduction for digital images
    • Playing with parameters could provide better rendering
  • Custom Reinhard '05
    • Rendering looks like a JPEG photo taken with a smartphone
  • iCAM06 - A refined image appearance model for HDR image rendering

Usage

go get github.com/mdouchement/hdr
package mainimport ("fmt""image""image/png""os""runtime""time""github.com/mdouchement/hdr"_"github.com/mdouchement/hdr/codec/rgbe""github.com/mdouchement/hdr/tmo")// Samples://// http://www.anyhere.com/gward/hdrenc/pages/originals.html// http://resources.mpi-inf.mpg.de/tmo/logmap/ (High Contrast Scenes)var (// input = "/Users/mdouchement/tmp/hdr/memorial_o876.hdr"// input = "/Users/mdouchement/tmp/hdr/MtTamWest_o281.hdr"// input = "/Users/mdouchement/tmp/hdr/rend02_oC95.hdr"// input = "/Users/mdouchement/tmp/hdr/Tree_oAC1.hdr"input="/Users/mdouchement/tmp/hdr/Apartment_float_o15C.hdr"output="/Users/mdouchement/tmp/hdr/output.png")funcmain() {fmt.Printf("Using %d CPUs\n",runtime.NumCPU())fi,err:=os.Open(input)check(err)deferfi.Close()start:=time.Now()m,fname,err:=image.Decode(fi)check(err)fmt.Printf("Read image (%s) took %v\n",fname,time.Since(start))ifhdrm,ok:=m.(hdr.Image);ok {startTMO:=time.Now()// t := tmo.NewLinear(hdrm)// t := tmo.NewLogarithmic(hdrm)// t := tmo.NewDefaultDrago03(hdrm)// t := tmo.NewDefaultDurand(hdrm)// t := tmo.NewDefaultCustomReinhard05(hdrm)t:=tmo.NewDefaultReinhard05(hdrm)// t := tmo.NewDefaultICam06(hdrm)m=t.Perform()fmt.Println("Apply TMO took",time.Since(startTMO))}fo,err:=os.Create(output)check(err)png.Encode(fo,m)fmt.Println("Total",time.Since(start))}funccheck(errerror) {iferr!=nil {panic(err)}}

HDR Tools

https://github.com/mdouchement/hdrtool

License

MIT

Implementing a TMO

A TMO must implementtmo.ToneMappingOperator:

typeToneMappingOperatorinterface {// Perform runs the TMO mapping.Perform() image.Image}

Implementing an image codec

  • Reader
// DecodeConfig returns the color model and dimensions of a PFM image without// decoding the entire image.funcDecodeConfig(r io.Reader) (image.Config,error) {// ...returnm,err}// Decode reads a HDR image from r and returns an image.Image.funcDecode(r io.Reader) (img image.Image,errerror) {// ...return}funcinit() {// Register the format in the official lib.// https://golang.org/pkg/image/#RegisterFormatimage.RegisterFormat("format-name","magic-code",Decode,DecodeConfig)}
  • Writer
// Encode writes the Image m to w in PFM format.funcEncode(w io.Writer,m hdr.Image)error {returnnil}

Contributing

All PRs are welcome. If you implement a TMO or an image codec in a dedicated repository, please tell me in order to link it in this readme.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

As possible, run the following commands to format and lint the code:

# Formatfind. -name'*.go' -not -path'./vendor*' -exec gofmt -s -w {}\;# Lintgolangci-lint run -c .golangci.yml

[8]ページ先頭

©2009-2025 Movatter.jp