How to transform data to have a new mean and maximum value? I have data relative to image intensity, which range from 0 to 255. For some models I need to run, I must transform this intensity data to a different scale, which must have a certain mean (for example, 1.5) and a certain maximum (for this example, 2). I have found information on how to convert data to a scale based on a min and a max, and also to a scale which has a given mean and variance, but these don't apply to my case - I just want to specify the mean and the maximum, deriving other properties from the data distribution.
Any ideas?
Many thanks!
 A: Let the mean of your sample be $\bar{x}$ and the desired mean be $\bar{y}$. Also, $x_{(n)}$ is your sample maximum and $y_{(n)}$ is the desired maximum. Then, create a transformation of your data $y=ax + b$ such that $\bar{x}$ corresponds to $\bar{y}$ and $x_{(n)}$ corresponds to $y_{(n)}$:
$$\begin{align*}
  a &= \frac{y_{(n)}-\bar{y}}{x_{(n)}-\bar{x}} \quad \text{and} \\
  b&=\bar{y}-a\bar{x}.
\end{align*}$$
Note that this is just a line through the points $(\bar{x},\bar{y})$ and $(x_{(n)},y_{(n)})$. It requires that $x_{(n)} \neq \bar{x}$, essentially implying that $x$ must have positive variance.
Since this is a linear transformation, deriving properties of the distribution of $y$ using the distribution of $x$ (other than the mean and maximum) should be easy.
Hope that helps.
A: Transforming based on maximum/minimums is dangerous because outliers can drastically affect the scaling. For example, if you have an image mostly in the 10-50 range, with a couple of noisy points in the 250 range, you will be adjusting the image based on a questionable maximum, hurting the dynamic range. 
I think it would be safer to adjust your image based on mean/median and variance, and then cap the maximum (clipping). For example, you can set the variance so the vast majority of data points in your typical image would fall in the range you desire, and cap anything that goes above it.  
