0

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]?

1
  • It depends on your purposes. I assume that your convolution includes negative coefficients. In that case, it is quite common to clamp the output range to match the min/max viewable values -- but you do lose information when you do that. Commented Aug 12, 2016 at 1:33

1 Answer 1

1
>>> 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.