Programming Practice
In image processing, a bitmap is a type of file format to store digital images. The format of a bitmap file can be divided into two parts, file header and image information, as the following type declaration:
typedef struct {
// File header: 14 bytes.
// Image information:
40 bytes. |
Following the file header and image information is the color palette with the size of OffsetBits-InfoSize-14 bytes, and then the image pixel data with the size of ImageSize bytes. The color palette and image pixel data can be declared as pointers of usigned char. The images used in this programming practice does not use color palette, i.e., OffsetBits-InfoSize-14 is 0. The pixel data area is stored using the following format:
Image pixels are stored in the row-major order starting from the bottom-left corner. That is, pixels are stored from left to right and from bottom to top; the pixels in the last row are stored on the front of the pixel data area.
Each pixel takes three bytes representing levels of the three original colors red, green, and blue (RGB) one byte each color. The order of the three bytes is blue color in the first byte, green in the second byte and red in the third byte.
The number of bytes in a row must be a multiple of four. If the number of actual pixel bytes is not a multiple of four, 0X00's are padded at the end of the row.
Write a C program to perform the following steps:
Read a color image bitmap file from disk.
Peform mirror reflection based on the central vertical line of the image. That is, exchange two pixels if they are left-right symmetric along the central vertical line of the image. For example, the two pixels on the top-left corner and the top-right corner are exchanged.
Write the image bitmap file after the vertical mirror reflection transformation to disk.
Output the resulting file header and the image information head on the screen.
Refer to Section 1.3.2 in The C Library Reference Guide for the function main: int main(int argc, char *argv[]) {body ...}. The default file name of the vertical mirror reflection image is "vertical_mirror_reflection.bmp". You may use example color image files blue_hills.bmp, water_lilies.bmp, abraham_lake.bmp, red_dragon.bmp, and wildflowers.bmp to test the program. If you use a color image other than the bit map format, such as png, gif, or jpg format, you may use a graphics tool to convert it to a bmp format file.
Program execution example:
A color image example:
The transformed banded-filter image: