Question: Practice using object - oriented programming in C + + by creating an Image class. The lab simulates basic image processing techniques used in data
Practice using objectoriented programming in C by creating an Image class. The lab simulates basic image processing techniques used in data augmentation, such as flipping, rotating, cropping, resizing, and inverting binary images.
Please finish the code below:
imageclass.cpp
#include "imageclass.h
#include
using namespace std;
void Image::setPixelint row, int col, int value
if row && row height && col && col width
pixelsrowcol value;
else
cerr "Error: Pixel coordinates out of bounds." endl;
TASK: implement constructor and destructor to initialize and clean up image data
Image::Imageint w int h : widthw heighth
if w MAXWIDTH h MAXHEIGHT
cerr "Error: Image dimensions exceed maximum allowed size." endl;
exit;
Initialize pixel data to white
write your code here
Image::~Image
Destructor
write your code here
Example: implement flip method to flip image horizontally or vertically
void Image::flipbool horizontal
if horizontal
for int i ; i height; i
for int j ; j width ; j
int temp pixelsij;
pixelsij pixelsiwidth j;
pixelsiwidth j temp;
else
for int i ; i height ; i
for int j ; j width; j
int temp pixelsij;
pixelsij pixelsheight ij;
pixelsheight ij temp;
Example: implement rotate method to rotate image by or degrees in clockwise direction
void Image::rotateint angle
if angle && angle && angle
cerr "Error: Only degrees are supported." endl;
return;
int rotatedMAXHEIGHTMAXWIDTH;
if angle
for int i ; i height; i
for int j ; j width; j
rotatedjheight i pixelsij;
int temp width;
width height;
height temp;
else if angle
for int i ; i height; i
for int j ; j width; j
rotatedheight iwidth j pixelsij;
else if angle
for int i ; i height; i
for int j ; j width; j
rotatedwidth ji pixelsij;
int temp width;
width height;
height temp;
Copy rotated data back to pixels
for int i ; i height; i
for int j ; j width; j
pixelsij rotatedij;
TASK: implement crop method to crop image to a specific area
void Image::cropint x int y int newWidth, int newHeight
if x newWidth width y newHeight height
cerr "Error: Crop dimensions are out of bounds." endl;
return;
write your code here
TASK: implement invert method to invert image becomes becomes
void Image::invert
write your code here
TASK: implement resize method to resize image by an integer scale factor
void Image::resizeint scale
if scale
cerr "Error: Scale factor must be a positive integer." endl;
return;
write your code here
Getter for width
int Image::getWidth const
return width;
Getter for height
int Image::getHeight const
return height;
display image data as ASCII art for testing purposes
void Image::display const
for int i ; i height; i
for int j ; j width; j
cout pixelsij : ;
cout endl;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
