Git Product home page Git Product logo

bilateral's Introduction

Bilateral Filter for Torch

A Lua Torch wrapper for the fast bilateral filter by Sylvain Paris and Frédo Durand.

Can also be used for cross/joint bilateral filtering.

Installation

Make sure you have Torch installed.

To install use:

git clone https://github.com/dmarnerides/bilateral.git
cd bilateral
./install.sh

Note:

  • Only accepts two dimensional tensors, i.e. only luminance channels.
  • Luminance needs to be [0,1]
  • Currently supports:
    • FloatTensor
    • DoubleTensor

Use

filter(img,edge,sigma_s,sigma_r)

Example:

local bilateral = require('bilateral')

-- Assuming a luminance channel lum, using default values
local filteredLum = bilateral.filter(lum)

-- Cross bilateral filter of lum given edgeLum, with given parameters
local filteredLum = bilateral.filter(lum,edgeLum,sigma_s,sigma_r)

To filter an rgb image, linearize it, compute the luminance, filter and then replace the luminance

Example 2:

local bilateral = require('bilateral')
local image = require('image')

local img = image.load('dragon.jpg',3,'float') -- load as float [0,1]

-- Linearize (remove gamma, usually gamma = 2.2)
img:pow(2.2)

-- Compute luminance
local lum = img[1]:clone()
lum:mul(0.2126):add(torch.mul(img[2],0.7152)):add(torch.mul(img[3],0.0722))

-- Filter
local filteredLum = bilateral.filter(lum)

-- Replace luminance
local filtered = img:clone()
for i=1,3 do filtered[i]:cmul(filteredLum):cdiv(lum) end
-- Replace NaNs from division with 0
filtered[filtered:ne(filtered)] = 0 

-- Add gamma and save
filtered:pow(1/2.2)
image.save('dragonFiltered.jpg',filtered)

bilateral's People

Contributors

dmarnerides avatar

Watchers

James Cloos avatar simongao 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.