This is a continuation of the previous post about Adjusting image pixels internally in Blender with bpy
results in this:
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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