Tag Archives: image negative

Image Negatives or inverting images using OpenCV

Image negatives, most of you might have heard this term, in good old days were used to produce images. Film Photography has not yet become obsolete as some wedding photographers are still shooting film. Because one has to pay for the film rolls and processing fees, most people have now switched to digital.

I recently heard of Foveon X3 direct image sensor which claims to combine the power of digital sensor with the essence of the film. (Check here)

Image negative is produced by subtracting each pixel from the maximum intensity value. e.g. for an 8-bit image, the max intensity value is 28– 1 = 255, thus each pixel is subtracted from 255 to produce the output image.

Thus, the transformation function used in image negative is

s = T(r) = L – 1 – r

Where L-1 is the max intensity value and s, and r are the output and input pixel values respectively.

For grayscale images, light areas appear dark and vice versa. For color images, colors are replaced by their complementary colors. Thus, red areas appear cyan, greens appear magenta, and blues appear yellow, and vice versa.

The output looks like this

Method 2

OpenCV provides a built-in function cv2.bitwise_not() that inverts every bit of an array. This takes as input the original image and outputs the inverted image. Below is the code for this.

There is a long debate going on whether black on white or white on black is better. To my knowledge, Image negative favors black on white thus it is suited for enhancing the white or gray information embedded in the dark regions of the image especially when the black areas are dominant in size.

Application: In grayscale images, when the background is black, the foreground gray levels are not clearly visible. So, converting background to white, the gray levels now become more visible.

In the next blog, we will discuss Log transformations in detail. Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.

Intensity Transformation

Intensity transformation as the name suggests, we transform the pixel intensity value using some transformation function or mathematical expression.

Intensity transformation operation is usually represented in the form

s = T(r)

where, r and s denotes the pixel value before and after processing and T is the transformation that maps pixel value r into s.

Basic types of transformation functions used for image enhancement are

  • Linear (Negative and Identity Transformation)
  • Logarithmic (log and inverse-log transformation)
  • Power law transformation

The below figure summarize these functions. Here, L denotes the intensity value (for 8-bit, L = [0,255])


source: R. C. GonzalezR. E. Woods, Digital Image Processing

This is a spatial domain technique which means that all the operations are done directly on the pixels. Also known as a point processing technique (output depend only on the single pixel) as opposed to neighborhood processing techniques(like filtering) which we will discuss later.

Applications:

  • To increase the contrast between certain intensity values or image regions.
  • For image thresholding or segmentation

In the next blog, we will discuss these different transformation functions in detail. Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.