Reputation: 27
I want to write code that does image filtering. I use simple 3x3 kernel and then use scipy.ndimage.filters.convolve()
function. After filtering, range of the values is -1.27 to 1.12. How to normalize data after filtering? Do I need to crop values (values less then zero set to zero, and greater than 1 set to 1), or use linear normalization? Is it OK if values after filtering are greater than range [0,1]?
Upvotes: 0
Views: 762
Reputation: 10771
>>> import numpy as np
>>> x = np.random.randn(10)
>>> x
array([-0.15827641, -0.90237627, 0.74738448, 0.80802178, 0.48720684,
0.56213483, -0.34239788, 1.75621007, 0.63168393, 0.99192999])
You could clip out values outside your range although you would lose that information:
>>> np.clip(x,0,1)
array([ 0. , 0. , 0.74738448, 0.80802178, 0.48720684,
0.56213483, 0. , 1. , 0.63168393, 0.99192999])
To preserve the scaling, you can linearly renormalise into the range 0 to 1:
>>> (x - np.min(x))/(np.max(x) - np.min(x))
array([ 0.27988553, 0. , 0.6205406 , 0.64334869, 0.52267744,
0.55086084, 0.21063013, 1. , 0.57702102, 0.71252388])
Is it OK if values after filtering are greater than range [0,1]?
This is really dependant on your use case for the filtered image.
Upvotes: 1