2 of 2 Croceted a fwe tpyos :))

There is no perfect solution to the problem you face. You must make a choice and every choice has pros and cons. For example you can apply saturation thresholding. Or you can use normalization. Saturation threshold clipping is very simple to realize and provide excellent performance provided that intermediate processing stages will not magnify the intensities too much above 255 (or below 0). Otherwise, it will severely distort the image. Normalization guarantees a loss free output but may severely degrade the algorithm quality. Besides it requires you to know in advance the normalization scale, which may not be possible always.