Wed Nov 22, 2023 11:49 am
#!/usr/bin/env python
# get-average-color.py
# Created by TT
# Trying to help solve this problem: https://old.reddit.com/r/GIMP/comments/17nxc75/is_there_a_way_i_can_average_and_blend_colors_of/
# Comments to gimpchat.com or gimp-forum.net
# License: GPLv3
# 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.
#
# To view a copy of the GNU General Public License
# visit: http://www.gnu.org/licenses/gpl.html
#
#
# ------------
#| Change Log |
# ------------
# Rel 1: Initial release
from gimpfu import *
def get_average_color(img, layer):
# #Set up an undo group, so the operation will be undone in one step.
#pdb.gimp_undo_push_group_start(img)
mean_r,std_dev,median,pixels,count,percentile = pdb.gimp_drawable_histogram(layer,HISTOGRAM_RED,0.0,1.0)
mean_g,std_dev,median,pixels,count,percentile = pdb.gimp_drawable_histogram(layer,HISTOGRAM_GREEN,0.0,1.0)
mean_b,std_dev,median,pixels,count,percentile = pdb.gimp_drawable_histogram(layer,HISTOGRAM_BLUE,0.0,1.0)
pdb.gimp_context_set_foreground((int(mean_r),int(mean_g),int(mean_b)))
# pdb.gimp_undo_push_group_end(img)
# #Ensure the updated image is displayed now
# pdb.gimp_displays_flush()
register(
"python_fu_get_average_color",
"Get Average Color and sets it foreground color",
"Get Average Color and sets it foreground color",
"TT",
"TT",
"November 22, 2023",
"Get Average Color",
"RGB*", # Alternately use RGB, RGB*, GRAY*, INDEXED etc.
[
#INPUT BEGINS
(PF_IMAGE, "img", "Image", None),
(PF_DRAWABLE, "layer", "Drawable", None),
#INPUT ENDS
],
[],
get_average_color,
menu="<Image>/Python-Fu")
main()
Wed Nov 22, 2023 12:54 pm
Wed Nov 22, 2023 2:11 pm
Wed Nov 22, 2023 3:02 pm
Wed Nov 22, 2023 5:06 pm
Wed Nov 22, 2023 6:11 pm
Thu Nov 23, 2023 8:28 am
trandoductin wrote:What I am confused doesn't gimp_histogram do mean meaning mean? What's the error in logics since I can't see any.
Or if you mean blend based on perception then there's no way for me to do that accurately.