title: Squeeze/spread histogram to set its percentiles values
body: <p>I want to equalize an image by setting its channels(RGB) histogram percentile values to: 
  <br>25P - 63.75
  <br>50P(median) - 127.5 
  <br>75P - 191.25</p>
  
  <p>The idea is to first shift all the histogram so the median will be set on 127.5 and then spread/squeeze the histogram so the 25/75 percentiles will be set while maintaining the histogram shape as much as possible.</p>
  
  <p>I tried to implement this, and while I do get the percentiles values I wanted - the shape  of the histogram changes drastically and always looks like 3 Gaussian distribution(see in the image).</p>
  
  <pre><code>UPPER_BOUND = 255.0
  LOWER_BOUND = 0.0
  MEDIAN = UPPER_BOUND/2
  P25 = UPPER_BOUND/4
  P75 = 3*P25
  
  def range_transfer(channel, old_min, old_max, new_min, new_max):
     new_channel = channel.copy()
     old_range = (old_max - old_min)
     if old_range == 0:
        if new_max == P25:
            new_channel[:] = new_max
        else:
            new_channel[:] = new_min
     else:
        new_range = (new_max - new_min)
        new_channel = (((channel - old_min) * new_range) / old_range) + new_min
     return new_channel
  
  def equalize_channel(channel):
     ch_med = np.median(channel)
     shift_med = MEDIAN - ch_med
     new_channel = channel + shift_med
  
     ch_p25 = np.percentile(new_channel,25)
     ch_p75 = np.percentile(new_channel,75)
     new_channel[new_channel &lt;= ch_p25] = range_transfer(new_channel, np.min(new_channel), ch_p25, 
                                          LOWER_BOUND, P25)[new_channel &lt;= ch_p25]
     new_channel[new_channel &gt;= ch_p75] = range_transfer(new_channel, ch_p75, np.max(new_channel), P75, 
                                          UPPER_BOUND)[new_channel &gt;= ch_p75]
     return new_channel
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SzhDa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SzhDa.png" alt="enter image description here"></a></p>
  
  <p>Can you please help me with this?</p>