I don't know if all this is what you're looking for.
We know that: .
. . . .And that: .
Consider the Fibonacci sequence:
The ratios of consecutive Fibonacci numbers approaches
I'm currently trying to write an equation or piece of logic which will allow me to test ratios against the Golden Ratio to find the closest match. The ratios I need to test range from 1:255 to 255:1 (to several decimal places) and I want to convert these ratios into a decimal (z) between 0 & 1, such that 0 is a perfect match (1:1.618) and 1 is a the furthest possible (255:1). All the z values should be positive, such that a ratio of 10:1 will return a result similar to 1:11.
The application of this is in testing whether the brightness of two parts of an image conform to the Golden Ratio. In practice most of the ratios will be much closer, say between 5:1 and 1:5, so it might suit a log(10) solution?
So, where x = left side of ratio and y = right side, how do I define z as this number between 0 & 1?
This is keeping me up at night!
Also mods, please move this thread if I'm in the wrong place. ***Have reposted this in Calculus Forum***
What I'm looking for is a difference generator to tell me the difference between ratios: so between 1:1.618033989 and any given ratio. However I want it to make sense in the context of brightness, such that 5 times darker and 5 times brighter give the same result, e.g. if 1:1 was the perfect ratio, 1:5 and 5:1 would generate the same difference value. The complication is that I'm looking to test images with a perfect result being that (avg. brightness of area 1) = 1.618x brighter than (avg. brightness of area 2). The equation needs to show how close or far from the Golden Ratio any given ratio is.
As far I as understand, you need a function f(x), where x is a ratio that needs to be compared with the golden ratio φ, such that:
(1) f(x) is defined for 1/255 ≤ x ≤ 255,
(2) 0 ≤ f(x) ≤ 1,
(3) f(φ) = 0, and
(4) f(aφ) = f((1/a)φ).
Property (4) means that ratios, say, twice φ and half φ produce the same score. Since you are saying that most often (1/5)φ ≤ x ≤ 5φ, I assume it is also desirable to have
(5) f((1/5)φ) = f(5φ) is close to 1.
Otherwise, if, say, f(5φ) = 0.25, then most often you will work with scores that are between 0 and 0.25, while 3/4 of the scale are left mostly unused.
For starters, we can consider f(x) of the form g(x/φ) for some function g since working with 1 is easier than with φ. Then (1)–(5) become
(1') g(x) is defined for 1/(255φ) ≤ x ≤ 255/φ,
(2') 0 ≤ g(x) ≤ 1,
(3') g(1) = 0,
(4') g(1/x) = g(x), and
(5') g(1/5) = g(5) ≈ 1.
Using logarithm (together with absolute value) is not a bad idea because |log(x)| satisfies (3') and (4'). We could define g(x) = |log(x)|/log(255φ) using logarithm to some base. This g(x) satisfies (1')–(4') (though g(1/(255φ)) = 1, but g(255/φ) ≈ 0.84). Unfortunately, log(5)/log(255φ) < log(5)/log(125) = log(5)/log(53) = log(5)/(3log(5)) = 1/3 regardless of the base, so (5') does not hold. Also, computing logarithm can be computationally expensive if it is done for every pixel in a region.
We could manufacture a rational function instead. For example, let h(x) = x if x ≥ 1 and h(x) = 1/x otherwise, and let k(x) = (x - 1)/x = 1 - 1/x. Then let g(x) = k(h(x)). I suggest checking whether g(x) satisfies (1')–(5').
It seems to me that the simplest way to "compare" a ratio to the golden ratio is to divide the number by the golden ratio. The close to 1 that number is, the closer your ratio is to the golden ratio. For example, if one of your ratios is 8/5= 1.6 then dividing by gives 0.9889. If another is 41/25= 1.64 then dividing but gives 1.0136. The first is 1- 0.9889= 0.0111 from 1 while the second is 1.0136- 1= .0136 from 1. The first is closer to 1 so 8/5 is closer to the golden ratio than 41/25.
Wow thanks emakarov, you seem to have understood very well what I'm trying to do and thanks for writing out properly the conditions I was explaining. I'm glad it wasn't missing an easy answer...
Regarding computing logarithms - I won't be testing every pixel but rather averaged brightness of areas, so we would be talking about 15,000 calcs per second at 15fps rather than millions. The code I'm using (Processing language) seems able to cope with that kind of work.
My hunch is that in order to satisfy (4) a rational function is probably needed. I'll take a look at your suggestion and see g(x) is feasible.
Anyone else who fancies a go at this now emakarov has set out the problem nicely is very welcome to try!
Hi HallsofIvy, I'm not sure that will always give me the 'difference' between a given ratio and 1:φ?
I want to apply this to a brightness test such that
Twice as bright = 1:2φ = half as bright = 1:φ/2
and so on,
1:x(φ) = 1:φ/x
For my purposes, ratios range between 1:255 and 255:1 and the output number needs to be a value between 0 and 1, so:
Best = 0 = 1:1.618
Worst = 1 = 255:1
I think what you're saying though is similar to emakarov's g(x/φ) idea, so possibly that is the way to go.
Then again HallsofIvy, looking at your credentials I wonder if the answer to this is actually really that simple and I'm making it more complicated than it is...
OK guys I think I have something...
x = left side of ratio
y = right side of ratio
r = solution (our factor of comparison)
First make the left side of the ratio = 1, so our ratio looks like
Then test if the left side (y/x) >= φ
r = (y/x)/φ
As in HallsofIvy's solution.
However, if no, and (y/x) < φ
We need the reciprocal, so
r = 10/10((y/x)/φ)
Then it's just a matter of converting r to fit my scale of 0-1. Is that correct? Can anyone confirm the logic here?