Blogs/Negative Transformation

# Negative Transformation

mesakarghm Sep 16 2021 1 min read 42 views
Computer Vision

Image Enhancement is the process of escalating the details of an image. We can use image enhancement techniques to improve the quality and the amount of information generated by our image. We can use various gray level transformations such as Linear transformations, Logarithmic transformations, or Power-law transformations.

Negative Transformation is a form of linear transformation which inverts the pixel values i.e. white pixels are converted to black pixels and black pixels are converted to white pixels. Negative Transformation of an image is used to enhance the white or gray detail embedded in dar regions of an image. The negative of an image is given by the expression

$$S = L - 1 - r$$

where L is the maximum pixel intensity possible in the color space, r is the current pixel value and S is the new pixel value.

Learn and practice this concept here:

https://mlpro.io/problems/negative-transformation/

def img_negative(img):
#converting to numpy array
pixels = np.asarray(img)
#Performing negative transformation s = L - 1 - r
#For grayscale image, L =   255
pixels = 255 - pixels
#making sure that the shape of the output image is same as that of input image
assert img.shape == pixels.shape
## making sure that the data type of output image is integer
pixels = pixels.astype('int32')
return pixels