Notifications
Clear all

[Closed] Swap green for blue wisely

so in the end the function would be

fn swap_gb c = (
	
	local nr =0.229
	local ng =0.587
	local nb =0.114

	color c.r (c.b*nb/ng) (c.g*ng/nb)

	)

swap_gb (color 0.848 0.429 0.111)
swap_gb (color 0.848 0.429 0.111)
-- (color 0.848 0.0215571 2.20897)

it would be too easy… but (color 0.848 0.0215571 2.20897)

i know, i wrote it in post °10

since the blue channel maximum (or 1.0) is way less than the green i see no other options unless you want to normalize the first color to the blue maximum intensity.

you can see in the format of post °10 the luminancce values are the same but you cant create something out of nothing.

i see no other options. do you?

(	
	try destroydialog ::RO_SWAP_CHANNELS catch()

	rollout RO_SWAP_CHANNELS "" width:216 height:234
	(
		groupBox    grp1 "Master Color"     pos:[8,  4] width:200 height:100
		groupBox    grp2 "Swapped Channels" pos:[8,108] width:200 height:118
		
		colorPicker cp1 "" pos:[ 13, 20] fieldwidth:182 height:76
		colorPicker cp2 "" pos:[ 13,124] fieldwidth:88  height:76
		colorPicker cp3 "" pos:[108,124] fieldwidth:88  height:76
		
		label lb1 "Direct Swap"     pos:[ 34, 206]
		label lb2 "Fixed Luminance" pos:[118, 206]
		
		fn GetLuminance colour =
		(
			return (colour.g^2.4 * 0.7152 + colour.b^2.4 * 0.0722)^0.333333
		)
		
		fn SwapBlueGreenChannels colour =
		(
			if colour.g == colour.b do return colour
			
			c1 = color 0 colour.g colour.b
			c2 = color 0 colour.b colour.g
			
			l1 = GetLuminance c1
			
			done = false
			
			for j = 1 to 255 while not done do
			(
				c2.v = j
				done = (GetLuminance c2) > l1
			)
			
			for j = c2.g to 255 while not done do
			(
				c2.g += 1
				done = (GetLuminance c2) > l1
			)
			
			c2.r = colour.r
			c2.g = int (c2.g + 0.5)
			c2.b = int (c2.b + 0.5)
			
			return c2
		)
		
		on RO_SWAP_CHANNELS open do
		(
			c = random black white
			
			cp1.color = c
			cp2.color = color c.r c.b c.g
			cp3.color = SwapBlueGreenChannels c
		)
		
		on cp1 changed arg do
		(
			cp2.color = color arg.r arg.b arg.g
			cp3.color = SwapBlueGreenChannels arg
		)
	)

	createdialog RO_SWAP_CHANNELS style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
)

Oh! Very nice!

where did you find the formula above?

I remember another theory, there the RGB constants for brightness (perceived by the human eye) are (0.299, 0.587 and 0.114)
when I add these numbers to your formula, the result gets closer to what I expected to see.

(	
	try destroydialog ::RO_SWAP_CHANNELS catch()

	rollout RO_SWAP_CHANNELS "" width:448 height:244
	(
		group "Master Color: "
		(
			colorPicker cp1 fieldwidth:415 height:76 align:#left
			
			label lb0 offset:[0,-14]
		)
		group "Swapped Channels: "
		(
			colorPicker cp2 fieldwidth:100 height:76 align:#left enabled:off across:4
			colorPicker cp3 fieldwidth:100 height:76 align:#left enabled:off
			colorPicker cp4 fieldwidth:100 height:76 align:#left enabled:off
			colorPicker cp5 fieldwidth:100 height:76 align:#left enabled:off

			label lb1 "Direct Swap" align:#center across:4
			label lb2 "Luminance"
			label lb3 "Brightness"
			label lb4 "Brightness (SQRT)"
		)
		
		
		fn GetLuminance0 colour =
		(
			return (colour.g^2.4 * 0.7152 + colour.b^2.4 * 0.0722)^0.333333
		)
		fn GetLuminance1 colour =
		(
			return (colour.r^2 * 0.299 + colour.g^2 * 0.587 + colour.b^2 * 0.114)
		)
		fn GetLuminance2 colour =
		(
			return sqrt(colour.r^2 * 0.299 + colour.g^2 * 0.587 + colour.b^2 * 0.114)
		)
		
		fn SwapBlueGreenChannels colour model:1 =
		(
			if colour.g == colour.b do return colour
			
			c1 = color 0 colour.g colour.b
			c2 = color 0 colour.b colour.g
			
			GetLuminance = case model of
			(
				1: GetLuminance0 
				2: GetLuminance1 
				3: GetLuminance2
			)
			
			l1 = GetLuminance c1
			
			done = false
			
			for j = 1 to 255 while not done do
			(
				c2.v = j
				done = (GetLuminance c2) > l1
			)
			
			for j = c2.g to 255 while not done do
			(
				c2.g += 1
				done = (GetLuminance c2) > l1
			)
			
			c2.r = colour.r
			c2.g = int (c2.g + 0.5)
			c2.b = int (c2.b + 0.5)
			
			return c2
		)
		
		on RO_SWAP_CHANNELS open do
		(
			c = random black white
			
			cp1.color = c
			cp2.color = color c.r c.b c.g
			cp3.color = SwapBlueGreenChannels c
		)
		
		on cp1 changed arg do
		(
			cp2.color = color arg.r arg.b arg.g
			cp3.color = SwapBlueGreenChannels arg model:1
			cp4.color = SwapBlueGreenChannels arg model:2
			cp5.color = SwapBlueGreenChannels arg model:3
		)
		on RO_SWAP_CHANNELS open do
		(
			cp1.changed cp1.color
		)
	)

	createdialog RO_SWAP_CHANNELS style:#(#style_titlebar, #style_toolwindow, #style_sysmenu)
)

This is a slightly modified interface and two “brightness” methods have been added for comparison.
I like the simple “Brightness”.

although, from a “scientific” point of view, Brightness (SQRT) looks more convincing

I found the article: Why You Should Forget Luminance Conversion and Do Something Better

I modified the original CIELAB equations.

I agree, they may look a bit better, specially for some colors.

Page 2 / 4