The "Meet the GiMP!" ForumGiMP, Image Processing (DIP) and PhotographyImage Processing SoftwareScripts, Python, Perl and SchemeThe "Meaningful Black" script
Pages: [1] 2 3 4   Go Down
Print
Author Topic: The "Meaningful Black" script  (Read 6293 times)
Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« on: August 12, 2008, 04:11:27 pm »

This is a first draft for a plugin to manipulate the curves of an image in a way that Vincent Versace describes.

Basic function:

a) The user defines two colours that are to be replaced with "meaningful black" or "End of Zone IX white". 

b) The plugin gives a choice for the selection of the two replacement colours, default is 7,7,7 and 247,247,247.

c) The plugin replaces the colours from a) with the ones set in b) by twisting the curves of all three channels.

Enhancements:

d) Option to work on a layer generated with "copy visible".

e) Option to set only one point.


« Last Edit: August 12, 2008, 06:03:26 pm by Rolf » Logged

Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« Reply #1 on: August 12, 2008, 09:24:29 pm »

Attack plan ;-)

a) Until we have a dialogue with two eye droppers the user selects the colours as fore- and background colour.

b) According to the documentation http://www.gimp.org/docs/python/index.html a parameter of the type PF_COLOR in the register part of the plugin should put a colour selection option in a dialogue. Never tried that. Set 7 and 247 as default values.

c) gimp-curves-spline in the PDB should work: Modifies the intensity mapping for one channel in the specified drawable. The drawable must be either grayscale or RGB, and the channel can be either an intensity component, or the value. The 'control_pts' parameter is an array of integers which define a set of control points which describe a Catmull Rom spline which yields the final intensity curve. Use the 'gimp-curves-explicit' function to explicitly modify intensity levels. (That's not me talking....)

d) should be built in from start - then you can compare the effect.

e) Huh?
Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #2 on: August 13, 2008, 09:39:38 pm »

Just an idea for a different way for selecting the color-pixels.
Why not doing it the same way you did in the video?
I'm thinking of a dialog with a button "select bright pixel" and one "select dark pixel", when pressing this button you get a slider, +/- buttons or anything like it, when adjusting the value, the addon uses the threshold-tool for creating a temprar layer with this value. after clicking ok the addon does this:
* store the threshold-value as "VALUE"
* now create an image of the original with threshold VALUE
* now create an image of the original with threshold VALUE-1 (+1 for the bright pixel)
* substract both images
* find first black pixel (should be a loop from width to heigth and check on colour)
now you would have a pixel the colour could be changed to 7.7.7/247.247.247
I know it's some work to do, but it would take much work from the user because he doesn't have to track down the changed pixel.
The disadvantage of this method is you would not have any influence of wether this pixel is part of the foreground background or anything else. Is this important?
Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #3 on: August 13, 2008, 11:27:53 pm »

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os

from gimpfu import *
import os.path

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def meaningfull_black(img, drw):
    img.disable_undo()
   
    layer_new = drw.copy(True)
    layer_new.mode = NORMAL_MODE
    layer_new.name = "Meaningfull Black"
    img.add_layer(layer_new, -1)
   
    target_low=7
    target_top=247

    #print "1.red:   %3d" % gimp.get_foreground()[0]
    #print "1.green: %3d" % gimp.get_foreground()[1]
    #print "1.blue:  %3d" % gimp.get_foreground()[2]

    #print "2.red:   %3d" % gimp.get_background()[0]
    #print "2.green: %3d" % gimp.get_background()[1]
    #print "2.blue:  %3d" % gimp.get_background()[2]

    red_a   = gimp.get_foreground()[0]
    green_a = gimp.get_foreground()[1]
    blue_a  = gimp.get_foreground()[2]
    red_b   = gimp.get_background()[0]
    green_b = gimp.get_background()[1]
    blue_b  = gimp.get_background()[2]

    pdb.gimp_curves_spline(layer_new,HISTOGRAM_RED   ,4, [red_a,   target_low, red_b,   target_top] )
    pdb.gimp_curves_spline(layer_new,HISTOGRAM_GREEN ,4, [green_a, target_low, green_b, target_top] )
    pdb.gimp_curves_spline(layer_new,HISTOGRAM_BLUE  ,4, [blue_a,  target_low, blue_b,  target_top] )

    img.enable_undo()
    gimp.displays_flush
       

register(
    "python-fu-meaningfull-black",
    "First try of 'meaningfull black'",
    "",
    "Meetthegimp-Community",
    "GPL",
    "2008",
    "<Image>/Filters/meaningfull__black",
    "RGB*, GRAY*",
    [],
    [],
    meaningfull_black)
   

main()


Just a first throw, but it seems to work. It would be great if someone could confirm this...
You have to select the foregroundcolor as "dark" and the backgroundcolor as "light" colour.
I attached 2 images, one before this script and one after.


* before.jpg (29.79 KB, 640x426 - viewed 131 times.)

* after.jpg (44.71 KB, 640x426 - viewed 133 times.)
« Last Edit: August 13, 2008, 11:32:52 pm by WarEagle » Logged

andrewagill
Regular
**
Posts: 28


View Profile
« Reply #4 on: August 14, 2008, 12:15:22 am »

Just a first throw, but it seems to work. It would be great if someone could confirm this...
You have to select the foregroundcolor as "dark" and the backgroundcolor as "light" colour.
I attached 2 images, one before this script and one after.

A quick glance says you've done it.

I can't find Rolf's picture, so I can't check to see how this would work on that, especially with the lighting that he mentioned, but it looks very nice, especially with respect to the color casts.  You could almost shave in that pond's reflection.

You know, I have an idea.  I'll be back in a bit.

I think I've done it.  It's not the image from this week's show, but it works nonetheless:

« Last Edit: August 14, 2008, 12:44:18 am by andrewagill » Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #5 on: August 14, 2008, 01:35:58 am »

Hi andrewagill,
thanks for testing.
I mus say I'm really impressed by this meaningfull black-thing. I saw Rolfs presentation, but in the video there nearly was no difference, but I tested the script at some images and ... wow! I'm wondering how it worked without this method...

I tweaked the script a little bit.
You now can select if you want to use the foreground or the backgroundcolor or both (normal case and default).

* MeaningfullBlack.py (4.15 KB - downloaded 74 times.)
Logged

Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« Reply #6 on: August 14, 2008, 01:43:57 am »

Great - I just was not looking for a while, and here is a first plugin! :-)

I'll try it tomorrow.

The result of WarEagle is impressive. But there is one problem still to solve - there was no "meaningful black" in the image, only "meaningful blue". ;-) So we need to have a colour selection dialogue.

Tomorrow... ;-)
Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #7 on: August 14, 2008, 02:13:23 am »

Oh, you mean something like this? Smiley

Omg, you can get some REALLY strange results when selecting the wrong layer.

I'll better stop now, I don't know if that's what the meaningfull-blue-or-black-concept really wants. But it works Smiley

* MeaningfullBlack.py (5.46 KB - downloaded 88 times.)

* screenshot.jpg (22.37 KB, 439x375 - viewed 149 times.)
Logged

Magnade
Just in
*
Posts: 5


View Profile
« Reply #8 on: August 14, 2008, 05:03:06 am »

been tinkering around with the first revision of the script
then after registering i saw the newer script so I'm not going to bother posting what i did
(perhaps forum needs to allow attachments of .py to be seen by everyone?)

first item is i changed the disable undo to use
img.undo_group_start()
and enable undo to
img.undo_group_end()
this gives a single undo item in the undo list by the script name

second i moved the script to the artistic submenu i think it fits in better there
"<Image>/Filters/Artistic/Meaningfull Black",

third item was i added color picking in the dialog itself rather than messing with fg/bg
that bit looks like the below and also requires adding darkc and lightc to the function call
(PF_COLOR, "darkc",  "Dark",  (0,0,0) ),
(PF_COLOR, "lightc", "Light", (255,255,255) )


I do like this script idea tho since I seemed to be doing something like this already
just didn't have much clue that someone else had already thought of it
and put a name to it and such...
Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #9 on: August 14, 2008, 08:10:50 am »

Thank you Magnade,

I was searching for a way to get the colorpicker into the plugin, but I didn't find a way. Now I've copied the PF_COLOr into the script and removed the fore/background-stuff.
I also moved the plugin to Image/Filters/Enhance and made the changes with the undo-chain, didn't know this exists.

   Torsten


* screenshot.jpg (27.58 KB, 388x451 - viewed 126 times.)
* MeaningfullBlack.py (5.53 KB - downloaded 79 times.)
Logged

Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« Reply #10 on: August 14, 2008, 02:24:01 pm »

I tackled this too now and added a selection for the target colours. And I added the start and end points into the histogram manipulation. Now the curve starts at 0 and ends at 255. The low and high colour points are twisted to the target colours.

I think this does now exactly that what Versace described while using Photoshop. I still have to test it with some images but I think it will be on Tuesdays show.





* Screenshot.png (48.06 KB, 396x553 - viewed 135 times.)
* MeaningfulBlack.py (5.99 KB - downloaded 131 times.)
Logged

WarEagle
Regular
**
Posts: 38


View Profile
« Reply #11 on: August 14, 2008, 02:34:30 pm »

Hi Rolf,
I thought of the pointsd 0/0 and 255/255 too, but IMHO they aren't needed and can cause problems.
The results are 100% identical when leaving them (tested it with 2 images, one with 0/0 255/255 and one without.
BUT: when setting the dark color to black (0) or the light color to white (255) then the curve goes from 0/7 up to 255/255 and not from 0/7 to 255/247 as it should.
Maybe I did something wrong, but the results where different for me.
Logged

Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« Reply #12 on: August 14, 2008, 02:45:25 pm »

Hi Torsten,

I'll check that. From the look at a curve I had the impression that everything below the dark point had vanished.

Everything that is darker as the dark point should stay darker, for light it should stay lighter. So you can set the points in way that keep uninteresting parts in the dark.
Logged

Luigi
Regular
**
Posts: 74


View Profile
« Reply #13 on: August 14, 2008, 07:46:02 pm »

Silly question: how do you install/use the script in Gimp for windows? I have no problem with script-fu scripts but I've never played with a python script so a quick start is needed.

Luigi
Logged

Rolf
Administrator
Lives here ;-)
***
Posts: 389


View Profile
« Reply #14 on: August 14, 2008, 08:04:24 pm »

In the comments to http://meetthegimp.org/episode-038-a-phython-in-a-barrel/ there was a discussion about it , including links. As I have last used Win98SE as more as an "OnlyUser" I can't help you more.
Logged

Pages: [1] 2 3 4   Go Up
Print
Jump to: