Table of Contents for
Intermediate C Programming

Version ebook / Retour

Cover image for bash Cookbook, 2nd Edition Intermediate C Programming by Yung-Hsiang Lu Published by CRC Press, 2015
  1. Front Cover
  2. Contents (1/2)
  3. Contents (2/2)
  4. List of Figures (1/2)
  5. List of Figures (2/2)
  6. List of Tables
  7. Foreword
  8. Preface
  9. Author, Reviewers, and Artist
  10. Rules in Software Development
  11. Source Code
  12. I. Computer Storage: Memory and File
  13. 1. Program Execution (1/2)
  14. 1. Program Execution (2/2)
  15. 2. Stack Memory (1/5)
  16. 2. Stack Memory (2/5)
  17. 2. Stack Memory (3/5)
  18. 2. Stack Memory (4/5)
  19. 2. Stack Memory (5/5)
  20. 3. Prevent, Detect, and Remove Bugs (1/2)
  21. 3. Prevent, Detect, and Remove Bugs (2/2)
  22. 4. Pointers (1/6)
  23. 4. Pointers (2/6)
  24. 4. Pointers (3/6)
  25. 4. Pointers (4/6)
  26. 4. Pointers (5/6)
  27. 4. Pointers (6/6)
  28. 5. Writing and Testing Programs (1/4)
  29. 5. Writing and Testing Programs (2/4)
  30. 5. Writing and Testing Programs (3/4)
  31. 5. Writing and Testing Programs (4/4)
  32. 6. Strings (1/3)
  33. 6. Strings (2/3)
  34. 6. Strings (3/3)
  35. 7. Programming Problems and Debugging (1/4)
  36. 7. Programming Problems and Debugging (2/4)
  37. 7. Programming Problems and Debugging (3/4)
  38. 7. Programming Problems and Debugging (4/4)
  39. 8. Heap Memory (1/3)
  40. 8. Heap Memory (2/3)
  41. 8. Heap Memory (3/3)
  42. 9. Programming Problems Using Heap Memory (1/4)
  43. 9. Programming Problems Using Heap Memory (2/4)
  44. 9. Programming Problems Using Heap Memory (3/4)
  45. 9. Programming Problems Using Heap Memory (4/4)
  46. 10. Reading and Writing Files (1/3)
  47. 10. Reading and Writing Files (2/3)
  48. 10. Reading and Writing Files (3/3)
  49. 11. Programming Problems Using File (1/2)
  50. 11. Programming Problems Using File (2/2)
  51. II. Recursion
  52. 12. Recursion (1/4)
  53. 12. Recursion (2/4)
  54. 12. Recursion (3/4)
  55. 12. Recursion (4/4)
  56. 13. Recursive C Functions (1/4)
  57. 13. Recursive C Functions (2/4)
  58. 13. Recursive C Functions (3/4)
  59. 13. Recursive C Functions (4/4)
  60. 14. Integer Partition (1/5)
  61. 14. Integer Partition (2/5)
  62. 14. Integer Partition (3/5)
  63. 14. Integer Partition (4/5)
  64. 14. Integer Partition (5/5)
  65. 15. Programming Problems Using Recursion (1/5)
  66. 15. Programming Problems Using Recursion (2/5)
  67. 15. Programming Problems Using Recursion (3/5)
  68. 15. Programming Problems Using Recursion (4/5)
  69. 15. Programming Problems Using Recursion (5/5)
  70. III. Structure
  71. 16. Programmer-Defined Data Types (1/6)
  72. 16. Programmer-Defined Data Types (2/6)
  73. 16. Programmer-Defined Data Types (3/6)
  74. 16. Programmer-Defined Data Types (4/6)
  75. 16. Programmer-Defined Data Types (5/6)
  76. 16. Programmer-Defined Data Types (6/6)
  77. 17. Programming Problems Using Structure (1/4)
  78. 17. Programming Problems Using Structure (2/4)
  79. 17. Programming Problems Using Structure (3/4)
  80. 17. Programming Problems Using Structure (4/4)
  81. 18. Linked Lists (1/3)
  82. 18. Linked Lists (2/3)
  83. 18. Linked Lists (3/3)
  84. 19. Programming Problems Using Linked List (1/2)
  85. 19. Programming Problems Using Linked List (2/2)
  86. 20. Binary Search Trees (1/4)
  87. 20. Binary Search Trees (2/4)
  88. 20. Binary Search Trees (3/4)
  89. 20. Binary Search Trees (4/4)
  90. 21. Parallel Programming Using Threads (1/5)
  91. 21. Parallel Programming Using Threads (2/5)
  92. 21. Parallel Programming Using Threads (3/5)
  93. 21. Parallel Programming Using Threads (4/5)
  94. 21. Parallel Programming Using Threads (5/5)
  95. IV. Applications
  96. 22. Finding the Exit of a Maze (1/5)
  97. 22. Finding the Exit of a Maze (2/5)
  98. 22. Finding the Exit of a Maze (3/5)
  99. 22. Finding the Exit of a Maze (4/5)
  100. 22. Finding the Exit of a Maze (5/5)
  101. 23. Image Processing (1/3)
  102. 23. Image Processing (2/3)
  103. 23. Image Processing (3/3)
  104. 24. Huffman Compression (1/10)
  105. 24. Huffman Compression (2/10)
  106. 24. Huffman Compression (3/10)
  107. 24. Huffman Compression (4/10)
  108. 24. Huffman Compression (5/10)
  109. 24. Huffman Compression (6/10)
  110. 24. Huffman Compression (7/10)
  111. 24. Huffman Compression (8/10)
  112. 24. Huffman Compression (9/10)
  113. 24. Huffman Compression (10/10)
  114. A. Linux
  115. B. Version Control
  116. C. Integrated Development Environments (IDE) (1/3)
  117. C. Integrated Development Environments (IDE) (2/3)
  118. C. Integrated Development Environments (IDE) (3/3)
Image Processing 391
}33
// detect edges and save the edges in the image34
pxl = 0;35
for ( row = 0; row < height ; row ++)36
{37
pxl += 3; // skip the first pixel in each row38
for ( col = 1; col < width ; col ++)39
{40
int diff = twoDGray [ row ][ col ] -41
twoDGray [ row ][ col - 1];42
// take the absolute value43
i f ( diff < 0)44
{45
diff = - diff ;46
}47
i f ( diff > thrshd ) // an edge48
{49
// set color to white50
img -> data [ pxl + 2] = 255;51
img -> data [ pxl + 1] = 255;52
img -> data [ pxl ] = 255;53
}54
e l s e // not an edge55
{56
// set color to black57
img -> data [ pxl + 2] = 0;58
img -> data [ pxl + 1] = 0;59
img -> data [ pxl ] = 0;60
}61
pxl += 3;62
}63
}64
for ( row = 0; row < height ; row ++)65
{66
free ( twoDGray [ row ]) ;67
}68
free ( twoDGray );69
}70
23.2.6 Color Equalization
Sometimes an image is over exposed (too bright) or under exposed (too dark). The image
can usually be enhanced by using color equalization using the following steps:
1. Find the maximum and the minimum values of the colors.
2. If the maximum and the minimum values are different, scale the maximum value to
255 and the minimum value to 0.
3. Scale the color based on a formula.
There are many ways to scale the pixel’s colors. One simple method is called linear
scaling: using a linear equation to express the relationship between the original color and
392 Intermediate C Programming
the new color. Let x and y be the old and the new colors, then a linear equation has two
coefficients: a and b.
y = ax + b (23.1)
Suppose M and m are the original minimum and the maximum values. They should
become 0 and 255 after the scaling. The following two equations are used to determine the
correct values for a and b.
0 = am + b
255 = aM + b
(23.2)
a =
255
M m
and b =
255m
M m
(23.3)
The code listing below implements this color equalization scheme.
// bm p equalize . c1
#in clude " bmpfunc . h"2
void BMP_eq ualize ( B MP_Image * img )3
{4
int pxl ;5
unsigned char redmin = 255;6
unsigned char redmax = 0;7
unsigned char greenmin = 255;8
unsigned char greenmax = 0;9
unsigned char bluemin = 255;10
unsigned char bluemax = 0;11
// find the maximum and the minimum values of each color12
for ( pxl = 0; pxl < ( img -> data_ size ) ; pxl += 3)13
{14
unsigned char red = img -> data [ pxl + 2];15
unsigned char green = img -> data [ pxl + 1];16
unsigned char blue = img -> data [ pxl ];17
i f ( redmin > red ) { redmin = red ; }18
i f ( redmax < red ) { redmax = red ; }19
i f ( greenmi n > green ) { greenmin = green ; }20
i f ( greenma x < green ) { greenmax = green ; }21
i f ( bluemin > blue ) { bluemin = blue ; }22
i f ( bluemax < blue ) { bluemax = blue ; }23
}24
// calc ulate the scaling factors25
// max and min must be d ifferent to prevent26
// divided by zero error27
double r edscale = 1.0;28
double greensca l e = 1.0;29
double bluescale = 1.0;30
i f ( redmax > redmin )31
{32
redscale = 255.0 / ( redmax - redmin ) ;33
}34
i f ( greenma x > green m in )35
{36
Image Processing 393
greensc a le = 255.0 / ( greenmax - green m i n );37
}38
i f ( bluemax > bluemin )39
{40
bluescale = 255.0 / ( bluemax - bluemin );41
}42
43
// equaliz e the pixels44
for ( pxl = 0; pxl < ( img -> data_ size ) ; pxl += 3)45
{46
i f ( redmax > redmin )47
{48
img -> data [ pxl + 2] = ( in t ) ( redscale *49
( img -> data [ pxl + 2] - redmin ) );50
}51
i f ( greenma x > green m in )52
{53
img -> data [ pxl + 1] = ( in t ) ( greens cale *54
( img -> data [ pxl + 1] - greenm i n ) );55
}56
i f ( bluemax > bluemin )57
{58
img -> data [ pxl ] = ( i n t ) ( bluesca le *59
( img -> data [ pxl ] - bluemin )) ;60
}61
}62
}63
This chapter gives a starting point for image processing. Image processing is a rich
subject and there are many books on the topic and related topics.
This page intentionally left blankThis page intentionally left blank