Convert a linear scale to a logarithmic scale

50.6k Views Asked by At

Given a number n, how would I convert this number into a logarithmic scale?

My logarithmic scale would range from 0 to 255 (I'm working with RGB colours), and I would expect values of n from 1 to 1,000,000.

Apologies if this is an easy question.

1

There are 1 best solutions below

6
On BEST ANSWER

let $f(n)$ be the log function of n.

So a general log function can be written as $f(n)=k\log n +c$

where $k$ and $c$ are constants

$\implies 255=k\log {10^6}+c$

and $0=k\log {1}+c$

here is to the base 10

so $c=0$ and $k=255/6$

or here you can use any base and different values of k

so that $f(n)=\frac {255 \log n}{6}$ if the base is 10.