联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codehelp

您当前位置:首页 >> Matlab程序Matlab程序

日期:2021-03-21 09:28

Project 1
Matrix operations: Part 1 (100pts)
Submission Procedure:
1. This project is due at 11:59:59pm on Thursday, March 25th, 2020. Every day late will
deduct 20 points.
2. You should work on your project through OnlineGDB and share your code as a Link.
Please make sure your link is valid and contains all of the files. You may also use your own IDE,
such as Visual Studio Code, and upload the files to Sakai and OnlineGDB.
3. Once you’re done, please save your Link in a PDF file named “Project 1.pdf”. Your PDF
should contain your name, RUID, and a single URL to OnlineGDB.
4. Submit your PDF file on Sakai assignment.
For this project, you will be completing 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 matrixes, 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.
There are multiple functions you will write in the assignment. These will be functions that
bridge the general image library with the RGB matrix view, as well as functions that use the
matrix view to generate new images. We will provide the initial code and necessary files to get
you started. The code designates parts of it with //YOUR CODE HERE, in order to indicate
where you should complete the code.
Code LINK:
https://rutgersconnect-my.sharepoint.com/:f:/g/personal/jo413_soe_rutgers_edu/Eovw3IQc02
pFrRoTa2htYp8Bkj77SSHg2mWXKiGbrZwCOA?e=PcubxD
Part 1: The code (25 points)
The code consists of a number of header files and the main file that you will be updating. The
four files are:
1. project1-main.c
2. stb_image.h
3. stb_image_write.h
4. Stb_image_resize.h
The code you will write will all be in project1-main.c. Notice, at the top of the file, we import all
the necessary files to run the code. These header files consist 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 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.
When you read an image as a command-line argument, the code loads the PNG images using
the library. Your job in this first task will be to implement init_rgb(). You should use
malloc() for dynamic memory allocation in order to initialize the r,g,b two-dimensional arrays.
Part 2: Scaling an image
In part 2, you will write the code to scale the pixel values of an image. The associated function
for this part of the project is imatrix* scale(imatrix* this, int width, int
height, float alpha). Please read the documentation for this function and complete
the code. You should test your code by calling it on an image in the main() function.
Part 3: Add, Subtract
Here complete the two add and subtraction functions, imatrix* subtract(imatrix*
m1, imatrix* m2, imatrix* add(imatrix* m1, imatrix* m2. These two
functions take two imatrix and add/subtract them from each other. The result is written to a file
and can be observed. To blend images together, try scaling them before adding or subtracting
them.
Part 4: Multiply
Finally, scaling and rotating an image can be done through matrix multiplication. Complete the
function for matrix multiply imatrix* multiply(imatrix* m1, imatrix* m2),
following the specification in the comments section above the function.

版权所有:留学生编程辅导网 2021,All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。