Ka Flashcards
Spiegeln Horizontal
{ public Picture spiegelHorizontal(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe]; for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { pixelNeu[x][y] = pixel[(breite-1)-x][y]; } }
Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Spiegeln Vertikal
{ public Picture spiegelVertikal(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe]; for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { pixelNeu[x][y] = pixel[x][(hoehe-1)-y]; } }
Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Dreh Rechts
{ public Picture dreheRechts(Picture originalbild) {
int breite = originalbild.getHeight();
int hoehe = originalbild.getWidth();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { pixelNeu[x][y] = pixel[y][(breite-1)-x]; } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
dreh links
{ public Picture dreheLinks(Picture originalbild) {
int breite = originalbild.getHeight();
int hoehe = originalbild.getWidth();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { pixelNeu[x][y] = pixel[(hoehe-1)-y][x]; } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
drehe 180
{ public Picture drehe180(Picture originalbild) {
Picture bild90 = dreheLinks(originalbild);
Picture bild180 = dreheLinks(bild90);
return bild180; }
graustufe Durchschnitt
{
public Picture graustufenDurchschnitt(Picture originalbild) { int breite = originalbild.getWidth(); int hoehe = originalbild.getHeight(); Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int grau = (int) ((pixel[x][y].getRed()+ pixel[x][y].getGreen() + pixel[x][y].getBlue())/3); pixelNeu[x][y] = new Color(grau, grau, grau); } }
Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
graustufe Minimum
{ public Picture graustufenMin(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int grau = pixel[x][y].getRed(); if (grau > pixel[x][y].getGreen()) grau = pixel[x][y].getGreen(); if (grau > pixel[x][y].getBlue()) grau = pixel[x][y].getBlue(); pixelNeu[x][y] = new Color(grau, grau, grau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
graustufe Maximum
public Picture graustufenMax(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int grau = pixel[x][y].getRed(); if (grau < pixel[x][y].getGreen()) grau = pixel[x][y].getGreen(); if (grau < pixel[x][y].getBlue()) grau = pixel[x][y].getBlue(); pixelNeu[x][y] = new Color(grau, grau, grau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Natürliche Grausstufe
public Picture graustufenNatuerlich(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int grau = (int) (pixel[x][y].getRed()*299+pixel[x][y].getGreen()*587+pixel[x][y].getBlue()*114)/1000; pixelNeu[x][y] = new Color(grau, grau, grau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Bild invertieren
{ public Picture invertieren(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int rot = 255-pixel[x][y].getRed(); int gruen = 255-pixel[x][y].getGreen(); int blau = 255-pixel[x][y].getBlue(); pixelNeu[x][y] = new Color(rot, gruen, blau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
tausch rot-grün
public Picture tauschRotGruen(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int rot = pixel[x][y].getGreen(); int gruen = pixel[x][y].getRed(); int blau = pixel[x][y].getBlue(); pixelNeu[x][y] = new Color(rot, gruen, blau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
tausch rot blau
public Picture tauschRotBlau(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int rot = pixel[x][y].getBlue(); int gruen = pixel[x][y].getGreen(); int blau = pixel[x][y].getRed(); pixelNeu[x][y] = new Color(rot, gruen, blau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Tausch Grün Blau
public Picture tauschGruenBlau(Picture originalbild) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe];
for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int rot = pixel[x][y].getRed(); int gruen = pixel[x][y].getBlue(); int blau = pixel[x][y].getGreen(); pixelNeu[x][y] = new Color(rot, gruen, blau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
Farbänderung
public Picture farbaenderung(Picture originalbild, double faktor_r, double faktor_g, double faktor_b) {
int breite = originalbild.getWidth();
int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Color[][] pixelNeu = new Color[breite][hoehe]; for(int x=0; x < breite; x++) { for(int y=0;y < hoehe; y++) { int rot = (int) (pixel[x][y].getRed() * faktor_r); int gruen = (int) (pixel[x][y].getGreen() * faktor_g); int blau = (int) (pixel[x][y].getBlue() * faktor_b);
//Begrenzung auf zulässigen Bereich if(rot < 0) rot = 0; if(rot > 255) rot = 255; if(gruen < 0) gruen = 0; if(gruen > 255) gruen = 255; if(blau < 0) blau = 0; if(blau > 255) blau = 255;
pixelNeu[x][y] = new Color(rot, gruen, blau); } } Picture neuesBild = new Picture(); neuesBild.setPixelArray(pixelNeu); return neuesBild; }
}
Striheln
class Kunst { public Picture stricheln(Picture originalbild, int laenge, int dicke, int anzahl) { int breite = originalbild.getWidth(); int hoehe = originalbild.getHeight();
Color[][] pixel = originalbild.getPixelArray(); Picture neuesBild = new Picture(breite,hoehe);
neuesBild.strokeWeight(dicke); Random r = new Random();
for(int i=0; i < anzahl; i++) { int x = r.nextInt(breite); int y = r.nextInt(hoehe); neuesBild.stroke(pixel[x][y].getRed(),pixel[x][y].getGreen(),pixel[x][y].getBlue()); neuesBild.line(x, y, x+laenge, y+laenge); } return neuesBild; }