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!

Re: Changing the range of numbers...

$\displaystyle \frac{x-a}{b-a}\cdot255$

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

$\displaystyle ua+v=0$

$\displaystyle ub+v=255$

and solve it to find $\displaystyle u$ and $\displaystyle v$ in terms of $\displaystyle a$ and $\displaystyle b$.

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!

Re: Changing the range of numbers...

$\displaystyle 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$

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