Results 1 to 5 of 5

Math Help - re-allocating a range of values for a program

  1. #1
    Newbie
    Joined
    Aug 2010
    Posts
    3

    Smile re-allocating a range of values for a program

    Please forgive me if this is the wrong forum. I am not quite sure under which heading this particular problem falls. Mods, please move it if it is not in the correct place. Thanks.

    OK, I wonder if some bright mathematician can help me with a PHP programming problem please?

    Let me explain. Greys in a black and white image are in the range 0-255. These are the only possible values. Each greyscale pixel has a value in this range.

    I have an image where the range is quite narrow (57-205) and I want to re-distribute it throughout the scale(0-255) in as even way as possible. I am writing a program to re-allocate these values and I would like help in working out a formula or formulas to achieve this.

    Can anyone work out a formula or a couple of formulas to allow me to re-distribute these values over the full range please. It does not matter if there are spaces without values, but I would like a nice relatively even spread if possible.

    Thank you so much for any super-duper mathematical solutions. As you can tell, I am not great at maths. :-)

    Thanks for your help.
    Paul
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Senior Member
    Joined
    Jul 2010
    From
    Vancouver
    Posts
    432
    Thanks
    16
    OK, I don't know if this is going to make much sense but here is my attempt!

    Let the small range be from "a" to "b". Let the big range be from "A" to "B". Then we want the ratios between the color values to remain the same. Here is what I tried. Let "x" be a point between "a" and "b", it will be one of the color values in the initial range. Then we map it to a point "y" in the big range in such a way that the distance from "x" to "a" relative to the whole range ("a" to "b") is the same as the distance from "A" to "y" relative the whole big range.

    Here is the mathematical way of saying it:

    \displaystyle \frac{x-a}{b-a} = \frac{y-A}{B-A}

    Solving for y, you get:

    \displaystyle y = (x-a)\frac{B-A}{b-a}+A

    Similarly, if you want to go the other way, you just use

    \displaystyle x = (y-A)\frac{b-a}{B-A}+a

    In your case you have a = 57, b = 205 and A = 0 and B = 255. Then you get

    \displaystyle y = (x-57)\frac{255}{148}
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Aug 2010
    Posts
    3
    Vlasev, This makes perfect sense.
    Thank you so much for spending the time and effort to sort this out for me.

    Thanks again.
    Paul
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Super Member

    Joined
    May 2006
    From
    Lexington, MA (USA)
    Posts
    11,678
    Thanks
    610
    Hello, ocpaul20!

    I got the same result as Vlasev . . .


    You have a range of numbers from 57 to 205.
    And you want to "spread" them to range from 0 to 255.


    So we have these two sets of numbers:

    . . \begin{array}{c||c|c|c|c|c}<br />
x & 57 & 58 & 59 & \hdots & 205 \\ \hline<br />
y & 0 & - & - & \hdots & 255\end{array}


    So we have a linear function which ranges from (57,0) to (205,255)

    . . The slope of this line is: . m \;=\;\frac{255-0}{205-57} \;=\;\frac{255}{148}

    . . The line passes through (57,0)

    Therefore, the equation of the line is: . y \;=\;\frac{255}{148}(x - 57)

    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Aug 2010
    Posts
    3
    soroban, thanks to you too.

    Program working well and calculating both ways. :-)
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 1
    Last Post: June 1st 2011, 01:47 AM
  2. Range of values
    Posted in the Trigonometry Forum
    Replies: 1
    Last Post: September 14th 2010, 03:28 AM
  3. Is there such a program for plugging in values?
    Posted in the Math Software Forum
    Replies: 2
    Last Post: May 2nd 2010, 05:46 AM
  4. Replies: 2
    Last Post: July 30th 2008, 10:36 PM
  5. range of values
    Posted in the Pre-Calculus Forum
    Replies: 3
    Last Post: December 5th 2007, 07:21 AM

Search Tags


/mathhelpforum @mathhelpforum