Table of Contents
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
- How to install Qt
- Clone the repo
git clone https://github.com/IlyasKadi/HSLA_Image_color_space.git
The HSL color system uses the Hue
, Saturation
and Luminance
of the color. From the Adobe Techinag Guide page an brief explanation of each attribute is given as follow:
Hue ( denoted h
) define the color itself, for example red in distinction to blue or yellow. The values of the hue axis run from
The Hue representation of basic colors.
Saturation (denoted as s
) indicates the degree to which the hue differs from a neutral gray. The values run from
The saturation field in the HSL space.
Luminance (denoted as l
) indicates the level of illumination.
The value values run as pecentenage
The saturation field in the HSL space.
The full HSL color space is a three-dimensional space, but it is not a cube. The area truncates toward the two ends of the luminance axis and is widest in the middle rangel. The ellipsoid reveals several properties of the HSL colro space:
Representation of the HSL color space.
the project contain a class called PNG
that implement basic images maniplation like:
-
Reading an image from the system.
-
Writing an image into the system.
-
Accessing pixels of this image.
Here is a glance for this class header:
class PNG{
PNG(); //default constructor
PNG(int, int): //constructor with width and height
~PNG(); //Destructor
bool readFromFile(string); //read from a file
bool writeToFile(string); //write content to a file
HSLAPixel getPixel(int x, int y); //get content for pixel x, y
};
Your goal is to write additional classes that inherit from this class and implement addtional functionalities.
UML class diagram for the additional Images classes.
Create a class named Image
that inherits from the PNG
class. This means that your class will inherits all the attributes and members from the PNG
class. Meaning that anything you can do with a PNG
you can do with an Image
.
.Header
class Image : public PNG
{
public:
using PNG::PNG;
Image(string filename);
void lighten(double amount=0.1);
void saturate(double amount);
void rotateColor(double angle);
};
lighten(double amount)
changes the luminance of each pixel by amount.
original | lighten |
---|---|
![]() |
![]() |
Effect of adding 0.2 light on the image.
.cpp
void Image::lighten(double amount)
{
for(unsigned i=0;i< width();i++)
{
for(unsigned j=0;j<height();j++)
{
HSLAPixel &p = getPixel(i,j);
p.l += amount;
p.l = (p.l>0) ? p.l:0;
p.l = (p.l<=1)? p.l:1;
}
}
}
saturate
changes the luminance by amount.
original | saturate |
---|---|
![]() |
![]() |
Effect of adding 0.2 light on the image.
.cpp
void Image::saturate(double amount)
{
for(unsigned i=0;i< width();i++)
{
for(unsigned j=0;j<height();j++)
{
HSLAPixel &p = getPixel(i,j);
p.s += amount;
p.s = (p.s>0) ? p.s:0;
p.s = (p.s<=1)? p.s:1;
}
}
}
rotateColor(double angle)
: add the value of angle to each pixel.
original | rotateColor |
---|---|
![]() |
![]() |
Effect of rotating the image by 90 degrees.
.cpp
void Image::rotateColor(double angle)
{
for(unsigned i=0;i< width();i++)
{
for(unsigned j=0;j<height();j++)
{
HSLAPixel &p = getPixel(i,j);
p.h += angle;
while (p.h>360)
p.h=p.h-360;
while (p.h<0)
p.h=p.h+360;
}
}
}
Now you should write a simple class Grayscale
that inherits from the Image
class. This is a simple class that eliminates all the colors and represents the image using only a grayscale
level.
original | Grayscale |
---|---|
![]() |
![]() |
Effect of reducing the saturation of each pixel.
.Header
class Grayscale : public Image
{
public:
using Image::Image;
using PNG::writeToFile;
Grayscale(string filename);
};
.cpp
Grayscale::Grayscale(string filename):Image(filename)
{
readFromFile(filename);
saturate(-1);
}
Create a class called Illini
that inherits from the Image
class. An Illini
image has only two colors that are defined as attributes.
We divided the hue cercle into the closest arc to the first color (in this case orange h=11), and the one close to the second color (in this case blue h=216)
original | Illini |
---|---|
![]() |
![]() |
Illini Image which only stores two color (in this case blue and orange).
.Header
class Illini : public Image
{
public:
using Image ::Image;
int color1 =11;
int color2 =216;
Illini(string filename,int color1=11,int color2=216);
};
.cpp
Illini::Illini(string filename,int col1,int col2):Image(filename)
{
this->color1=col1;
this->color2=col2;
readFromFile(filename);
for(unsigned x = 0; x < width() ; x++)
for(unsigned y = 0; y < height(); y++)
{
//reference on the pixel
HSLAPixel &P = getPixel(x, y);
//modifiy the element of P
int ma_hue=max(color1,color2);
int mi_hue=min(color1,color2);
int half_r_dist=(ma_hue-mi_hue)/2;
int half_l_dist=(360-ma_hue+mi_hue)/2+ma_hue;
P.h= (P.h>half_r_dist && P.h<=half_l_dist) ?ma_hue:mi_hue;
}
}
A Spotlight
image create a spotlight centered at a given point centerX, centerY
defined as attributes.
original | Spotlight |
---|---|
![]() |
![]() |
Illustration of the spotlight effect.
.Header
class Spotlight : public Image
{
public:
using Image::Image;
int centerX;
int centerY;
Spotlight(string filename, int centX, int centY);
void changeSpotPoint(int cX, int cY);
};
.cpp
Spotlight::Spotlight(string filename,int centX, int centY):Image(filename)
{
this->centerX=centX;
this->centerY=centY;
readFromFile(filename);
for(unsigned x = 0; x < width() ; x++)
for(unsigned y = 0; y < height(); y++)
{
double dist = sqrt(((x-centerX)*(x-centerX))+((y-centerY)*(y-centerY)));
//reference on the pixel
HSLAPixel &P = getPixel(x, y);
//modifiy the element of P
if(dist<160)
P.l=P.l*(1-dist*0.005);
else
P.l=0.2*P.l;
}
}
Spotlight | ChangeSpotPoint |
---|---|
![]() |
![]() |
After completing the all the tests, add a method
void changeSpotPoint(int centerX, int centerY)
That changes the position of the spotlight.
void Spotlight::changeSpotPoint(int cX, int cY)
{
for(unsigned x = 0; x < width() ; x++)
for(unsigned y = 0; y < height(); y++)
{
double O_dist = sqrt(((x-centerX)*(x-centerX))+((y-centerY)*(y-centerY)));
double N_dist = sqrt(((x-cX)*(x-cX))+((y-cY)*(y-cY)));
//reference on the pixel
HSLAPixel &P = getPixel(x, y);
//modifiy the element of P
if(O_dist>=160)
P.l=5*P.l;
else
P.l=P.l/(1-O_dist*0.005);
if(N_dist>=160)
P.l=0.2*P.l;
else
P.l=P.l*(1-N_dist*0.005);
}
}
Out Team - AIT EL KADI Ilyas - AZIZ Oussama
Project Link: https://github.com/IlyasKadi/HSLA_Image_color_space
Excellent Work!! One of the best reports I've read so far!