1 / 37

Two-week ISTE workshop on Effective teaching/learning of computer programming

Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lectures 11, Matrices -examples Saturday 3 July 2010 [Several slides courtesy Anirudha Jathar and Wikipedia]. Two-week ISTE workshop on Effective teaching/learning of computer programming.

roscoe
Download Presentation

Two-week ISTE workshop on Effective teaching/learning of computer programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lectures 11, Matrices -examples Saturday 3 July 2010 [Several slides courtesy Anirudha Jathar and Wikipedia] Two-week ISTE workshop onEffective teaching/learning of computer programming

  2. Overview • A quiz • Handling images • Representation of digital images • Histogram • Contrast enhancement • Example program to calculate histogram of a small digital image

  3. A quiz Q. Currently, what activity do you propose to carry out within two weeks of the workshop conclusion, for the mandatory submission A. Design questions and answers for examinations B. Design quiz questions and answers C. Add lecture slides with examples D. Something different

  4. Digital images • Digital images are a collection of pixel values • These are arranged in an array (W x H) • Each pixel value can be represented by • 1 bit (m : mono colour, e.g. black and white) • 8 bits (g : gray scale 0 – black to 255 – white) • 24 bits (c: Red, Blue, Green, each one byte) • One can have 16 million colours! • Capacity of a human eye is limited to a small range from 200 to 2000 colours

  5. Digital images ... • While storing information about an image in a file, we mainly need values of Width, Height, the type of colours present, and values for each pixel • Images such as black and white fingerprints have small size (500 x 300) • For large images, compression is mandatory to keep the file size within limits • 12 M pixel camera can produce 36 M bytes image • Compression can be either lossy or lossless • Several file formats have evolved raw, png, bmp, tiff, giff, jpeg, xmp • Refer to wikipedia (Image_file_formats)

  6. Images and histograms • Pixel values of digital images can be read in a matrix for further processing • Each picture point (pixel) has an associated “tonal” value • For grayscale images, the value range is 0-255 • 0: Black, 255: White • Thus each element of such an image matrix would contain a value which can be of the type/size short int or char (1 byte) • Histogram indicates how many pixels in an image have the same value

  7. A sample image 8 pixel x 8 pixel

  8. Pixel values in the sample image

  9. Histogram values Val n Val n Val n Val n Val n 52 1 64 2 72 1 85 2 113 1 55 3 65 3 73 2 87 1 122 1 58 2 66 2 75 1 88 1 126 1 59 3 67 1 76 1 90 1 144 1 60 1 68 5 77 1 94 1 154 1 61 4 69 3 78 1 104 2 62 1 70 4 79 2 106 1 63 2 71 2 83 1 109 1

  10. Cumulative Distribution Function (cdf) V c V c V c V c V c 52 1 64 19 72 40 85 51 113 60 55 4 65 22 73 42 87 52 122 61 58 6 66 24 75 43 88 53 126 62 59 9 67 25 76 44 90 54 144 63 60 10 68 30 77 45 94 55 154 64 61 14 69 33 78 46 104 57 62 15 70 37 79 48 106 58 63 17 71 39 83 49 109 59

  11. Histogram equalization • The histogram equalization formula • “Equalization” formula for example image

  12. For example, the cdf of 78 is 46 Histogram equalization …

  13. Pixel values after histogram equalization

  14. Enhancement of Contrast

  15. Original Picture for comparison

  16. Another grayscale picture

  17. Histogram and cdf

  18. “Equalized” histogram and cdf

  19. Picture with enhanced contrast

  20. Original picture for comparison

  21. Program to calculate histogram #include<iostream> using namespace std; int main(){ int i, j, npix; int image[500][500], histogram[256]; /* we assume that the image data is contained in a text file "image.txt“ in a suitable format Also, we will use command line redirection to read data from this file */

  22. Histogram … cin >> npix; // number of pixels //read image pixel values in the matrix for(i=0; i< npix; i++){ for(j=0; j < npix; j++){ cin >> image[i][j]; cout << image[i][j] << " "; } cout << "\n"; }

  23. Histogram … // set histogram counts to zero // for(i=0 ; i< 256; i++) histogram[i] = 0; // Calculate histogram values for(i=0; i< npix; i++){ for (j = 0; j < npix; j++){ // based on the value of the pixel // increment the corresponding count // in the histogram array histogram[image[i][j]]++; } }

  24. Histogram … // print the histogram at non zero values cout << "Histogram at non zero values is:”; cout << "\n"; for (i=0; i<256; i++){ if (histogram[i] !=0) { cout << i << " " << histogram[i] << "\n"; } }

  25. Histogram … // find the maximum value in the histogram int imax, max = 0; for (i=0; i<256; i++){ if (histogram[i] > max) max = histogram[i]; } cout << "Maximum histogram value " << max cout << “ occurs at:” << "\n"; // Print the grey levels at which max value occurs for(i=0; i<256; i++){ if (histogram[i]== max) cout << i << " "; } return 0; }

  26. Image of a finger print

  27. THANK YOU

  28. Question, From GEC Thrisur • Can we return structure from the function ?

  29. Question, From PSG Coimbatore • Does C support function overloading ? Lecture 11 Examples of matrix manipulation

  30. Question, From PSG Coimbatore • Why is C, C++ generally use to design and develop an operating system ? Lecture 11 Examples of matrix manipulation

  31. Question, From NIT, Kurukshetra • What is the application of bit wise operators ? Lecture 11 Examples of matrix manipulation

  32. Question, From GEC Thrisur • What is the maximum dimension possible for a multi dimension array ? Lecture 11 Examples of matrix manipulation

  33. Question, From GEC Thrisur • Earlier Pascal was use to discuss programming methodology, later why its turn to C ? Lecture 11 Examples of matrix manipulation

  34. Question, From PSG Coimbatore • If C is not supporting function overloading mean how it is possible to use different number of scanf with different argument ? Lecture 11 Examples of matrix manipulation

  35. Question, From NIT Kurukshetra • When we declare float instruct and why scanning • value, It will display floating point abnormal • termination error? Lecture 11 Examples of matrix manipulation

  36. Question, From NIT Kurukshetra • Is cin and cout return any value? Lecture 11 Examples of matrix manipulation

  37. Question, From NIT Jalandhar • What are macros and why they are taking lesser time during compilation? Lecture 11 Examples of matrix manipulation

More Related