It is currently 01 Jun 2020, 08:53

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | 🡆 Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Change Luminosity Mask Script

Post your Script Requests for GIMP here.
Forum rules
Request your Script(s) for GIMP here in this forum.
Provide details of steps performed in GIMP so that script can be written for the process and also give the request a name so that scripts can be named after.
david
Forum Member

Re: Change Luminosity Mask Script

Post#11 by david » 13 Nov 2019, 21:35


setup_luminosity_masking_layers.py
(3.86 KiB) Downloaded 46 times
Our posts have overlapped!!!

Krikor,
I suggest you try my new script before tim puts in a lot of work correcting the SG version.
Also (thanks to dinasset) another version has come to light. This version is written in Python. I will add it to this post.
But for my purposes it's disadvantage is that it puts Lights, Mids and Darks into three layer groups. It is possible to adjust one of the three in each layer group, but they cannot be used independently.

david.

Edit: Apologies Krikor - now I re-read your post I realize that it is the Zone Separation script which you have asked tim to update.
Last edited by david on 13 Nov 2019, 21:42, edited 1 time in total.
0

Krikor
Forum Member

Post#12 by Krikor » 13 Nov 2019, 21:41


david wrote:
13 Nov 2019, 21:27
tim,
Your script works great. You can select any one of the nine layers and make adjustments.

Krikor,
My script (above) is a modification of tim's script and will do everything that the Saul Goode version is capable of.
By selecting and adjusting, for instance, L, M, & D you will get the same results as MM. Selecting DD & DDD will give the same results as DD. However, you now have seven non-overlapping channels which you can also adjust individually or in any combination. That was the aim of the change.
If you would like to try it, I would be pleased to read your comments or criticisms.

david.
@@david
"However, you now have seven non-overlapping channels which you can also adjust individually or in any combination"
why 7 channels? Shouldn't it be 9 (D, DD, DDD, M, MM, MMM, L, LL, LLL)?

I will do the following:
I will do the channels manually and compare the results with the version of the script you edited.

BTW: When you emphasized "without really understanding what I was doing !!!", I confess that I was afraid. :aw_shucks_purple:
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
0

david
Forum Member

Post#13 by david » 13 Nov 2019, 21:53


Krikor,
The reason there are now only 7 channels is because in the previous version there was an overlap between channels.
L included LL and LLL.
LL included LLL
MM included L, M and D
MMM included LL, L, M, D and DD
Similarly for the Darks.
With my new version there is no overlap between channels, but they can be used in any combination or independently.

My comment about "not understanding what I was doing" was because I have little or no knowledge of the scripting language, but fortunately tim's script was full of useful comments - I wish all programmers would do that!
0

tim
GL Blogger

Post#14 by tim » 13 Nov 2019, 22:22


Krikor wrote:
13 Nov 2019, 21:25
tim wrote:
13 Nov 2019, 21:16
sure I can take a look at it..where is it?
Here it there,
Here it is edited to call gimp-drawable-threshold (new) instead of deprecated gimp-threshold and edited values to be
0.0 to 1.0 instead of the deprecated 0-255.

Code: Select all

;
;   zone-separation.scm - script-fu for The Gimp
;	ZS-Separator - Separate a b/w-photo according to the zone system 
;   Version 0.8 (2013-11-15) 
;   testet with The Gimp 2.8
;   Copyright (C) 2013 Leif Pullich - liclic@gmx.de
; 
; Description
; 
; The script is intended to do some annoying work for a photographer
; who wants to analyze a b/w-photo according to the zone system
; of Ansel Adams.
; 
;   What it does
;
; ZS-Separator creates 11 masked layers, each representing one of the 11
; tonal zones of the zone system. The mask of each layer makes all pixels
; transparent which do not belong to the gray values of the corresponding
; zone. The sum of all layers gives the complete photo.
; Additionally, four differently colored layers are inserted below the
; stack of the zone layers which can be used to highlight pixels belonging
; to selected zones.
;
;   How to use it
;
; Activate the layer you  want to analyze and run the script. You will
; find the menu entry in Filters/Generic/Zone System Separator.
; Turn the colored layers below the layer stack invisible except
; one. Play around with the visibility or opacity of the zone layers.
; 
;   Shortcomings 
;
; - works only with RGB-images
; - does not check whether it has already been run. Hence, if it is
;   run again all layers will be created again
; - suits only for analyzing. There's no dynamic adaption if
;   you make changes to your original layer or to the zone layers 
;   If you did and you want to analyze the result, run the script again
; - excessively commented. Since the author is not a programmer he would
;   have appreciated to find more comments in other scripts while learning
;   script-fu
;
; The value ranges for each zone are inspired from an article by
; Thomas Brotzler on focussiert.com:
; http://fokussiert.com/2013/03/20/digitale-schwarzweisfotografie-das-zonensystem-2/
;
; TODO:
; - make it work with other image types or insert a check and warning
; - check whether the colored layers are already there, to avoid 
;   doubling when the script ist run again
; ----------------------------------------------------------------------
; Change log
;    - released: 2013-11-15
;	 - edited: 2019-11-13 
;              Tin Tran added subtract 1 from low value and go up to 256 
;                       call gimp_drawable_threshold instead of gimp_threshold
;                       and divide low and high values by 256 so we get a float value from 0 to 1.0 because that's what the new call requires.
;                  
;
; ----------------------------------------------------------------------
;
;    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, see <http://www.gnu.org/licenses/>.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; subs
(define (sub-copy-layer inImage inLayer inLayerName)
	;; copy the layer <inLayer> and set it's name to <inLayerName>
	;; create copy of the orgininal layer, insert copy, set name 
	(let ((nZone 0))
	(set! nZone (car (gimp-layer-copy inLayer FALSE))) 
	(gimp-image-insert-layer inImage nZone 0 -1)
	(gimp-item-set-name nZone inLayerName)
	)
)

(define (sub-add-mask inLayer maskType)
	;; ad a mask of the type <maskType> to the copied layer
	;; create mask, set edit mode
	(gimp-layer-add-mask inLayer (car (gimp-layer-create-mask inLayer maskType)))
	(gimp-layer-set-edit-mask inLayer TRUE)
)

(define (sub-apply-threshold inLayer inValues)
	;; apply threshold-tool to the layer's mask 
	;;(gimp-threshold (car (gimp-layer-get-mask inLayer)) (car inValues) (cadr inValues))
	(gimp-drawable-threshold (car (gimp-layer-get-mask inLayer)) 0 (/ (car inValues) 256) (/ (cadr inValues) 256) )
)				

(define (sub-create-layer inImage inLayer inColVals)
	;; create colored layer
	(let*
		(
		(imageWidth (car(gimp-drawable-width (car(gimp-image-get-active-layer inImage)))))
		(imageHeight(car(gimp-drawable-height(car(gimp-image-get-active-layer inImage)))))
		(drawableType 0)    ;set drawable type to RGB (TODO: insert check of image type)
		(clayParent 0) 		;position new layer in main stack
		(clayPosition -1)	;position new layer directly above the current layer
		(clayOpacity 100)	;set full opacity
		(clayMode 0)		;set layer mode to normal
		(clayFillType 0)	;set fill-type to fill with foreground color
		(clayName (car inColVals))
		(clayColor(cdr inColVals))
		(cLayer)			;anonymous layer object
		)
		(gimp-context-set-foreground clayColor)
		(set! cLayer(car(gimp-layer-new inImage imageWidth imageHeight drawableType clayName clayOpacity clayMode)))
		(gimp-image-insert-layer inImage cLayer clayParent clayPosition)
		(gimp-drawable-fill cLayer clayFillType)
	)
)
;; main
(define (script-fu-separate-zones inImage inLayer)

	(let*
		(
		(baseLayer inLayer)
		;; each element of the following vector definition is a list 
		;; containing the layer's name and values for the threshold
		;; tool
 		;; (STR_LAYER_NAME NUM_THRESHOLD_LOW NUM_THRESHOLD_HIGH)			
		(zones #(				;define vector for zone values
			("Zone 0" 0 13)
			("Zone I" 13 39)
			("Zone II" 39 64)
			("Zone III" 64 89)
			("Zone IV" 89 115)
			("Zone V" 115 140)
			("Zone VI" 140 165)
			("Zone VII" 165 191)
			("Zone VIII" 191 216)
			("Zone IX" 216 242)
			("Zone X" 242 256)
			) 	
		)						;end zones
		(zoneLayer)				;layer for the zone to create
		(zoneLayerName "")		;name of the layer
		(zoneData)				;stores list from vector with the values for zone to create
		(i 10)					;counting variable
		;; (STR_LAYER_NAME NUM_R  NUM_G NUM_B)
		(vColoredLayers #(			;define vector for colored layer values
			("zs red"   255 0 0)
			("zs cyan"  0 255 255)
			("zs black" 0 0 0)
			("zs white" 255 255 255)
			)
		)						;end vColoredLayers
		) 
								;end var definition
		;; preliminaries
		(gimp-context-push)
		(gimp-image-undo-group-start inImage)
		(gimp-progress-init "Creating zones" -1)
		(gimp-progress-pulse)
		
		;; START - work thru all elements of <zones>
		(while (>= i 0)
		
		;; get list from vector for zone to create
		(set! zoneData (aref zones i)) 
		
		;; call sub for copying the original layer
		;; set name for layer, call sub, get layer for next step
		(set! zoneLayerName (car zoneData)) 
		(sub-copy-layer inImage baseLayer zoneLayerName) 
		(set! zoneLayer (car(gimp-image-get-active-layer inImage))) 
				
		;; call sub for generating new mask
		(sub-add-mask zoneLayer 5)
		
		;; call sub for applying threshold-tool to mask with values
		(sub-apply-threshold zoneLayer (cdr zoneData))
		
		;; set original layer as active layer
		(gimp-image-set-active-layer inImage baseLayer)
						
		;; update counter 
		(set! i (- i 1))
		) ;endwhile		
		
		;; insert colored layers
		(let((j 0)) ;; very locally defined counter
			(while (< j 4)
			(sub-create-layer inImage baseLayer (aref vColoredLayers j))
			;; pass each value list from vector-----------^
			(set! j (+ j 1))
			)
		)
		 
		;; cleanup
		(gimp-context-pop)
		(gimp-image-undo-group-end inImage)
		(gimp-progress-set-text "Ready")
		(gimp-progress-update 1.0)
		(gimp-displays-flush)
		
	)

)				
		


(script-fu-register 
	"script-fu-separate-zones"
	"Zone System Separator"
	"Separates a b&w photo according to the zone system. Set selected \
	 zone layers unvisible and use the colored layers to bring out the \
	 pixels belonging to the zone"
	"Leif Pullich"
	"2013 Leif Pullich under \
	terms of CC-License BY-NC Version XX"
	"Oktober 2013"
	"RGB*"
	
	SF-IMAGE "image" 0 
    SF-DRAWABLE "layer" 0 

)
(script-fu-menu-register 
	"script-fu-separate-zones"
	"<Image>/Filters/Generic"
)


aka Tin
:tree_02:
Tin's: Favorite Index | Simple Art === fb4yt video search | fb4yt recent video views report
Lottery numbers from image | Interested Members in TLF
Paying for hosting is to support my hobby, and donating money made from ads to The Red Cross.
         
1

Krikor
Forum Member

Post#15 by Krikor » 14 Nov 2019, 04:16


@@david ,

I didn't really have time to check the script thoroughly. I haven't even edited any images with it (yet). I just limited myself to compare the expected results with the ones the script produces.

For this:
  • Manually created the channels.
  • I compared the results with those obtained by SG-Luminosity-Masks.scm.
Noting that the results obtained manually were reliable, I compared them with the results obtained by DM_Luminosity_Masks.scm.
Krikor - SGLuminosity masks X DM_Luminosity
Krikor - SGLuminosity masks X DM_Luminosity
MaskChannelOk.jpg (139.49 KiB) Viewed 2012 times
This version is quite different, both SaulGoode and Tim's. It's kind of a mix of the two.
In addition to the channels with only 4 tones: L, LL, D and DD, there are also 7 layers with masks (missing M and MM).

As I said, I didn't have time to check the accuracy of this version, but I noticed the following:

The 4 channels in DM_Luminosity (L, LL, D, and DD) are identical to those obtained with the SaulGoode script and displayed on Pat David's website.

But the masks found in the layer window are different from the masks generated using existing channels.
Krikor - Masks on channels other than channels
Krikor - Masks on channels other than channels
MaskLayersDiffer.jpg (105.19 KiB) Viewed 2012 times
Somehow the algorithm that generates the layers window masks is producing a different result than expected.
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
0

Krikor
Forum Member

Post#16 by Krikor » 14 Nov 2019, 04:36


tim wrote:
13 Nov 2019, 22:22

Here it is edited to call gimp-drawable-threshold (new) instead of deprecated gimp-threshold and edited values to be
0.0 to 1.0 instead of the deprecated 0-255.

Code: Select all

...
@tim, you did it! :hi5:
I haven't thoroughly tested the script yet, here is 1:31 am, I need to go to sleep, :off_to_bed_purple:
but I'm glad the reported problem no longer exists! :confetti:
Thank you!
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
1

Krikor
Forum Member

Post#17 by Krikor » 14 Nov 2019, 12:15


Ofnuts has just released a new and different version for luminosity masks.
I already downloaded it and started reading the file that comes with the script.
Looks like the fun will continue.

Version is at: https://www.gimp-forum.net/Thread-ofn-luminosity-masks
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
0

david
Forum Member

Post#18 by david » 14 Nov 2019, 13:55


Krikor,
My new script is not working as intended.

This morning I created an image with a gradient to test it.

Masks LL, LLL, DD, and DDD behave as I intended, but at present I am unable to persuade the script to subtract DD & DDD from D - the equivalent problem for the L mask and I cannot get all the Lights & Darks to subtract from the M. So, at present L, M & D remain as the previous version.

I suspect that my problems may be with loop counting possibly, but this programming language appears very convoluted to me and at present I don't have the time to make a detailed study of it.
david.
0

Krikor
Forum Member

Post#19 by Krikor » 14 Nov 2019, 15:56


david wrote:
14 Nov 2019, 13:55
Krikor,
My new script is not working as intended.

This morning I created an image with a gradient to test it.

Masks LL, LLL, DD, and DDD behave as I intended, but at present I am unable to persuade the script to subtract DD & DDD from D - the equivalent problem for the L mask and I cannot get all the Lights & Darks to subtract from the M. So, at present L, M & D remain as the previous version.

I suspect that my problems may be with loop counting possibly, but this programming language appears very convoluted to me and at present I don't have the time to make a detailed study of it.
david.
"but at present, I am unable to persuade the script to subtract DD & DDD from D - the equivalent problem for the L mask and I cannot get all the Lights & Darks to subtract from the M. So, at present L, M & D remain as the previous version."
@david ,
Why subtract DD and DDD from D?
I think this would be impossible as a result you have everything black.

The Mids you get eliminated the lights and darks tones of the image.

If you subtract L from M you will get LL again.
If you subtract L from MM you will get LLL again.
But you already have these channels.


My concern was not being able to use the newer versions of Gimp without being able to use SG-LuminosityMasks. I could always create the channels manually, but ...

Considering that Tim's script and now Ofnuts's have scared off this dark future, I'm already relieved.

David, good to see you messing with the language of these scripts. I tried to start once, but without realizing it had stopped. Maybe one day I'll try this hobby again.
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston
0

david
Forum Member

Post#20 by david » 15 Nov 2019, 10:28


Krikor,

I have not made it clear in my previous posts as to what I was trying to achieve in modifying Tim's script.
The aim was to be able, with one run of the script, to use any of the masks, independently or in combination. Each of the masks must not have any effect on the other layers or masks.

To hopefully clarify the intention, I have attached an image of a gradient showing the range each mask would affect.

Perhaps one day I may be able to change the code to get this result!

david.
masks.jpg
masks.jpg (12.64 KiB) Viewed 1964 times
0


GIMP/GL:  Tutorials | Tips | Questions | Interests | 🡆 Script Requests
Recommendations:  Index | Top 10
Resources:  Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 5 guests