Contrast stretching (basic gradation conversion function) to achieve the basic principles and Python

1. Basic principles

Contrast stretching is extended dynamic range of the gray scale image processing. To control the shape of the transform function is determined by two points in the gray levels. The following sample code is a contrast stretching function threshold processing, the threshold value is an average value.

2. Test results

FIG derived skimage

3. Code

. 1  DEF contrast_stretch (input_image):
 2      '' ' 
. 3      contrast stretching (This implementation thresholding, the threshold value is the mean)
 . 4      : param input_image: an input image
 . 5      : return: the image contrast stretching FIG
 . 6      ' '' 
. 7      input_image_cp = (input_image) np.copy # copy of the input image 
. 8  
. 9      pixels_value_mean = np.mean (input_image_cp) # average gray value of the input image 
10  
. 11      # Comparative tensile FIG. (Note: this order can not be reversed to achieve) 
12 is      input_image_cp [NP .Where (input_image_cp <= pixels_value_mean)] = 0
 13 is      input_image_cp [np.where (input_image_cp> pixels_value_mean)]. 1 =
 14  
15     output_image = input_image_cp
16 
17     return output_image

 

Guess you like

Origin www.cnblogs.com/iwuqing/p/11297259.html