辅导C++编程、C++程序设计调试、辅导data编程
- 首页 >> Matlab编程 Project 2
Matrix operations: Part 1 (100pts)
Submission Procedure:
1. This project is due at 11:59:59pm on Monday, May 3rd, 2020. Every day late will deduct
20 points.
2. You may also use your own IDE, such as Visual Studio Code, and upload the files to Sakai.
3. Once you’re done, please save your Link in a PDF file named “Project 2.pdf”. Your PDF
should contain your name, RUID, and a single URL to OnlineGDB.
4. Also submit a PDF file on Sakai assignment. In that PDF file, please indicate if you are
taking the PM1 class only, lab only, or both. At the top of the PDF file, write your name, netID,
and one of these (PM1 class only, Lab only, Class + Lab).
For this project, you will be converting the code from project 1, into an object-oriented program
in C++. Recall, you completed an image processing library that can process images using matrix
operations. All images can be represented as a matrix of single-byte values, where a pixel at
matrix location (i, j) is represented by a number between 0 and 255. A color image consists of
three channels: a red channel (R), a green channel (G), and a blue channel (B), and the
corresponding matrix information for an image include three matrices, each with the same
number of rows (height) and columns (width), one for each of the three channels. Together,
these are passed to an image-writing library for outputting to a file and displaying.
In this assignment, you will create several classes that build up the library. Starting with
vector, creating a matrix as a collection of vectors, and an image as an extension of a matrix.
Code:
https://rutgersconnect-my.sharepoint.com/:f:/g/personal/jo413_soe_rutgers_edu/EjMsej7h7YB
MuHrWLEmTK90BTe0Q3Aqe3dqe0uPJUTQRjQ?e=RyNT5h
SETUP FROM PROJECT 1: The code consists of a number of header files and the main file that
you will be updating. The four files are: 1) project1.c, 2)stb_image.h, 3) stb_image_write.h, and
4) stb_image_resize.h
The code is entirely project1.c. Notice, at the top of the file, we import all the necessary files to
run the code. These header files consist of the necessary function definitions to open, write,
and manipulate a PNG file. For this project, we will be working ONLY with PNG files.
The main object that you will manipulate be translating is shown below:
// imatrix struct, wraps a byte array of pixel data for an image
typedef struct imatrix{
int width;
int height;
uint8_t** r;
uint8_t** g;
uint8_t** b;
struct imatrix* (*add)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*subtract)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*multiply)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*scale)(struct imatrix* this, int width, int height, float
alpha);
void (*write_image_to_rgb)(struct imatrix* this);
void (*write_rgb_to_image)(struct imatrix* m);
struct imatrix* (*set_rgb_image)(struct imatrix* this, uint8_t*
new_rgb_image, int width, int height, int channels);
//internal image reference
uint8_t* rgb_image;
} imatrix;
This structure consists of a number of fields. Three pointers r, g, b will be used to represent an
image as three separate matrices, one for each channel. The structure also consists of a pointer
rgb_image, which is a pointer to the image data written in a contiguous memory block.
PART 1: (35 points) Write a class called Vector as a templated class that stores a collection of
objects. This class should be able to store any kind of homogeneous data. Implement a
getsize() function to return the size of the vector (i.e. the number of elements in it). You may
choose to implement it with an array or as a linked list (your choice). You should implement:
1. int getsize()
2. the copy constructor
3. the assignment operator,
4. the destructor,
5. the input and output stream operators,
6. the +, -, and * operator,
7. and the subscript operator []
Implement any functions as virtual that you believe should be implemented as such.
Part 2: (35 points) Create a new class called Matrix that extends (inheritance) and/or uses
(composition) the Vector class to represent a matrix of doubles. This class should overwrite
all the operators in the Vector class (except getsize()). Add two more functions: getrows(),
getcols().
Part 3: (20 points) Create a new Image class that inherits from the Matrix class and implements
all the functions in Project 1. This class should be able to scale and image, add or subtract two
images, multiply two images. Scaling, adding, subtracting, and multiplying to should
implemented as overloaded operators (+, -, *).
Part 4: (10 points) Add a function called transpose() to the Matrix class. Write a main.cpp file
which tests your Image class with real images, executing all the operations that you
implemented in the previous parts of this project.
Matrix operations: Part 1 (100pts)
Submission Procedure:
1. This project is due at 11:59:59pm on Monday, May 3rd, 2020. Every day late will deduct
20 points.
2. You may also use your own IDE, such as Visual Studio Code, and upload the files to Sakai.
3. Once you’re done, please save your Link in a PDF file named “Project 2.pdf”. Your PDF
should contain your name, RUID, and a single URL to OnlineGDB.
4. Also submit a PDF file on Sakai assignment. In that PDF file, please indicate if you are
taking the PM1 class only, lab only, or both. At the top of the PDF file, write your name, netID,
and one of these (PM1 class only, Lab only, Class + Lab).
For this project, you will be converting the code from project 1, into an object-oriented program
in C++. Recall, you completed an image processing library that can process images using matrix
operations. All images can be represented as a matrix of single-byte values, where a pixel at
matrix location (i, j) is represented by a number between 0 and 255. A color image consists of
three channels: a red channel (R), a green channel (G), and a blue channel (B), and the
corresponding matrix information for an image include three matrices, each with the same
number of rows (height) and columns (width), one for each of the three channels. Together,
these are passed to an image-writing library for outputting to a file and displaying.
In this assignment, you will create several classes that build up the library. Starting with
vector, creating a matrix as a collection of vectors, and an image as an extension of a matrix.
Code:
https://rutgersconnect-my.sharepoint.com/:f:/g/personal/jo413_soe_rutgers_edu/EjMsej7h7YB
MuHrWLEmTK90BTe0Q3Aqe3dqe0uPJUTQRjQ?e=RyNT5h
SETUP FROM PROJECT 1: The code consists of a number of header files and the main file that
you will be updating. The four files are: 1) project1.c, 2)stb_image.h, 3) stb_image_write.h, and
4) stb_image_resize.h
The code is entirely project1.c. Notice, at the top of the file, we import all the necessary files to
run the code. These header files consist of the necessary function definitions to open, write,
and manipulate a PNG file. For this project, we will be working ONLY with PNG files.
The main object that you will manipulate be translating is shown below:
// imatrix struct, wraps a byte array of pixel data for an image
typedef struct imatrix{
int width;
int height;
uint8_t** r;
uint8_t** g;
uint8_t** b;
struct imatrix* (*add)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*subtract)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*multiply)(struct imatrix* this, struct imatrix* m2);
struct imatrix* (*scale)(struct imatrix* this, int width, int height, float
alpha);
void (*write_image_to_rgb)(struct imatrix* this);
void (*write_rgb_to_image)(struct imatrix* m);
struct imatrix* (*set_rgb_image)(struct imatrix* this, uint8_t*
new_rgb_image, int width, int height, int channels);
//internal image reference
uint8_t* rgb_image;
} imatrix;
This structure consists of a number of fields. Three pointers r, g, b will be used to represent an
image as three separate matrices, one for each channel. The structure also consists of a pointer
rgb_image, which is a pointer to the image data written in a contiguous memory block.
PART 1: (35 points) Write a class called Vector as a templated class that stores a collection of
objects. This class should be able to store any kind of homogeneous data. Implement a
getsize() function to return the size of the vector (i.e. the number of elements in it). You may
choose to implement it with an array or as a linked list (your choice). You should implement:
1. int getsize()
2. the copy constructor
3. the assignment operator,
4. the destructor,
5. the input and output stream operators,
6. the +, -, and * operator,
7. and the subscript operator []
Implement any functions as virtual that you believe should be implemented as such.
Part 2: (35 points) Create a new class called Matrix that extends (inheritance) and/or uses
(composition) the Vector class to represent a matrix of doubles. This class should overwrite
all the operators in the Vector class (except getsize()). Add two more functions: getrows(),
getcols().
Part 3: (20 points) Create a new Image class that inherits from the Matrix class and implements
all the functions in Project 1. This class should be able to scale and image, add or subtract two
images, multiply two images. Scaling, adding, subtracting, and multiplying to should
implemented as overloaded operators (+, -, *).
Part 4: (10 points) Add a function called transpose() to the Matrix class. Write a main.cpp file
which tests your Image class with real images, executing all the operations that you
implemented in the previous parts of this project.