#!/usr/bin/env python # -*- coding: utf-8 -*- # Debanding - reduces high ISO banding and blue haze. # Copyright (C) 2011 Mario Mlačak # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. from gimpfu import * gettext.install("gimp20-python", gimp.locale_directory, unicode=True) pdb = gimp.pdb TYPE_DEBAND = 0 TYPE_DENOISE = 1 TYPE_DENOISE_MORE = 2 def debanding(image, drawable, denoise_type, if_flatten): gimp.context_push() image.undo_group_start() gimp.progress_init() for l in image.layers: pdb.gimp_drawable_set_visible(l, False) gimp.progress_update(0.1) layer = image.active_layer if layer is None: layer = drawable pdb.gimp_drawable_set_visible(layer, True) gimp.progress_update(0.2) do_deband = denoise_type == TYPE_DEBAND do_denoise = denoise_type == TYPE_DENOISE do_denoise_more = denoise_type == TYPE_DENOISE_MORE do_denoising = do_denoise or do_denoise_more luminosity = pdb.gimp_layer_new_from_drawable(layer, image) gimp.progress_update(0.3) luminosity.name = "Luminosity" index = pdb.gimp_image_get_layer_position(image, layer) pdb.gimp_image_add_layer(image, luminosity, index+1) pdb.gimp_desaturate_full(luminosity, DESATURATE_LUMINOSITY) gimp.progress_update(0.4) if do_denoising: lightness = pdb.gimp_layer_new_from_drawable(layer, image) gimp.progress_update(0.5) lightness.name = "Lightness" pdb.gimp_image_add_layer(image, lightness, index+1) pdb.gimp_desaturate_full(lightness, DESATURATE_LIGHTNESS) gimp.progress_update(0.6) if do_denoise: pdb.gimp_layer_set_mode(lightness, OVERLAY_MODE) elif do_denoise_more: pdb.gimp_layer_set_mode(lightness, MULTIPLY_MODE) pdb.gimp_layer_set_mode(layer, COLOR_MODE) deband = pdb.gimp_layer_new_from_visible(image, image, "Debanded") pdb.gimp_image_add_layer(image, deband, index) gimp.progress_update(0.9) pdb.gimp_layer_set_mode(layer, NORMAL_MODE) pdb.gimp_image_remove_layer(image, luminosity) if do_denoising: pdb.gimp_image_remove_layer(image, lightness) if if_flatten: flat = pdb.gimp_image_flatten(image) gimp.progress_update(1.0) image.undo_group_end() gimp.context_pop() register( "python-fu-debanding", N_("Reduces high ISO banding, blue haze \n" \ "and chroma noise in active layer, \n" \ "generaly produced by Olympus gear."), "Reduces high ISO banding, blue haze \n" \ "and chroma noise in active layer, \n" \ "generaly produced by Olympus gear.", "Mario Mlačak", "Mario Mlačak", "2011", N_("_Debanding ..."), "RGB*", [ (PF_IMAGE, "image", "Input image", None), (PF_DRAWABLE, "drawable", "Input drawable", None), (PF_RADIO, "denoise_type", _("Type"), TYPE_DEBAND, ((_("Deband"), TYPE_DEBAND), (_("Denoise"), TYPE_DENOISE), (_("Denoise more"), TYPE_DENOISE_MORE))), (PF_TOGGLE, "if_flatten", _("Flatten image"), False), ], [], debanding, menu="/Filters/Enhance", domain=("gimp20-python", gimp.locale_directory) ) main()