CSE1PES - Image Manipulation Assignment in C - La Trobe University

Verified

Added on  2023/03/30

|4
|343
|265
Homework Assignment
AI Summary
This assignment solution provides a C implementation for RGB image manipulation, following the guidelines of a La Trobe University assignment (CSE1PES). The code includes functions for loading, saving, and modifying images, such as changing luminosity, removing color channels, inverting colors, quantizing, flipping horizontally, and cropping. The solution begins with the provided starting code and implements each function step-by-step as outlined in the assignment instructions, including dynamic memory allocation and file operations. The main function presents a menu-driven interface, allowing the user to select various image processing options. Desklib provides a wealth of similar assignments and study resources for students.
Document Page
For this Application I followed the step-by-step guide that was provided.
Each function is as defined in the pdfs that were provided on LMS
The Imports required were;
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
To start with, I copy pasted the starting section of the program as outlined in the assignment
instructions, as follows;
ALL THIS THIS SECTION I DID NOT CHANGE ANYTHING AS IT WAS GIVEN THE WAY IT IS
#define MAX_FILE_NAME_SIZE 100 // this defines the maxim
struct Pixel
{
unsigned char red;
unsigned char green;
unsigned char blue;
};
struct RGB_Image
{
char file_name[MAX_FILE_NAME_SIZE];
long height;
long width;
long size;
struct Pixel** pixels;
};
//FILE FUNCTIONS AND DYNAMIC MEMORY ALLOCATION
int load_image(struct RGB_Image* image);
int save_image(struct RGB_Image image);
//FREE FUNCTION
void free_RGB_pixels(struct RGB_Image image);
//REALLOC FUNCTION
void re_allocate_pixels(struct RGB_Image image, int new_height, int
new_width);
//IMAGE FUNCTIONS
void save_copy_image();
void remove_channel_image();
void invert_image();
void quantize_image();
void flip_horizontal_image();
tabler-icon-diamond-filled.svg

Paraphrase This Document

Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
Document Page
void flip_horizontal_image();
void change_luminosity_image();
void print_information_image();
void crop_image();
//PIXEL FUNCTIONS
void invert_pixels(struct Pixel** pixels, int height, int width);
void flip_horizontal_pixels(struct Pixel** pixels, int height, int width);
void quantize_pixels(struct Pixel** pixels, int height, int width, int
quantization_level);
void remove_red_pixels(struct Pixel** pixels, int height, int width);
void remove_green_pixels(struct Pixel** pixels, int height, int width);
void remove_blue_pixels(struct Pixel** pixels, int height, int width);
void change_luminosity_pixels(struct Pixel** pixels, int height, int width,
int lum_level);
//END OF COPY PAST SECTION
1.0 Main Function
For the main function, I used an infinite loop to always display the console interface. I used a while
loop : and an IF ELSE Structure to select the options.
while(1 > 0){
printf("\n\n IMAGE MENU \n\n");
printf(" 0. Print Image Information\n");
printf(" 1. Save Copy of Image\n");
printf(" 2. Change Luminosity\n");
printf(" 3. Remove Image Channel\n");
printf(" 4. Invert Image Clours\n");
printf(" 5. Quantize Image\n");
printf(" 6. Flip Image Horizntally\n");
printf(" 7. Crop Image\n");
printf(" -1. Quit\n");
printf("\nChoice>> : ");
Document Page
2. Main Method
int load_image(struct RGB_Image* image_pointer)
Here I requested the user to enter name of the file; I then followed step by step guide given
Document Page
FOR EVERY OTHER FUNCTION, I FOLLOWED THE GUIDE FOR EACH FUNCTION
chevron_up_icon
1 out of 4
circle_padding
hide_on_mobile
zoom_out_icon
[object Object]