Image normalization

I applied some operations on the grayscale image and now I get new values, but the problem in the intensity values ​​is now less than 0, from 0 to 255 and above 255. For values ​​between [ 0-255

] there is no problem, but for intensity values ​​<0 and intensity values > 255 is a problem because these values ​​cannot appear in a grayscale image.

So I need to normalize the values ​​so that all values, no matter if they are negative or greater than 255 or any other values, are in the range 0 to 255 for the image to be displayed.

I know two methods for this:

Method # 1

newImg = ((255-0)/(max(img(:))-min(img(:))))*(img-min(img(:)))

      

where min(img(:))

and max(img(:))

are the minimum and maximum values ​​obtained after performing some operations with the input image img

. min

may be less than 0, or max

may be greater than 255.

Method # 2

I just make all values ​​less than 0 equal to 0 and all values ​​greater than 255 equal to 255, so:

img(img < 0) = 0;
img(img > 255) = 255;

      

I have tried both methods, but get good results using the second method, but not the first. Can any of you tell me what the problem is?

+3


source to share


1 answer


It totally depends on the content of the image itself. Both of these methods are valid to ensure that the range of values ​​is between [0,255]

. However, before you decide which method you are using, you need to ask yourself the following questions:

Question # 1 - What is my image?

The first question you need to ask is what does your image represent? If it is, for example, the output of an edge detector, the method you choose will depend on the dynamic range of values ​​observed as a result (for more details in question # 2). For example, it is preferable to use the second method if there is good pixel distribution and low variance. However, if the dynamic range is slightly less, then you will want to use the first method to increase the contrast of your result.

If the output is image subtraction, then the first method is preferred because you want to visualize the exact differences between pixels. Truncating the result will not give you a good visualization of the differences.

Question # 2 - What is the dynamic range of values?

Another thing you should consider is how wide the dynamic range of the minimum and maximum values ​​is. For example, if the minimum and maximum are not so far from the limits [0,255]

, then you can use the first or second method and you will not notice much difference. However, if your values ​​are within a small range that is within [0,255]

, then doing the first method will increase the contrast, while the second method will do nothing. If your goal is to also increase the contrast of your image, and if the intensities are within the acceptable range [0,255]

, you should do the first method.



However, if you have minimum and maximum values ​​that are quite far from the range [0,255]

, for example min=-50

and max=350

, then the first method will not perform very well: / strong> if the gray intensity has huge variance. What I mean by huge variance is that you will have values ​​that are in the high range, values ​​that are in the low range, and nothing else. If you changed the scale using the first method, that would mean that the minimum value would be pressed down to 0, the maximum value would decrease to 255, and the rest of the intensities would increase in between, so for those values ​​below they are scaled like that re renders as gray ...

Question # 3 - Do I have a clean or noisy image?

This is something that few people think about. Is your image very clean, or is there a couple of spurious noisy places? The first method is very bad when it comes to noisy pixels. If you only had a few pixel values ​​that are very important, but other pixels are in the range [0,255]

, this will cause all other pixels to be scaled appropriately and thus reduce the contrast of your image. You probably want to ignore the contribution made by these pixels, and therefore the second method is preferable.

Conclusion

Therefore, there is nothing wrong with any of the methods you talked about. You need to know what the image is , the dynamic range of values ​​that you see when you view the output, and whether it is a crisp or noisy image. You just need to make smart choices with these two factors in mind. So, in your case, the first result probably didn't work because you have very large negative values ​​and large positive values, and perhaps very few of those values. Doing truncation is probably best for your application.

+7


source







All Articles