Featured post

new redirect for blender.org bpy docs.

http://www.blender.org/api/blender_python_api_current/ As of 10/11 november 2015 we can now link to the current api docs and not be worr...

August 02, 2012

Firefly removal in blender

This is a continuation of the previous post about Adjusting image pixels internally in Blender with bpy

firefly removal

In optimal lighting conditions fireflies don't really occur often in cycles, I can't remember seeing any lately. here's a script that first creates a simulation of fireflies then removes them.
import bpy
import random
D = bpy.data
image_name = 'pixeltest4'
if not image_name in D.images:
image_object = D.images.new(name=image_name, width=40, height=30)
image_object = D.images[image_name]
num_pixels = len(image_object.pixels)
""" set default values """
dm = [.2, .2, .2, 1.0] * (int(num_pixels/4))
""" randomize background noise """
for i in range(0,len(dm),4):
# only affect RGB, not A. Never full white.
for j in range(3):
dm[i+j] = (random.random()*.5)
""" insert fireflies at random """
last_pixel = False
for i in range(0,len(dm),4):
rand_val = random.random()
if rand_val > .97 and not last_pixel:
last_pixel = True
for j in range(3):
dm[i+j] = (1.0)
else:
last_pixel = False
""" assign list to pixels """
image_object.pixels = dm
results in this:

TBC

As you can see it's probably an ok simulation, looking at it tells me something about a potential algorithm.
  • collect all whites
  • sample colour from the surrounding non white pixels
Most images don't have any pixels that are fully white, so i won't include a check for all surrounding pixels.

Finished firefly removal script can be found here: link