代写C代码 代做C程序 C辅导 C家教

远程写代码 Debug 讲解答疑 不是中介,本人直接写

微信: ittutor QQ: 14061936 Email: ittutor@qq.com

导航

Spring 2014
ECE 222 System Programming Concepts
1 of 4
Lab 6 – Arrays, Pointers, and Structures
Objectives
In this lab, each student is to write a program called prog6.c
that allows the user to process a bitmap image file with a transformation m
atrix. The student should gain
and understanding of:
Use of dynamic memory allocation Manipulation of two-dimensional arrays
Manipulation of structures Use of pointers to structures Format and manipulation of bitmap image files
Input
The program should receive as command line argument
s the name of the input file and
the output file, which must be different. The inpu
t file is to be a 24-bit color bitmap
image of the windows
.bmp
format.
A 24-bit color .bmp file has two parts to its heade
r describing the image file. The first
header has the following structure:
struct HEADER
{ unsigned short int Type; /* Magic identifier
*/
unsigned int Size; /* File size in byt
es */
unsigned short int Reserved1, Reserved2;
unsigned int Offset; /* Offset to data (
in B) */
} Header; /* -- 14 Bytes --
*/
The second part of the header has the following str
ucture:
struct INFOHEADER
{ unsigned int Size; /* Header size in b
ytes */
int Width, Height; /* Width / Height o
f image */
unsigned short int Planes; /* Number of colour
planes */
unsigned short int Bits; /* Bits per pixel
*/
unsigned int Compression; /* Compression type
*/
unsigned int ImageSize; /* Image size in by
tes */
int xResolution, yResolution;/* Pixels per meter
*/
unsigned int Colors; /* Number of colors
*/
unsigned int ImportantColors;/* Important colors
*/
} InfoHeader; /* -- 40 Bytes --
*/
Spring 2014
ECE 222 System Programming Concepts
2 of 4
The actual image information follows as groups of t
hree bytes representing the color of
each pixel in RGB format. The pixels are stored as
rows of columns just as a two
dimensional matrix is stored in C. RGB format spec
ifies the intensity of Red as the
first byte, Green as the second byte, and Blue as t
he third byte. For example, the
three bytes
0x00FF00
would represent Red = 0, Green = 255, and Blue = 0
which
would be Green. A group of
0x802080
would be Red = 128, Green = 32, and
Blue = 128 which is a purple. (White is
0xFFFFFF
and black is
0x000000
.)
You are to read in the pixel data of the image and
store it in a dynamically allocated
two-dimensional array of pixels where each pixel is
stored as the following structure:
struct PIXEL
{ unsigned char Red, Green, Blue;
};
Functionality
Your program is to use a second derivative filter a
s shown below which will serve as a
kind of “edge detector” for the image.
char Matrix[3][3] =
{ { 0, -1, 0 },
{ -1, 4, -1 },
{ 0, -1, 0 }
};
This matrix is to be used as a filter on each pixel
of the image to produce new pixels.
For example, consider an image that has the followi
ng data:
Col 0 Col 1 Col 2 Col 3 Col 4 ....
Row 0 (0,0,0) (0,2,0) (3,2,1) (1,0,0) (0,0,1)
Row 1 (0,0,0) (0,2,0) (1,2,3) (1,0,0) (0,0,1)
Row 2 (5,0,0) (0,4,0) (7,2,4)
(9,0,2)
(8,0,1)
Row 3 (0,3,0) (0,1,0) (8,2,5) (1,0,1) (9,0,1)
...
Spring 2014
ECE 222 System Programming Concepts
3 of 4
The
Row 2
-
Col 3
pixel
(9,0,2)
would be transformed by summing the product
of the overlayed filter at pixel
[2][3]
. That is, you would calculate the new value
for pixel
[2][3]
as the sum of
Matrix[0][0]
multiplied by
pixel[1][2]
and
Matrix[0][1]
multiplied by
pixel[1][3]
and
Matrix[0][2]
multiplied by
pixel[1][4]
and
Matrix[1][0]
multiplied by
pixel[2][2]
and
Matrix[1][1]
multiplied by
pixel [2][3]
, etc...
Col 0 Col 1 Col 2 Col 3 Col 4 ....
Row 0 (0,0,0) (0,2,0) (3,2,1) (1,0,0) (0,0,1)
Row 1 (0,0,0) (0,2,0)
(1,2,3) (1,0,0) (0,0,1)
Row 2 (5,0,0) (0,4,0)
(7,2,4)
(9,0,2)
(8,0,1)
Row 3 (0,3,0) (0,1,0)
(8,2,5) (1,0,1) (9,0,1)
The matrix factor is to be multiplied by each of th
e RGB components. So the new [2][3]
pixel would be:
[0
x
(1,2,3)
] + [(-1)
x
(1,0,0)
] + [0
x
(0,0,1)
] +
[(-1)
x
(7,2,4)
] + [(4)
x
(9,0,2)
] + [(-1)
x
(8,0,1)
] +
[0
x
(8,2,5)
] + [(-1)
x
(1,0,1)
] + [0
x
(9,0,1)
]
= (-1 -7 +
36
-8 -1, -2 +
0
, -4 +
8
-1 -1)
= (19, -2, 2)
Output
The program should write the header and then each n
ew pixel to the output file to
create a valid
.bmp
file.
Further Considerations
Your instructor will supply you with two test files
for input. When the edge detection is
properly applied, a message in the image will be re
vealed.
Work must be completed by each individual student.
If it is determined that a piece of
work has been copied, all parties involved will rec
eive zero credit, and a letter grade
may be deducted at the end of the semester.
 

相关推荐