Computer Programming

IIT Bombay Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session: Histo...
Author: Darleen Wheeler
6 downloads 0 Views 735KB Size
IIT Bombay

Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering IIT Bombay Session: Histogram Equalization Program

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

1

Quick Recap IIT Bombay

• We discussed the concept of associative arrays, and saw how it could be used to efficiently calculate a histogram

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

2

Overview IIT Bombay

• We will use the formulae for histogram equalization, and write a program to improve image contrast [Note: The histogram equalization technique described here, and the digital images used are directly based on a wikipedia article: http://en.wikipedia.org/wiki/Histogram_equalization]

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

3

Original and contrast-enhanced pictures IIT Bombay

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

4

Pixel values for the image IIT Bombay

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

5

Histogram values (shown for non-zero pixels) IIT Bombay

Val 52 55 58 59 60 61 62 63

n 1 3 2 3 1 4 1 2

Val 64 65 66 67 68 69 70 71

n Val n 2 72 1 3 73 2 2 75 1 1 76 1 5 77 1 3 78 1 4 79 2 2 83 1

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

Val n 85 2 87 1 88 1 90 1 94 1 104 2 106 1 109 1

Val 113 122 126 144 154

n 1 1 1 1 1

6

Histogram Equalization IIT Bombay

• The equalization formula to calculate new value for any existing pixel value v

• “Equalization” formula for example image • L = 256, M = N = 8, minimum cdf is 1

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

7

Program: enhance_contrast.cpp IIT Bombay

/* Program: enhance_contrast.cpp A program which reads the pixel intensities for a grayscale image, calculates the histogram and the cumulative distribution function, and finally recalculates the pixel values, such that the histogram is equalized. This procedure gives us an image with better contrast. Procedure and formula is based on the material given on wikipedia */

Dr. Deepak B. Phatak & Dr. Supratik Chakraborty, IIT Bombay

8

Program: enhance_contrast.cpp … IIT Bombay

#include #include using namespace std; int main(){ int i, j, min=0, M, N; int image[500][500], newimage[500][500]; int histogram[256], cdf[256], equalizer[256]; // Read Image data cout > N; cout