# Changing the range of numbers...

• Jul 5th 2011, 11:49 AM
cp05
Changing the range of numbers...
I am trying to write a program that compares two images. That info is not too important.
What is important is, that once I ratio the images, I get values starting from decimal numbers (like .0001) to possibly very large numbers (like 10..20..30.....100) depending on what two images I am ratioing.
The problem is that I am working in GIMP, and image values go from 0 to 255. So anything tiny is getting set to 0.
Is there some sort of algorithm that will scale my ratio results to these 0-255 values? So lets say I have values between .0001 (lets say, make this value arbitrarily 'a') to 20 ('b'). How can I scale the .0001 to correspond to zero ('x'), the 20 to correspond to 255('y'), and anything in between to scale accordingly? So transform a->x, b->y for arbitrary values of a and b.
Thanks!
• Jul 5th 2011, 12:06 PM
emakarov
Re: Changing the range of numbers...
$\frac{x-a}{b-a}\cdot255$

One way to derive this formula is as follows. A linear function of $x$ has the form $ux+v$ for some constants $u, v$. Therefore, we form a system of equations

$ua+v=0$
$ub+v=255$

and solve it to find $u$ and $v$ in terms of $a$ and $b$.
• Jul 5th 2011, 01:29 PM
cp05
Re: Changing the range of numbers...
I apologize if I'm being really slow with this.

I found u and v:
u=-255/(a-b)
v=255a/(a-b)

How do you get http://latex.codecogs.com/png.latex?...a%7D%5Ccdot255?

Thanks!
• Jul 5th 2011, 01:59 PM
emakarov
Re: Changing the range of numbers...
$ux+v=\frac{-255}{a-b}x+\frac{255a}{a-b}=\frac{255}{b-a}x-\frac{255a}{b-a}=\frac{x-a}{b-a}\cdot255$
• Jul 6th 2011, 08:45 PM
CaptainBlack
Re: Changing the range of numbers...
Quote:

Originally Posted by cp05
I am trying to write a program that compares two images. That info is not too important.
What is important is, that once I ratio the images, I get values starting from decimal numbers (like .0001) to possibly very large numbers (like 10..20..30.....100) depending on what two images I am ratioing.
The problem is that I am working in GIMP, and image values go from 0 to 255. So anything tiny is getting set to 0.
Is there some sort of algorithm that will scale my ratio results to these 0-255 values? So lets say I have values between .0001 (lets say, make this value arbitrarily 'a') to 20 ('b'). How can I scale the .0001 to correspond to zero ('x'), the 20 to correspond to 255('y'), and anything in between to scale accordingly? So transform a->x, b->y for arbitrary values of a and b.
Thanks!

Try plotting the logs (base 10 is probably better than natural logs here) of the ratios (add a constant to make most of them all positive and truncate below to a minimum of 0)

CB