Skip to content
Snippets Groups Projects
Commit b226473d authored by Teo Blaise Kaplanski's avatar Teo Blaise Kaplanski
Browse files

fin

parent 2f81946c
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,6 @@
/MatrixGrayImage.class
/Transform.class
/Invert.class
/DecreaseGrayLevels.class
/pixelate.class
/Pixelate.class
......@@ -38,7 +38,7 @@ public class ByteGrayColor implements GrayColor {
@Override
public double getLuminosity() {
// TODO : Retourner la luminosité de la couleur (entre 0 noir et 1 blanc)
return 0;
return (double)this.grayLevel/MAXIMUM_GRAY_LEVEL;
}
@Override
......@@ -62,10 +62,15 @@ public class ByteGrayColor implements GrayColor {
return this.compareTo(color) == 0;
}
@Override
public GrayColor invert() {
// TODO Auto-generated method stub
return null;
}
@Override
public GrayColor invert() {
return new ByteGrayColor(MAXIMUM_GRAY_LEVEL - grayLevel);
}
public GrayColor decreaseGrayLevel(int nbGrayLevels){
return new ByteGrayColor((Math.floor(grayLevel/255.0 * (nbGrayLevels-1)) * MAXIMUM_GRAY_LEVEL / (nbGrayLevels-1)));
}
}
public class DecreaseGrayLevels implements Transform {
int nbGrayLevel;
DecreaseGrayLevels(int nbGrayLevel){
this.nbGrayLevel = nbGrayLevel;
}
@Override
public void applyTo(GrayImage image) {
for (int x = 0; x < image.getWidth(); ++x){
for(int y = 0; y < image.getHeight(); ++y){
image.setPixel(image.getPixelGrayColor(x, y).decreaseGrayLevel(nbGrayLevel), x, y);
}
}
}
}
......@@ -8,11 +8,8 @@ public interface GrayColor extends Comparable<GrayColor> {
int getGrayLevel();
double getLuminosity();
Color getColor();
// Add methode Invert()
public GrayColor invert() {
}
}
GrayColor invert();
GrayColor decreaseGrayLevel(int nbGrayLevels);
}
......@@ -5,4 +5,12 @@
public interface GrayImage extends Image {
void setPixel(GrayColor gray, int x, int y);
GrayColor getPixelGrayColor(int x, int y);
GrayColor getDominantGray(int squareX, int squareY, int squareSize);
default int dominantGray(int squareX, int squareY, int squareSize) {
int sumOfGrayLevels = 0;
for (int x = squareX; x < squareX+squareSize; ++x)
for (int y = squareY; y < squareY+squareSize; ++y)
sumOfGrayLevels += getPixelGrayColor(x, y).getGrayLevel();
return (sumOfGrayLevels / (squareSize*squareSize));
}
}
public class Invert implements Transform {
public void invert() {
}
public void applyTo(GrayImage image) {
}
}
@Override
public void applyTo(GrayImage image) {
for (int x = 0; x < image.getWidth(); ++x){
for(int y = 0; y < image.getHeight(); ++y){
image.setPixel(image.getPixelGrayColor(x, y).invert(), x, y);
}
}
}
}
\ No newline at end of file
......@@ -15,6 +15,14 @@ public class Main
MatrixGrayImage.createImageFromPGMFile("luminy.pgm");
// Add code here;
Invert invert = new Invert();
DecreaseGrayLevels decreaseGrayLevel = new DecreaseGrayLevels(5);
Pixelate pixelate = new Pixelate(10);
invert.applyTo(image);
pixelate.applyTo(image);
decreaseGrayLevel.applyTo(image);
display(image);
}
......
......@@ -17,49 +17,47 @@ public class MatrixGrayImage implements GrayImage {
@Override
public void setPixel(GrayColor gray, int x, int y) {
// TODO : Compléter la méthode pour modifier le pixel.
pixels[x][y] = gray;
pixels[x][y] = gray;
}
@Override
public GrayColor getPixelGrayColor(int x, int y) {
// TODO : Changer les instructions pour retourner le bon pixel.
int Gcolor = pixels[x][y].getGrayLevel();
return new ByteGrayColor(Gcolor);
return pixels[x][y];
}
@Override
public Color getPixelColor(int x, int y) {
// TODO : Changer les instructions pour retourner la couleur du pixel.
return pixels[x][y].getColor();
}
@Override
public int getWidth() {
// TODO : Changer les instructions pour retourner la largeur de l'image.
return this.width;
}
@Override
public int getHeight() {
// TODO : Changer les instructions pour retourner la hauteur de l'image.
return this.height;
}
public MatrixGrayImage(int width, int height){
/* TODO : Modifier les instructions pour initialiser correctement
les propriétés de l'instance.
*/
this.width = width;
this.height = height;
this.pixels = null;
this.pixels = new GrayColor[width][height];
}
public int getPixelByteColor(int x, int y) {
return (int)(getPixelGrayColor(x, y).getGrayLevel()*PGM_MAXIMUM_CODE);
}
@Override
public GrayColor getDominantGray(int squareX, int squareY, int squareSize) {
return new ByteGrayColor(dominantGray(squareX, squareY, squareSize));
}
public static MatrixGrayImage createImageFromPGMFile(String fileName) {
// NE PAS MODIFIER !
InputStream file = ClassLoader.getSystemResourceAsStream(fileName);
......
public class Pixelate implements Transform {
int newPixelSize;
int newSquareX;
int newSquareY;
GrayColor dominantColor;
Pixelate(int newPixelSize){
this.newPixelSize = newPixelSize;
}
@Override
public void applyTo(GrayImage image) {
for (int x = 0; x < (image.getWidth()) / newPixelSize; ++x) {
for (int y = 0; y < (image.getHeight()) / newPixelSize; ++y) {
newSquareX = x * newPixelSize;
newSquareY = y * newPixelSize;
dominantColor = image.getDominantGray(newSquareX, newSquareY, newPixelSize);
for (int squareX = 0; squareX < newPixelSize; ++squareX){
for (int squareY = 0; squareY < newPixelSize; ++squareY ){
int X = newSquareX + squareX;
int Y = newSquareY + squareY;
image.setPixel(dominantColor, X, Y);
}
}
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment