Add Comments to DesaturateIt.java
This commit is contained in:
parent
8ce87145b8
commit
0d0e7140c4
Binary file not shown.
|
@ -12,19 +12,19 @@ public class DesaturateIt{
|
||||||
// - original, grayscale, sepia
|
// - original, grayscale, sepia
|
||||||
//Array Structure
|
//Array Structure
|
||||||
// [X][Y][COLOR]
|
// [X][Y][COLOR]
|
||||||
int[][][][] images = new int[3][][][];
|
int[][][][] images = new int[3][][][]; //We want to draw 3 images,
|
||||||
images[0]=rgb;
|
images[0]=rgb; //the default image
|
||||||
images[1]=gray;
|
images[1]=gray; //gray image
|
||||||
images[2]=sepia;
|
images[2]=sepia; //sepiaed image
|
||||||
Java101ImageUtil.showViewer(images,"show all");
|
Java101ImageUtil.showViewer(images,"show all"); //Call ImageUtil to draw the image
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int [][][] grayscale(int [][][] rgb) {
|
public static int [][][] grayscale(int [][][] rgb) {
|
||||||
// fill code
|
// fill code
|
||||||
int[][][] grayscale = new int [rgb.length][rgb[0].length][3];
|
int[][][] grayscale = new int [rgb.length][rgb[0].length][3];
|
||||||
for(int i=0;i<grayscale.length;i++) for(int j=0;j<grayscale[0].length;j++) {
|
for(int i=0;i<grayscale.length;i++) for(int j=0;j<grayscale[0].length;j++) { //Loop through each Pixel
|
||||||
int modifiedColor = (int)Math.ceil((rgb[i][j][0]+rgb[i][j][1]+rgb[i][j][2])/3.0);
|
int modifiedColor = (int)Math.ceil((rgb[i][j][0]+rgb[i][j][1]+rgb[i][j][2])/3.0); //Grayscale is the average of all color in each pixel
|
||||||
for(int k = 0;k<3;k++)grayscale[i][j][k] = modifiedColor;
|
for(int k = 0;k<3;k++)grayscale[i][j][k] = modifiedColor; //All color in pixel == Avg Color
|
||||||
}
|
}
|
||||||
return grayscale;
|
return grayscale;
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,7 @@ public class DesaturateIt{
|
||||||
int[][][] sepia = new int [rgb.length][rgb[0].length][3];
|
int[][][] sepia = new int [rgb.length][rgb[0].length][3];
|
||||||
for(int i=0;i<sepia.length;i++) for(int j=0;j<sepia[0].length;j++) {
|
for(int i=0;i<sepia.length;i++) for(int j=0;j<sepia[0].length;j++) {
|
||||||
int modifiedColor = (int)Math.ceil((rgb[i][j][0]+rgb[i][j][1]+rgb[i][j][2])/3.0);
|
int modifiedColor = (int)Math.ceil((rgb[i][j][0]+rgb[i][j][1]+rgb[i][j][2])/3.0);
|
||||||
|
//Like Grayscale, just adjust the color ratio
|
||||||
sepia[i][j][0] = (int)(modifiedColor*0.8745);
|
sepia[i][j][0] = (int)(modifiedColor*0.8745);
|
||||||
sepia[i][j][1] = (int)(modifiedColor*0.6352);
|
sepia[i][j][1] = (int)(modifiedColor*0.6352);
|
||||||
sepia[i][j][2] = (int)(modifiedColor*0.4941);
|
sepia[i][j][2] = (int)(modifiedColor*0.4941);
|
||||||
|
|
Loading…
Reference in New Issue