I had some magical tasks to do on my lessons. I had to write an app which performs some operations: basic (adding, subtracting, multiplying a constant and a second image), geometric, filtering, histograms etc. There were ~50 tasks.

I've made them all, even with Prewitt filters and other down/upbandwith and gradient things.

Now, my teacher sent me an info, that I did my normalization wrong in basic operations, for example in adding a constant. 

As he wrote in his document there are 3 ways of handling the pixel overflow >255 or <0:

 - cutting the overflow - which means a simple clamp
 - scaling images before processing
 - ***normalization*** of the final image - scaling and moving the image function with a specified range that the final image fills the given range.

I've left first two and got the third one, because he said it's the correct way. I've read somewhere that I still need to combine it with a clamp (0,255).

Now, I got his formula:

$$\large f_{norm}=Z_{rep}[(f-f_{min})\div(f_{max}-f_{min})]$$

And  I thought it's easy to understand, but I have some problems with it.

As I understand:

 - $f_{norm}$ - final pixel (normalized)
 - $f$ - given pixel
 - $f_{min}$ - minimum
 - $f_{max}$ - extremum
 - $Z_{rep}$ - clamp 0-255?


*I have the following questions:*

1. Are $f_{min}$ and $f_{max}$ taken from the given image, or from the image after the operation (for ex. adding a constant)? I know what extremes are, but I can't figure it out which two should I use in this formula.

2. Is $Z_{rep}$ really a clamp method as I thought which just cuts to 0-255? I've read somewhere that even with normalization there can be an overflow.

3. Does normalization work like: no matter what value you'll add or subtract from the image, I'll make for you a beautiful 0-255 values? Or am I wrong?


I've even made some calculations, made some images in photoshop with extremes 30,200 and even 0,255, put them into the formula and got some results, but I still don't know if it's done well. 

I'm sitting here for 3 weeks, really and can't get which extremes should I use and if I should clamp or not.