Version 1.0.0 (2024-12-29): Material ZPG (2020)
BIN
6_processing_variante/02_kopiervorlagen/02_alg_farbmodell.odt
Normal file
BIN
6_processing_variante/02_kopiervorlagen/03_alg_faltung.odt
Normal file
BIN
6_processing_variante/02_kopiervorlagen/05_alg_gui_erstellen.odt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Eigenes Werk (Eisenmann):
|
||||
buesche.jpg
|
||||
huetten.jpg
|
||||
kuehe.jpg
|
||||
rabe.jpg
|
||||
schmetterling.jpg
|
||||
see.jpg
|
||||
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 125 KiB |
|
After Width: | Height: | Size: 159 KiB |
|
After Width: | Height: | Size: 76 KiB |
|
After Width: | Height: | Size: 141 KiB |
|
|
@ -0,0 +1,45 @@
|
|||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
// Aufgaben 7 und 8 hier ergänzen
|
||||
|
||||
// Aufruf der Methode aus Aufgabe 10 hier ergänzen
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in ein zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode aus Aufgabe 10 hier ergänzen
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Eigenes Werk (Eisenmann):
|
||||
buesche.jpg
|
||||
huetten.jpg
|
||||
kuehe.jpg
|
||||
rabe.jpg
|
||||
schmetterling.jpg
|
||||
see.jpg
|
||||
|
After Width: | Height: | Size: 192 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
|
@ -0,0 +1,29 @@
|
|||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/kuehe.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
// Aufruf der geschriebenen Methoden
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in ein zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
// Need G4P library
|
||||
import g4p_controls.*;
|
||||
|
||||
// ********* Deklarationen
|
||||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
public void setup(){
|
||||
size(800, 700, JAVA2D);
|
||||
createGUI();
|
||||
customGUI();
|
||||
|
||||
// ********** setup()-Methode ergänzen, aber hier keine Bildbearbeitungs-
|
||||
// methode aufrufen!
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
// background(230); // wird hier auskommentiert, kommt in setup()
|
||||
}
|
||||
|
||||
// ************* hier alle Bildbearbeitungsmethoden einfügen
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in ein zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Use this method to add additional statements
|
||||
// to customise the GUI controls
|
||||
public void customGUI(){
|
||||
}
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* =========================================================
|
||||
* ==== WARNING ===
|
||||
* =========================================================
|
||||
* The code in this tab has been generated from the GUI form
|
||||
* designer and care should be taken when editing this file.
|
||||
* Only add/edit code inside the event handlers i.e. only
|
||||
* use lines between the matching comment tags. e.g.
|
||||
|
||||
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
|
||||
// It is safe to enter your event code here
|
||||
} //_CODE_:button1:12356:
|
||||
|
||||
* Do not rename this tab!
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
public void btSpiegelnClick(GButton source, GEvent event) { //_CODE_:btSpiegeln:781683:
|
||||
if (opHorizontal.isSelected()) {
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
} else {
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
}
|
||||
background(255); // altes Bild wird übermalt
|
||||
image(bildNeu, 0, 0); // Bild wird an der Position (0|0) angezeigt
|
||||
} //_CODE_:btSpiegeln:781683:
|
||||
|
||||
|
||||
|
||||
// Create all the GUI controls.
|
||||
// autogenerated do not edit
|
||||
public void createGUI(){
|
||||
G4P.messagesEnabled(false);
|
||||
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
|
||||
G4P.setMouseOverEnabled(false);
|
||||
surface.setTitle("Sketch Window");
|
||||
btSpiegeln = new GButton(this, 670, 50, 120, 30);
|
||||
btSpiegeln.setText("Bild spiegeln");
|
||||
btSpiegeln.addEventHandler(this, "btSpiegelnClick");
|
||||
grSpiegeln = new GToggleGroup();
|
||||
opHorizontal = new GOption(this, 670, 30, 120, 20);
|
||||
opHorizontal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHorizontal.setText("horizontal");
|
||||
opHorizontal.setOpaque(false);
|
||||
opVertikal = new GOption(this, 670, 10, 120, 20);
|
||||
opVertikal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opVertikal.setText("vertikal");
|
||||
opVertikal.setOpaque(false);
|
||||
grSpiegeln.addControl(opHorizontal);
|
||||
opHorizontal.setSelected(true);
|
||||
grSpiegeln.addControl(opVertikal);
|
||||
}
|
||||
|
||||
// Variable declarations
|
||||
// autogenerated do not edit
|
||||
GButton btSpiegeln;
|
||||
GToggleGroup grSpiegeln;
|
||||
GOption opHorizontal;
|
||||
GOption opVertikal;
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
/*
|
||||
// Aufgabe 7
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
// Aufgabe 8
|
||||
save("data/spiegelsee.jpg");
|
||||
|
||||
// Aufgabe 10
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
// Aufgabe 15 - Testen
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
*/
|
||||
// Aufgabe 16 - Testen
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in ein zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
|
@ -0,0 +1,128 @@
|
|||
color[][] pixelNeu;
|
||||
color[][] pixelAlt;
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
/*
|
||||
*/
|
||||
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
image(bildNeu, bildAlt.width, bildAlt.height);
|
||||
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
image(bildNeu,0,0);
|
||||
}
|
||||
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
color[][] pixelNeu;
|
||||
color[][] pixelAlt;
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/kuehe.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
bildNeu = invertiere(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
bildNeu = farbaenderung(bildAlt, 2.0, 2.0, 2.0);
|
||||
image(bildNeu, bildAlt.width, bildAlt.height);
|
||||
}
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
87
6_processing_variante/04_loesungen/p04faltung/p04faltung.pde
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
double[][] weichzeichnen = {{1.0/9,1.0/9,1.0/9},{1.0/9,1.0/9,1.0/9},{1.0/9,1.0/9,1.0/9}};
|
||||
double[][] schaerfen = {{0,-1,0},{-1,5,-1},{0,-1,0}};
|
||||
double[][] relief = {{-2,-1,0},{-1,1,1},{0,1,2}};
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
// Aufruf der geschriebenen Methoden
|
||||
bildNeu = faltung(bildAlt,weichzeichnen);
|
||||
image(bildNeu,bildAlt.width,0);
|
||||
|
||||
bildNeu = faltung(bildAlt,schaerfen);
|
||||
image(bildNeu,0,bildAlt.height);
|
||||
|
||||
bildNeu = faltung(bildAlt,relief);
|
||||
image(bildNeu,bildAlt.width,bildAlt.height);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
// neue Pixel zunächst wie alte, damit Rand kopiert wird:
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, double[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
double rot = 0.0;
|
||||
double gruen = 0.0;
|
||||
double blau = 0.0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
|
|
@ -0,0 +1,372 @@
|
|||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu;
|
||||
|
||||
float[][] weichzeichnen = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}};
|
||||
float[][] schaerfen = {{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}};
|
||||
float[][] relief = {{-2, -1, 0}, {-1, 1, 1}, {0, 1, 2}};
|
||||
|
||||
void setup() {
|
||||
size(1000, 800);
|
||||
background(255);
|
||||
bildAlt = loadImage("data/see.jpg");
|
||||
image(bildAlt, 0, 0); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
|
||||
// Aufruf der geschriebenen Methoden
|
||||
/*
|
||||
// Aufgabe 7
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
// Aufgabe 8
|
||||
save("data/spiegelsee.jpg");
|
||||
|
||||
// Aufgabe 10
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
// Aufgabe 15 - Testen
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
image(bildNeu, bildAlt.width, bildAlt.height);
|
||||
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
image(bildNeu,0,0);
|
||||
|
||||
bildNeu = invertiere(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
bildNeu = farbaenderung(bildAlt, 2.0, 2.0, 2.0);
|
||||
image(bildNeu, bildAlt.width, bildAlt.height);
|
||||
|
||||
|
||||
|
||||
// Aufgabe 16 - Testen
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
*/
|
||||
|
||||
bildNeu = faltung(bildAlt, weichzeichnen);
|
||||
image(bildNeu, bildAlt.width, 0);
|
||||
|
||||
bildNeu = faltung(bildAlt, schaerfen);
|
||||
image(bildNeu, 0, bildAlt.height);
|
||||
|
||||
bildNeu = faltung(bildAlt, relief);
|
||||
image(bildNeu, bildAlt.width, bildAlt.height);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
// neue Pixel zunächst wie alte, damit Rand kopiert wird:
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, float[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
355
6_processing_variante/04_loesungen/p05alles_drin_mit_gui/gui.pde
Normal file
|
|
@ -0,0 +1,355 @@
|
|||
/* =========================================================
|
||||
* ==== WARNING ===
|
||||
* =========================================================
|
||||
* The code in this tab has been generated from the GUI form
|
||||
* designer and care should be taken when editing this file.
|
||||
* Only add/edit code inside the event handlers i.e. only
|
||||
* use lines between the matching comment tags. e.g.
|
||||
|
||||
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
|
||||
// It is safe to enter your event code here
|
||||
} //_CODE_:button1:12356:
|
||||
|
||||
* Do not rename this tab!
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
public void btSpiegleHorizontalClick(GButton source, GEvent event) { //_CODE_:btSpiegleHorizontal:794212:
|
||||
if (opHorizontal.isSelected()) {
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
} else {
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btSpiegleHorizontal:794212:
|
||||
|
||||
public void opHorizontalClicked(GOption source, GEvent event) { //_CODE_:opHorizontal:776377:
|
||||
|
||||
} //_CODE_:opHorizontal:776377:
|
||||
|
||||
public void opVertikalClicked(GOption source, GEvent event) { //_CODE_:opVertikal:280145:
|
||||
|
||||
} //_CODE_:opVertikal:280145:
|
||||
|
||||
public void opDreheLinksClicked(GOption source, GEvent event) { //_CODE_:opDreheLinks:906072:
|
||||
|
||||
} //_CODE_:opDreheLinks:906072:
|
||||
|
||||
public void opDreheRechtsClicked(GOption source, GEvent event) { //_CODE_:opDreheRechts:227629:
|
||||
|
||||
} //_CODE_:opDreheRechts:227629:
|
||||
|
||||
public void btDrehenClick(GButton source, GEvent event) { //_CODE_:btDrehen:314298:
|
||||
if (opDreheLinks.isSelected()) {
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
} else if (opDreheRechts.isSelected()) {
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btDrehen:314298:
|
||||
|
||||
public void btInvertierenClick(GButton source, GEvent event) { //_CODE_:btInvertieren:524942:
|
||||
bildNeu = invertiere(bildAlt);
|
||||
AnzeigenUndMerken(x_start,y_start);
|
||||
} //_CODE_:btInvertieren:524942:
|
||||
|
||||
public void opMittelwertClicked(GOption source, GEvent event) { //_CODE_:opMittelwert:973298:
|
||||
|
||||
} //_CODE_:opMittelwert:973298:
|
||||
|
||||
public void opMinimumClicked(GOption source, GEvent event) { //_CODE_:opMinimum:513484:
|
||||
|
||||
} //_CODE_:opMinimum:513484:
|
||||
|
||||
public void opMaximumClicked(GOption source, GEvent event) { //_CODE_:opMaximum:399858:
|
||||
|
||||
} //_CODE_:opMaximum:399858:
|
||||
|
||||
public void opNatuerlichClicked(GOption source, GEvent event) { //_CODE_:opNatuerlich:845925:
|
||||
|
||||
} //_CODE_:opNatuerlich:845925:
|
||||
|
||||
public void btGraustufenClick(GButton source, GEvent event) { //_CODE_:btGraustufen:859002:
|
||||
if (opMittelwert.isSelected()) {
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
} else if (opMinimum.isSelected()) {
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
} else if (opMaximum.isSelected()) {
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
} else {
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btGraustufen:859002:
|
||||
|
||||
public void btBildLadenClick(GButton source, GEvent event) { //_CODE_:btBildLaden:362917:
|
||||
background(255);
|
||||
selectInput("Wähle ein Bild:", "fileSelected");
|
||||
} //_CODE_:btBildLaden:362917:
|
||||
|
||||
public void opWeichzeichnenClicked(GOption source, GEvent event) { //_CODE_:opWeichzeichnen:515433:
|
||||
|
||||
} //_CODE_:opWeichzeichnen:515433:
|
||||
|
||||
public void opSchaerfenClicked(GOption source, GEvent event) { //_CODE_:opSchaerfen:681076:
|
||||
|
||||
} //_CODE_:opSchaerfen:681076:
|
||||
|
||||
public void opReliefClicked(GOption source, GEvent event) { //_CODE_:opRelief:281383:
|
||||
|
||||
} //_CODE_:opRelief:281383:
|
||||
|
||||
public void btFaltungClicked(GButton source, GEvent event) { //_CODE_:btFaltung:907937:
|
||||
if (opWeichzeichnen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, weichzeichnen);
|
||||
} else if (opSchaerfen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, schaerfen);
|
||||
} else {
|
||||
bildNeu = faltung(bildAlt, relief);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFaltung:907937:
|
||||
|
||||
public void btTauschRGClicked(GButton source, GEvent event) { //_CODE_:btTauschRG:897884:
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTauschRG:897884:
|
||||
|
||||
public void btFarbaenderungClicked(GButton source, GEvent event) { //_CODE_:btFarbaenderung:610399:
|
||||
bildNeu = farbaenderung(bildAlt, slFaktorRot.getValueF(), slFaktorGruen.getValueF(), slFaktorBlau.getValueF());
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFarbaenderung:610399:
|
||||
|
||||
public void slFaktorRotChanged(GSlider source, GEvent event) { //_CODE_:slFaktorRot:988001:
|
||||
noStroke();
|
||||
rect(lbRot.getX(), lbRot.getY(), lbRot.getWidth(), lbRot.getHeight());
|
||||
lbRot.setText(""+Math.round(10.0*slFaktorRot.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorRot:988001:
|
||||
|
||||
public void slFaktorGruenChanged(GSlider source, GEvent event) { //_CODE_:slFaktorGruen:632440:
|
||||
noStroke();
|
||||
rect(lbGruen.getX(), lbGruen.getY(), lbGruen.getWidth(), lbGruen.getHeight());
|
||||
lbGruen.setText(""+Math.round(10.0*slFaktorGruen.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorGruen:632440:
|
||||
|
||||
public void slFaktorBlauChanged(GSlider source, GEvent event) { //_CODE_:slFaktorBlau:377268:
|
||||
noStroke();
|
||||
rect(lbBlau.getX(), lbBlau.getY(), lbBlau.getWidth(), lbBlau.getHeight());
|
||||
lbBlau.setText(""+Math.round(10.0*slFaktorBlau.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorBlau:377268:
|
||||
|
||||
public void btSpeichernClicked(GButton source, GEvent event) { //_CODE_:btSpeichern:713724:
|
||||
selectOutput("Dateinamen wählen:", "fileSelectedSave");
|
||||
} //_CODE_:btSpeichern:713724:
|
||||
|
||||
public void btRueckgaengigClicked(GButton source, GEvent event) { //_CODE_:btRueckgaengig:565159:
|
||||
background(255);
|
||||
image(bildVorher, x_start, y_start);
|
||||
bildAlt = bildVorher;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btRueckgaengig:565159:
|
||||
|
||||
public void btOriginalClicked(GButton source, GEvent event) { //_CODE_:btOriginal:928763:
|
||||
image(bildOriginal, x_start, y_start);
|
||||
bildAlt = bildOriginal;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btOriginal:928763:
|
||||
|
||||
|
||||
|
||||
// Create all the GUI controls.
|
||||
// autogenerated do not edit
|
||||
public void createGUI(){
|
||||
G4P.messagesEnabled(false);
|
||||
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
|
||||
G4P.setMouseOverEnabled(false);
|
||||
surface.setTitle("Bildbearbeitung");
|
||||
btSpiegleHorizontal = new GButton(this, 650, 80, 120, 30);
|
||||
btSpiegleHorizontal.setText("Bild Spiegeln");
|
||||
btSpiegleHorizontal.addEventHandler(this, "btSpiegleHorizontalClick");
|
||||
grSpiegeln = new GToggleGroup();
|
||||
opHorizontal = new GOption(this, 650, 40, 120, 20);
|
||||
opHorizontal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHorizontal.setText("horizontal");
|
||||
opHorizontal.setOpaque(false);
|
||||
opHorizontal.addEventHandler(this, "opHorizontalClicked");
|
||||
opVertikal = new GOption(this, 650, 60, 120, 20);
|
||||
opVertikal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opVertikal.setText("vertikal");
|
||||
opVertikal.setOpaque(false);
|
||||
opVertikal.addEventHandler(this, "opVertikalClicked");
|
||||
grSpiegeln.addControl(opHorizontal);
|
||||
opHorizontal.setSelected(true);
|
||||
grSpiegeln.addControl(opVertikal);
|
||||
grDrehen = new GToggleGroup();
|
||||
opDreheLinks = new GOption(this, 650, 120, 120, 20);
|
||||
opDreheLinks.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheLinks.setText("nach links");
|
||||
opDreheLinks.setOpaque(false);
|
||||
opDreheLinks.addEventHandler(this, "opDreheLinksClicked");
|
||||
opDreheRechts = new GOption(this, 650, 140, 120, 20);
|
||||
opDreheRechts.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheRechts.setText("nach rechts");
|
||||
opDreheRechts.setOpaque(false);
|
||||
opDreheRechts.addEventHandler(this, "opDreheRechtsClicked");
|
||||
grDrehen.addControl(opDreheLinks);
|
||||
opDreheLinks.setSelected(true);
|
||||
grDrehen.addControl(opDreheRechts);
|
||||
btDrehen = new GButton(this, 650, 160, 120, 30);
|
||||
btDrehen.setText("Bild drehen");
|
||||
btDrehen.addEventHandler(this, "btDrehenClick");
|
||||
btInvertieren = new GButton(this, 650, 200, 120, 30);
|
||||
btInvertieren.setText("Farben invertieren");
|
||||
btInvertieren.addEventHandler(this, "btInvertierenClick");
|
||||
grGraustufen = new GToggleGroup();
|
||||
opMittelwert = new GOption(this, 650, 240, 120, 20);
|
||||
opMittelwert.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMittelwert.setText("Mittelwert");
|
||||
opMittelwert.setOpaque(false);
|
||||
opMittelwert.addEventHandler(this, "opMittelwertClicked");
|
||||
opMinimum = new GOption(this, 650, 260, 120, 20);
|
||||
opMinimum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMinimum.setText("Minimum");
|
||||
opMinimum.setOpaque(false);
|
||||
opMinimum.addEventHandler(this, "opMinimumClicked");
|
||||
opMaximum = new GOption(this, 650, 280, 120, 20);
|
||||
opMaximum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMaximum.setText("Maximum");
|
||||
opMaximum.setOpaque(false);
|
||||
opMaximum.addEventHandler(this, "opMaximumClicked");
|
||||
opNatuerlich = new GOption(this, 650, 300, 120, 20);
|
||||
opNatuerlich.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opNatuerlich.setText("Natürlich");
|
||||
opNatuerlich.setOpaque(false);
|
||||
opNatuerlich.addEventHandler(this, "opNatuerlichClicked");
|
||||
grGraustufen.addControl(opMittelwert);
|
||||
opMittelwert.setSelected(true);
|
||||
grGraustufen.addControl(opMinimum);
|
||||
grGraustufen.addControl(opMaximum);
|
||||
grGraustufen.addControl(opNatuerlich);
|
||||
btGraustufen = new GButton(this, 650, 320, 120, 30);
|
||||
btGraustufen.setText("Graustufen");
|
||||
btGraustufen.addEventHandler(this, "btGraustufenClick");
|
||||
btBildLaden = new GButton(this, 0, 0, 118, 30);
|
||||
btBildLaden.setText("Bild laden");
|
||||
btBildLaden.addEventHandler(this, "btBildLadenClick");
|
||||
grFaltung = new GToggleGroup();
|
||||
opWeichzeichnen = new GOption(this, 650, 360, 120, 20);
|
||||
opWeichzeichnen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opWeichzeichnen.setText("Weichzeichnen");
|
||||
opWeichzeichnen.setOpaque(false);
|
||||
opWeichzeichnen.addEventHandler(this, "opWeichzeichnenClicked");
|
||||
opSchaerfen = new GOption(this, 650, 380, 120, 20);
|
||||
opSchaerfen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opSchaerfen.setText("Schärfen");
|
||||
opSchaerfen.setOpaque(false);
|
||||
opSchaerfen.addEventHandler(this, "opSchaerfenClicked");
|
||||
opRelief = new GOption(this, 650, 400, 120, 20);
|
||||
opRelief.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opRelief.setText("Relief");
|
||||
opRelief.setOpaque(false);
|
||||
opRelief.addEventHandler(this, "opReliefClicked");
|
||||
grFaltung.addControl(opWeichzeichnen);
|
||||
opWeichzeichnen.setSelected(true);
|
||||
grFaltung.addControl(opSchaerfen);
|
||||
grFaltung.addControl(opRelief);
|
||||
btFaltung = new GButton(this, 650, 420, 120, 30);
|
||||
btFaltung.setText("Faltung ausführen");
|
||||
btFaltung.addEventHandler(this, "btFaltungClicked");
|
||||
btTauschRG = new GButton(this, 650, 460, 120, 30);
|
||||
btTauschRG.setText("Tausche Rot - Grün");
|
||||
btTauschRG.addEventHandler(this, "btTauschRGClicked");
|
||||
btFarbaenderung = new GButton(this, 650, 650, 120, 30);
|
||||
btFarbaenderung.setText("Farbänderung");
|
||||
btFarbaenderung.addEventHandler(this, "btFarbaenderungClicked");
|
||||
slFaktorRot = new GSlider(this, 650, 510, 120, 40, 10.0);
|
||||
slFaktorRot.setShowLimits(true);
|
||||
slFaktorRot.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorRot.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorRot.setOpaque(false);
|
||||
slFaktorRot.addEventHandler(this, "slFaktorRotChanged");
|
||||
lbRotFaktor = new GLabel(this, 650, 500, 80, 20);
|
||||
lbRotFaktor.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRotFaktor.setText("Faktor Rot:");
|
||||
lbRotFaktor.setOpaque(false);
|
||||
lbRot = new GLabel(this, 720, 500, 50, 20);
|
||||
lbRot.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRot.setText("1.0");
|
||||
lbRot.setOpaque(false);
|
||||
slFaktorGruen = new GSlider(this, 650, 560, 120, 40, 10.0);
|
||||
slFaktorGruen.setShowLimits(true);
|
||||
slFaktorGruen.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorGruen.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorGruen.setOpaque(false);
|
||||
slFaktorGruen.addEventHandler(this, "slFaktorGruenChanged");
|
||||
lbFaktorGruen = new GLabel(this, 650, 550, 80, 20);
|
||||
lbFaktorGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorGruen.setText("Faktor Grün: ");
|
||||
lbFaktorGruen.setOpaque(false);
|
||||
lbGruen = new GLabel(this, 720, 550, 50, 20);
|
||||
lbGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbGruen.setText("1.0");
|
||||
lbGruen.setOpaque(false);
|
||||
slFaktorBlau = new GSlider(this, 650, 610, 120, 40, 10.0);
|
||||
slFaktorBlau.setShowLimits(true);
|
||||
slFaktorBlau.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorBlau.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorBlau.setOpaque(false);
|
||||
slFaktorBlau.addEventHandler(this, "slFaktorBlauChanged");
|
||||
lbFaktorBlau = new GLabel(this, 650, 600, 80, 20);
|
||||
lbFaktorBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorBlau.setText("Faktor Blau: ");
|
||||
lbFaktorBlau.setOpaque(false);
|
||||
lbBlau = new GLabel(this, 720, 600, 50, 20);
|
||||
lbBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbBlau.setText("1.0");
|
||||
lbBlau.setOpaque(false);
|
||||
btSpeichern = new GButton(this, 120, 0, 110, 30);
|
||||
btSpeichern.setText("Bild speichern");
|
||||
btSpeichern.addEventHandler(this, "btSpeichernClicked");
|
||||
btRueckgaengig = new GButton(this, 300, 0, 160, 30);
|
||||
btRueckgaengig.setText("Rückgängig");
|
||||
btRueckgaengig.setLocalColorScheme(GCScheme.GOLD_SCHEME);
|
||||
btRueckgaengig.addEventHandler(this, "btRueckgaengigClicked");
|
||||
btOriginal = new GButton(this, 470, 0, 160, 30);
|
||||
btOriginal.setText("Originalbild");
|
||||
btOriginal.addEventHandler(this, "btOriginalClicked");
|
||||
}
|
||||
|
||||
// Variable declarations
|
||||
// autogenerated do not edit
|
||||
GButton btSpiegleHorizontal;
|
||||
GToggleGroup grSpiegeln;
|
||||
GOption opHorizontal;
|
||||
GOption opVertikal;
|
||||
GToggleGroup grDrehen;
|
||||
GOption opDreheLinks;
|
||||
GOption opDreheRechts;
|
||||
GButton btDrehen;
|
||||
GButton btInvertieren;
|
||||
GToggleGroup grGraustufen;
|
||||
GOption opMittelwert;
|
||||
GOption opMinimum;
|
||||
GOption opMaximum;
|
||||
GOption opNatuerlich;
|
||||
GButton btGraustufen;
|
||||
GButton btBildLaden;
|
||||
GToggleGroup grFaltung;
|
||||
GOption opWeichzeichnen;
|
||||
GOption opSchaerfen;
|
||||
GOption opRelief;
|
||||
GButton btFaltung;
|
||||
GButton btTauschRG;
|
||||
GButton btFarbaenderung;
|
||||
GSlider slFaktorRot;
|
||||
GLabel lbRotFaktor;
|
||||
GLabel lbRot;
|
||||
GSlider slFaktorGruen;
|
||||
GLabel lbFaktorGruen;
|
||||
GLabel lbGruen;
|
||||
GSlider slFaktorBlau;
|
||||
GLabel lbFaktorBlau;
|
||||
GLabel lbBlau;
|
||||
GButton btSpeichern;
|
||||
GButton btRueckgaengig;
|
||||
GButton btOriginal;
|
||||
|
|
@ -0,0 +1,385 @@
|
|||
// Need G4P library
|
||||
import g4p_controls.*;
|
||||
|
||||
|
||||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu, bildOriginal, bildVorher;
|
||||
|
||||
float[][] weichzeichnen = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}};
|
||||
float[][] schaerfen = {{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}};
|
||||
float[][] relief = {{-2, -1, 0}, {-1, 1, 1}, {0, 1, 2}};
|
||||
|
||||
int x_start = 0; // Position der linken oberen Bildecke bei der Anzeige
|
||||
int y_start = 50;
|
||||
|
||||
boolean bildgewaehlt = false;
|
||||
|
||||
String dateiname;
|
||||
|
||||
public void setup() {
|
||||
|
||||
size(800, 700, JAVA2D);
|
||||
background(255);
|
||||
createGUI();
|
||||
customGUI();
|
||||
// Place your setup code here
|
||||
bildLaden("kuehe.jpg");
|
||||
}
|
||||
|
||||
void fileSelected(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
bildgewaehlt = true;
|
||||
dateiname = selection.getAbsolutePath();
|
||||
// bildLaden(selection.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
void fileSelectedSave(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
dateiname = selection.getAbsolutePath();
|
||||
bildNeu.save(dateiname+".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void draw() {
|
||||
if (bildgewaehlt) {
|
||||
bildLaden(dateiname);
|
||||
}
|
||||
bildgewaehlt = false;
|
||||
}
|
||||
|
||||
// Use this method to add additional statements
|
||||
// to customise the GUI controls
|
||||
public void customGUI() {
|
||||
}
|
||||
|
||||
public void AnzeigenUndMerken(int x, int y){
|
||||
// fuer die Anzeige des veränderten Bildes und speichern des Vorgängers
|
||||
// wird nur in Eventhandlern aufgerufen
|
||||
background(255);
|
||||
image(bildNeu, x, y);
|
||||
bildVorher = new PImage(bildNeu.width, bildNeu.height, RGB);
|
||||
bildVorher = bildAlt;
|
||||
bildAlt = bildNeu;
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
|
||||
void bildLaden(String pfad) {
|
||||
bildOriginal = loadImage(pfad);
|
||||
// bildAlt = new PImage(bildOriginal.width, bildOriginal.height, RGB);
|
||||
bildAlt = bildOriginal;
|
||||
image(bildAlt, x_start, y_start); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
// neue Pixel zunächst wie alte, damit Rand kopiert wird:
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, float[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
|
|
@ -0,0 +1,418 @@
|
|||
/* =========================================================
|
||||
* ==== WARNING ===
|
||||
* =========================================================
|
||||
* The code in this tab has been generated from the GUI form
|
||||
* designer and care should be taken when editing this file.
|
||||
* Only add/edit code inside the event handlers i.e. only
|
||||
* use lines between the matching comment tags. e.g.
|
||||
|
||||
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
|
||||
// It is safe to enter your event code here
|
||||
} //_CODE_:button1:12356:
|
||||
|
||||
* Do not rename this tab!
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
public void btSpiegleHorizontalClick(GButton source, GEvent event) { //_CODE_:btSpiegleHorizontal:794212:
|
||||
if (opHorizontal.isSelected()) {
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
} else {
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btSpiegleHorizontal:794212:
|
||||
|
||||
public void opHorizontalClicked(GOption source, GEvent event) { //_CODE_:opHorizontal:776377:
|
||||
println("opHorizontal - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opHorizontal:776377:
|
||||
|
||||
public void opVertikalClicked(GOption source, GEvent event) { //_CODE_:opVertikal:280145:
|
||||
println("opVertikal - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opVertikal:280145:
|
||||
|
||||
public void opDreheLinksClicked(GOption source, GEvent event) { //_CODE_:opDreheLinks:906072:
|
||||
println("opDreheLinks - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opDreheLinks:906072:
|
||||
|
||||
public void opDreheRechtsClicked(GOption source, GEvent event) { //_CODE_:opDreheRechts:227629:
|
||||
println("opDreheRechts - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opDreheRechts:227629:
|
||||
|
||||
public void btDrehenClick(GButton source, GEvent event) { //_CODE_:btDrehen:314298:
|
||||
if (opDreheLinks.isSelected()) {
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
} else if (opDreheRechts.isSelected()) {
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btDrehen:314298:
|
||||
|
||||
public void btInvertierenClick(GButton source, GEvent event) { //_CODE_:btInvertieren:524942:
|
||||
bildNeu = invertiere(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btInvertieren:524942:
|
||||
|
||||
public void opMittelwertClicked(GOption source, GEvent event) { //_CODE_:opMittelwert:973298:
|
||||
println("opMittelwert - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMittelwert:973298:
|
||||
|
||||
public void opMinimumClicked(GOption source, GEvent event) { //_CODE_:opMinimum:513484:
|
||||
println("opMinimum - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMinimum:513484:
|
||||
|
||||
public void opMaximumClicked(GOption source, GEvent event) { //_CODE_:opMaximum:399858:
|
||||
println("opMaximum - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMaximum:399858:
|
||||
|
||||
public void opNatuerlichClicked(GOption source, GEvent event) { //_CODE_:opNatuerlich:845925:
|
||||
println("opNatuerlich - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opNatuerlich:845925:
|
||||
|
||||
public void btGraustufenClick(GButton source, GEvent event) { //_CODE_:btGraustufen:859002:
|
||||
if (opMittelwert.isSelected()) {
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
} else if (opMinimum.isSelected()) {
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
} else if (opMaximum.isSelected()) {
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
} else if (opNatuerlich.isSelected()) {
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btGraustufen:859002:
|
||||
|
||||
public void btBildLadenClick(GButton source, GEvent event) { //_CODE_:btBildLaden:362917:
|
||||
background(255);
|
||||
selectInput("Wähle ein Bild:", "fileSelected");
|
||||
} //_CODE_:btBildLaden:362917:
|
||||
|
||||
public void opWeichzeichnenClicked(GOption source, GEvent event) { //_CODE_:opWeichzeichnen:515433:
|
||||
println("opWeichzeichnen - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opWeichzeichnen:515433:
|
||||
|
||||
public void opSchaerfenClicked(GOption source, GEvent event) { //_CODE_:opSchaerfen:681076:
|
||||
println("opSchaerfen - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opSchaerfen:681076:
|
||||
|
||||
public void opReliefClicked(GOption source, GEvent event) { //_CODE_:opRelief:281383:
|
||||
println("opRelief - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opRelief:281383:
|
||||
|
||||
public void btFaltungClicked(GButton source, GEvent event) { //_CODE_:btFaltung:907937:
|
||||
if (opWeichzeichnen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, weichzeichnen);
|
||||
} else if (opSchaerfen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, schaerfen);
|
||||
} else {
|
||||
bildNeu = faltung(bildAlt, relief);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFaltung:907937:
|
||||
|
||||
public void btTauschRGClicked(GButton source, GEvent event) { //_CODE_:btTauschRG:897884:
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTauschRG:897884:
|
||||
|
||||
public void btFarbaenderungClicked(GButton source, GEvent event) { //_CODE_:btFarbaenderung:610399:
|
||||
bildNeu = farbaenderung(bildAlt, slFaktorRot.getValueF(), slFaktorGruen.getValueF(), slFaktorBlau.getValueF());
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFarbaenderung:610399:
|
||||
|
||||
public void slFaktorRotChanged(GSlider source, GEvent event) { //_CODE_:slFaktorRot:988001:
|
||||
noStroke();
|
||||
rect(lbRot.getX(), lbRot.getY(), lbRot.getWidth(), lbRot.getHeight());
|
||||
lbRot.setText(""+Math.round(10.0*slFaktorRot.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorRot:988001:
|
||||
|
||||
public void slFaktorGruenChanged(GSlider source, GEvent event) { //_CODE_:slFaktorGruen:632440:
|
||||
noStroke();
|
||||
rect(lbGruen.getX(), lbGruen.getY(), lbGruen.getWidth(), lbGruen.getHeight());
|
||||
lbGruen.setText(""+Math.round(10.0*slFaktorGruen.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorGruen:632440:
|
||||
|
||||
public void slFaktorBlauChanged(GSlider source, GEvent event) { //_CODE_:slFaktorBlau:377268:
|
||||
noStroke();
|
||||
rect(lbBlau.getX(), lbBlau.getY(), lbBlau.getWidth(), lbBlau.getHeight());
|
||||
lbBlau.setText(""+Math.round(10.0*slFaktorBlau.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorBlau:377268:
|
||||
|
||||
public void btSpeichernClicked(GButton source, GEvent event) { //_CODE_:btSpeichern:713724:
|
||||
selectOutput("Dateinamen wählen:", "fileSelectedSave");
|
||||
} //_CODE_:btSpeichern:713724:
|
||||
|
||||
public void btRueckgaengigClicked(GButton source, GEvent event) { //_CODE_:btRueckgaengig:565159:
|
||||
background(255);
|
||||
image(bildVorher, x_start, y_start);
|
||||
bildAlt = bildVorher;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btRueckgaengig:565159:
|
||||
|
||||
public void btOriginalClicked(GButton source, GEvent event) { //_CODE_:btOriginal:928763:
|
||||
image(bildOriginal, x_start, y_start);
|
||||
bildAlt = bildOriginal;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btOriginal:928763:
|
||||
|
||||
public void btTupfenClick(GButton source, GEvent event) { //_CODE_:btTupfen:311847:
|
||||
bildNeu = tupfen(bildAlt, int(tfDurchmesser.getText()), int(tfTupfAnzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTupfen:311847:
|
||||
|
||||
public void btStrichelnClick(GButton source, GEvent event) { //_CODE_:btStricheln:882489:
|
||||
bildNeu = stricheln(bildAlt, int(tfStiftdicke.getText()), int(tfStrichlaenge.getText()), int(tfStrichanzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btStricheln:882489:
|
||||
|
||||
|
||||
|
||||
// Create all the GUI controls.
|
||||
// autogenerated do not edit
|
||||
public void createGUI(){
|
||||
G4P.messagesEnabled(false);
|
||||
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
|
||||
G4P.setMouseOverEnabled(false);
|
||||
surface.setTitle("Bildbearbeitung");
|
||||
btSpiegleHorizontal = new GButton(this, 650, 50, 120, 30);
|
||||
btSpiegleHorizontal.setText("Bild spiegeln");
|
||||
btSpiegleHorizontal.addEventHandler(this, "btSpiegleHorizontalClick");
|
||||
grSpiegeln = new GToggleGroup();
|
||||
opHorizontal = new GOption(this, 650, 10, 120, 20);
|
||||
opHorizontal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHorizontal.setText("horizontal");
|
||||
opHorizontal.setOpaque(false);
|
||||
opHorizontal.addEventHandler(this, "opHorizontalClicked");
|
||||
opVertikal = new GOption(this, 650, 30, 120, 20);
|
||||
opVertikal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opVertikal.setText("vertikal");
|
||||
opVertikal.setOpaque(false);
|
||||
opVertikal.addEventHandler(this, "opVertikalClicked");
|
||||
grSpiegeln.addControl(opHorizontal);
|
||||
opHorizontal.setSelected(true);
|
||||
grSpiegeln.addControl(opVertikal);
|
||||
grDrehen = new GToggleGroup();
|
||||
opDreheLinks = new GOption(this, 650, 90, 120, 20);
|
||||
opDreheLinks.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheLinks.setText("nach links");
|
||||
opDreheLinks.setOpaque(false);
|
||||
opDreheLinks.addEventHandler(this, "opDreheLinksClicked");
|
||||
opDreheRechts = new GOption(this, 650, 110, 120, 20);
|
||||
opDreheRechts.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheRechts.setText("nach rechts");
|
||||
opDreheRechts.setOpaque(false);
|
||||
opDreheRechts.addEventHandler(this, "opDreheRechtsClicked");
|
||||
grDrehen.addControl(opDreheLinks);
|
||||
opDreheLinks.setSelected(true);
|
||||
grDrehen.addControl(opDreheRechts);
|
||||
btDrehen = new GButton(this, 650, 130, 120, 30);
|
||||
btDrehen.setText("Bild drehen");
|
||||
btDrehen.addEventHandler(this, "btDrehenClick");
|
||||
btInvertieren = new GButton(this, 650, 170, 120, 30);
|
||||
btInvertieren.setText("Farben invertieren");
|
||||
btInvertieren.addEventHandler(this, "btInvertierenClick");
|
||||
grGraustufen = new GToggleGroup();
|
||||
opMittelwert = new GOption(this, 650, 210, 120, 20);
|
||||
opMittelwert.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMittelwert.setText("Mittelwert");
|
||||
opMittelwert.setOpaque(false);
|
||||
opMittelwert.addEventHandler(this, "opMittelwertClicked");
|
||||
opMinimum = new GOption(this, 650, 230, 120, 20);
|
||||
opMinimum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMinimum.setText("Minimum");
|
||||
opMinimum.setOpaque(false);
|
||||
opMinimum.addEventHandler(this, "opMinimumClicked");
|
||||
opMaximum = new GOption(this, 650, 250, 120, 20);
|
||||
opMaximum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMaximum.setText("Maximum");
|
||||
opMaximum.setOpaque(false);
|
||||
opMaximum.addEventHandler(this, "opMaximumClicked");
|
||||
opNatuerlich = new GOption(this, 650, 270, 120, 20);
|
||||
opNatuerlich.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opNatuerlich.setText("Natürlich");
|
||||
opNatuerlich.setOpaque(false);
|
||||
opNatuerlich.addEventHandler(this, "opNatuerlichClicked");
|
||||
grGraustufen.addControl(opMittelwert);
|
||||
opMittelwert.setSelected(true);
|
||||
grGraustufen.addControl(opMinimum);
|
||||
grGraustufen.addControl(opMaximum);
|
||||
grGraustufen.addControl(opNatuerlich);
|
||||
btGraustufen = new GButton(this, 650, 290, 120, 30);
|
||||
btGraustufen.setText("Graustufen");
|
||||
btGraustufen.addEventHandler(this, "btGraustufenClick");
|
||||
btBildLaden = new GButton(this, 0, 0, 118, 30);
|
||||
btBildLaden.setText("Bild laden");
|
||||
btBildLaden.addEventHandler(this, "btBildLadenClick");
|
||||
grFaltung = new GToggleGroup();
|
||||
opWeichzeichnen = new GOption(this, 650, 360, 120, 20);
|
||||
opWeichzeichnen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opWeichzeichnen.setText("Weichzeichnen");
|
||||
opWeichzeichnen.setOpaque(false);
|
||||
opWeichzeichnen.addEventHandler(this, "opWeichzeichnenClicked");
|
||||
opSchaerfen = new GOption(this, 650, 380, 120, 20);
|
||||
opSchaerfen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opSchaerfen.setText("Schärfen");
|
||||
opSchaerfen.setOpaque(false);
|
||||
opSchaerfen.addEventHandler(this, "opSchaerfenClicked");
|
||||
opRelief = new GOption(this, 650, 400, 120, 20);
|
||||
opRelief.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opRelief.setText("Relief");
|
||||
opRelief.setOpaque(false);
|
||||
opRelief.addEventHandler(this, "opReliefClicked");
|
||||
grFaltung.addControl(opWeichzeichnen);
|
||||
opWeichzeichnen.setSelected(true);
|
||||
grFaltung.addControl(opSchaerfen);
|
||||
grFaltung.addControl(opRelief);
|
||||
btFaltung = new GButton(this, 650, 420, 120, 30);
|
||||
btFaltung.setText("Faltung ausführen");
|
||||
btFaltung.addEventHandler(this, "btFaltungClicked");
|
||||
btTauschRG = new GButton(this, 650, 460, 120, 30);
|
||||
btTauschRG.setText("Tausche Rot - Grün");
|
||||
btTauschRG.addEventHandler(this, "btTauschRGClicked");
|
||||
btFarbaenderung = new GButton(this, 650, 660, 120, 30);
|
||||
btFarbaenderung.setText("Farbänderung");
|
||||
btFarbaenderung.addEventHandler(this, "btFarbaenderungClicked");
|
||||
slFaktorRot = new GSlider(this, 650, 510, 120, 40, 10.0);
|
||||
slFaktorRot.setShowLimits(true);
|
||||
slFaktorRot.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorRot.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorRot.setOpaque(false);
|
||||
slFaktorRot.addEventHandler(this, "slFaktorRotChanged");
|
||||
lbRotFaktor = new GLabel(this, 650, 500, 80, 20);
|
||||
lbRotFaktor.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRotFaktor.setText("Faktor Rot:");
|
||||
lbRotFaktor.setOpaque(false);
|
||||
lbRot = new GLabel(this, 720, 500, 50, 20);
|
||||
lbRot.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRot.setText("1.0");
|
||||
lbRot.setOpaque(false);
|
||||
slFaktorGruen = new GSlider(this, 650, 560, 120, 40, 10.0);
|
||||
slFaktorGruen.setShowLimits(true);
|
||||
slFaktorGruen.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorGruen.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorGruen.setOpaque(false);
|
||||
slFaktorGruen.addEventHandler(this, "slFaktorGruenChanged");
|
||||
lbFaktorGruen = new GLabel(this, 650, 550, 80, 20);
|
||||
lbFaktorGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorGruen.setText("Faktor Grün: ");
|
||||
lbFaktorGruen.setOpaque(false);
|
||||
lbGruen = new GLabel(this, 720, 550, 50, 20);
|
||||
lbGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbGruen.setText("1.0");
|
||||
lbGruen.setOpaque(false);
|
||||
slFaktorBlau = new GSlider(this, 650, 610, 120, 40, 10.0);
|
||||
slFaktorBlau.setShowLimits(true);
|
||||
slFaktorBlau.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorBlau.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorBlau.setOpaque(false);
|
||||
slFaktorBlau.addEventHandler(this, "slFaktorBlauChanged");
|
||||
lbFaktorBlau = new GLabel(this, 650, 600, 80, 20);
|
||||
lbFaktorBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorBlau.setText("Faktor Blau: ");
|
||||
lbFaktorBlau.setOpaque(false);
|
||||
lbBlau = new GLabel(this, 720, 600, 50, 20);
|
||||
lbBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbBlau.setText("1.0");
|
||||
lbBlau.setOpaque(false);
|
||||
btSpeichern = new GButton(this, 120, 0, 110, 30);
|
||||
btSpeichern.setText("Bild speichern");
|
||||
btSpeichern.addEventHandler(this, "btSpeichernClicked");
|
||||
btRueckgaengig = new GButton(this, 300, 0, 160, 30);
|
||||
btRueckgaengig.setText("Rückgängig");
|
||||
btRueckgaengig.setLocalColorScheme(GCScheme.GOLD_SCHEME);
|
||||
btRueckgaengig.addEventHandler(this, "btRueckgaengigClicked");
|
||||
btOriginal = new GButton(this, 470, 0, 160, 30);
|
||||
btOriginal.setText("Originalbild");
|
||||
btOriginal.addEventHandler(this, "btOriginalClicked");
|
||||
btTupfen = new GButton(this, 120, 660, 110, 30);
|
||||
btTupfen.setText("Bild tupfen");
|
||||
btTupfen.addEventHandler(this, "btTupfenClick");
|
||||
btStricheln = new GButton(this, 390, 660, 120, 30);
|
||||
btStricheln.setText("Bild stricheln");
|
||||
btStricheln.addEventHandler(this, "btStrichelnClick");
|
||||
label1 = new GLabel(this, 0, 610, 130, 20);
|
||||
label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label1.setText("Durchmesser Tupfen:");
|
||||
label1.setOpaque(false);
|
||||
tfDurchmesser = new GTextField(this, 80, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfDurchmesser.setText("10");
|
||||
tfDurchmesser.setOpaque(true);
|
||||
label2 = new GLabel(this, 130, 610, 100, 20);
|
||||
label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label2.setText("Tupfen-Anzahl:");
|
||||
label2.setOpaque(false);
|
||||
tfTupfAnzahl = new GTextField(this, 180, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfTupfAnzahl.setText("5000");
|
||||
tfTupfAnzahl.setOpaque(true);
|
||||
label3 = new GLabel(this, 270, 610, 80, 20);
|
||||
label3.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label3.setText("Stiftdicke:");
|
||||
label3.setOpaque(false);
|
||||
tfStiftdicke = new GTextField(this, 300, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStiftdicke.setText("5");
|
||||
tfStiftdicke.setOpaque(true);
|
||||
label4 = new GLabel(this, 350, 610, 80, 20);
|
||||
label4.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label4.setText("Strichlänge:");
|
||||
label4.setOpaque(false);
|
||||
tfStrichlaenge = new GTextField(this, 380, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichlaenge.setText("10");
|
||||
tfStrichlaenge.setOpaque(true);
|
||||
label5 = new GLabel(this, 430, 610, 80, 20);
|
||||
label5.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label5.setText("Strichanzahl:");
|
||||
label5.setOpaque(false);
|
||||
tfStrichanzahl = new GTextField(this, 460, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichanzahl.setText("5000");
|
||||
tfStrichanzahl.setOpaque(true);
|
||||
}
|
||||
|
||||
// Variable declarations
|
||||
// autogenerated do not edit
|
||||
GButton btSpiegleHorizontal;
|
||||
GToggleGroup grSpiegeln;
|
||||
GOption opHorizontal;
|
||||
GOption opVertikal;
|
||||
GToggleGroup grDrehen;
|
||||
GOption opDreheLinks;
|
||||
GOption opDreheRechts;
|
||||
GButton btDrehen;
|
||||
GButton btInvertieren;
|
||||
GToggleGroup grGraustufen;
|
||||
GOption opMittelwert;
|
||||
GOption opMinimum;
|
||||
GOption opMaximum;
|
||||
GOption opNatuerlich;
|
||||
GButton btGraustufen;
|
||||
GButton btBildLaden;
|
||||
GToggleGroup grFaltung;
|
||||
GOption opWeichzeichnen;
|
||||
GOption opSchaerfen;
|
||||
GOption opRelief;
|
||||
GButton btFaltung;
|
||||
GButton btTauschRG;
|
||||
GButton btFarbaenderung;
|
||||
GSlider slFaktorRot;
|
||||
GLabel lbRotFaktor;
|
||||
GLabel lbRot;
|
||||
GSlider slFaktorGruen;
|
||||
GLabel lbFaktorGruen;
|
||||
GLabel lbGruen;
|
||||
GSlider slFaktorBlau;
|
||||
GLabel lbFaktorBlau;
|
||||
GLabel lbBlau;
|
||||
GButton btSpeichern;
|
||||
GButton btRueckgaengig;
|
||||
GButton btOriginal;
|
||||
GButton btTupfen;
|
||||
GButton btStricheln;
|
||||
GLabel label1;
|
||||
GTextField tfDurchmesser;
|
||||
GLabel label2;
|
||||
GTextField tfTupfAnzahl;
|
||||
GLabel label3;
|
||||
GTextField tfStiftdicke;
|
||||
GLabel label4;
|
||||
GTextField tfStrichlaenge;
|
||||
GLabel label5;
|
||||
GTextField tfStrichanzahl;
|
||||
|
|
@ -0,0 +1,458 @@
|
|||
// Need G4P library
|
||||
import g4p_controls.*;
|
||||
|
||||
|
||||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu, bildOriginal, bildVorher;
|
||||
|
||||
float[][] weichzeichnen = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}};
|
||||
float[][] schaerfen = {{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}};
|
||||
float[][] relief = {{-2, -1, 0}, {-1, 1, 1}, {0, 1, 2}};
|
||||
|
||||
int x_start = 0; // Position der linken oberen Bildecke bei der Anzeige
|
||||
int y_start = 50;
|
||||
|
||||
boolean bildgewaehlt = false;
|
||||
|
||||
String dateiname;
|
||||
|
||||
public void setup() {
|
||||
|
||||
size(800, 700, JAVA2D);
|
||||
background(255);
|
||||
createGUI();
|
||||
customGUI();
|
||||
// Place your setup code here
|
||||
bildLaden("kuehe.jpg");
|
||||
}
|
||||
|
||||
void fileSelected(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
bildgewaehlt = true;
|
||||
dateiname = selection.getAbsolutePath();
|
||||
// bildLaden(selection.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
void fileSelectedSave(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
dateiname = selection.getAbsolutePath();
|
||||
bildNeu.save(dateiname+".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void draw() {
|
||||
if (bildgewaehlt) {
|
||||
bildLaden(dateiname);
|
||||
}
|
||||
bildgewaehlt = false;
|
||||
}
|
||||
|
||||
// Use this method to add additional statements
|
||||
// to customise the GUI controls
|
||||
public void customGUI() {
|
||||
}
|
||||
|
||||
public void AnzeigenUndMerken(int x, int y) {
|
||||
// fuer die Anzeige des veränderten Bildes und speichern des Vorgängers
|
||||
// wird nur in Eventhandlern aufgerufen
|
||||
background(255);
|
||||
image(bildNeu, x, y);
|
||||
bildVorher = new PImage(bildNeu.width, bildNeu.height, RGB);
|
||||
bildVorher = bildAlt;
|
||||
bildAlt = bildNeu;
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
|
||||
void bildLaden(String pfad) {
|
||||
bildOriginal = loadImage(pfad);
|
||||
// bildAlt = new PImage(bildOriginal.width, bildOriginal.height, RGB);
|
||||
bildAlt = bildOriginal;
|
||||
image(bildAlt, x_start, y_start); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
// neue Pixel zunächst wie alte, damit Rand kopiert wird:
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 9: HSB-Farbmodell - Graustufen
|
||||
PImage graustufenHSB(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
colorMode(HSB, 360, 100, 100);
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
float h = hue(pixelAlt[x][y]); // Farbton wird übernommen
|
||||
float s = 0; // Sättigung wird auf 0 gesetzt
|
||||
float b = brightness(pixelAlt[x][y]); // Helligkeit wird übernommen
|
||||
pixelNeu[x][y]= color(int(h), int(s), int(b));
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
// zurücksetzen Farbmodus:
|
||||
colorMode(RGB, 255, 255, 255);
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, float[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
|
||||
// Blatt 8 - Tupfen und Stricheln
|
||||
// Methode ermöglicht Tupfen von Bildern
|
||||
PImage tupfen(PImage originalbild, int groesse, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
noStroke();
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = groesse/2 + int(random(breite-groesse));
|
||||
int y = groesse/2 + int(random(hoehe-groesse));
|
||||
fill(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
ellipse(x + x_start, y + y_start, groesse, groesse);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode ermöglicht Stricheln von Bildern
|
||||
PImage stricheln(PImage originalbild, int dicke, int laenge, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = laenge/2 + int(random(breite-laenge));
|
||||
int y = laenge/2 + int(random(hoehe-laenge));
|
||||
stroke(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
strokeWeight(dicke);
|
||||
// mit Pythagoras
|
||||
int schritt = round(laenge / sqrt(2));
|
||||
line(x + x_start, y + y_start, x + x_start+schritt, y + y_start - schritt);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
465
6_processing_variante/04_loesungen/p09alles_drin_mit_hsb/gui.pde
Normal file
|
|
@ -0,0 +1,465 @@
|
|||
/* =========================================================
|
||||
* ==== WARNING ===
|
||||
* =========================================================
|
||||
* The code in this tab has been generated from the GUI form
|
||||
* designer and care should be taken when editing this file.
|
||||
* Only add/edit code inside the event handlers i.e. only
|
||||
* use lines between the matching comment tags. e.g.
|
||||
|
||||
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
|
||||
// It is safe to enter your event code here
|
||||
} //_CODE_:button1:12356:
|
||||
|
||||
* Do not rename this tab!
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
public void btSpiegleHorizontalClick(GButton source, GEvent event) { //_CODE_:btSpiegleHorizontal:794212:
|
||||
if (opHorizontal.isSelected()) {
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
} else {
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btSpiegleHorizontal:794212:
|
||||
|
||||
public void opHorizontalClicked(GOption source, GEvent event) { //_CODE_:opHorizontal:776377:
|
||||
println("opHorizontal - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opHorizontal:776377:
|
||||
|
||||
public void opVertikalClicked(GOption source, GEvent event) { //_CODE_:opVertikal:280145:
|
||||
println("opVertikal - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opVertikal:280145:
|
||||
|
||||
public void opDreheLinksClicked(GOption source, GEvent event) { //_CODE_:opDreheLinks:906072:
|
||||
println("opDreheLinks - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opDreheLinks:906072:
|
||||
|
||||
public void opDreheRechtsClicked(GOption source, GEvent event) { //_CODE_:opDreheRechts:227629:
|
||||
println("opDreheRechts - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opDreheRechts:227629:
|
||||
|
||||
public void btDrehenClick(GButton source, GEvent event) { //_CODE_:btDrehen:314298:
|
||||
if (opDreheLinks.isSelected()) {
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
} else if (opDreheRechts.isSelected()) {
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btDrehen:314298:
|
||||
|
||||
public void btInvertierenClick(GButton source, GEvent event) { //_CODE_:btInvertieren:524942:
|
||||
bildNeu = invertiere(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btInvertieren:524942:
|
||||
|
||||
public void opMittelwertClicked(GOption source, GEvent event) { //_CODE_:opMittelwert:973298:
|
||||
println("opMittelwert - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMittelwert:973298:
|
||||
|
||||
public void opMinimumClicked(GOption source, GEvent event) { //_CODE_:opMinimum:513484:
|
||||
println("opMinimum - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMinimum:513484:
|
||||
|
||||
public void opMaximumClicked(GOption source, GEvent event) { //_CODE_:opMaximum:399858:
|
||||
println("opMaximum - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opMaximum:399858:
|
||||
|
||||
public void opNatuerlichClicked(GOption source, GEvent event) { //_CODE_:opNatuerlich:845925:
|
||||
println("opNatuerlich - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opNatuerlich:845925:
|
||||
|
||||
public void btGraustufenClick(GButton source, GEvent event) { //_CODE_:btGraustufen:859002:
|
||||
if (opMittelwert.isSelected()) {
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
} else if (opMinimum.isSelected()) {
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
} else if (opMaximum.isSelected()) {
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
} else if (opNatuerlich.isSelected()) {
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
} else if (opHSB.isSelected()) {
|
||||
bildNeu = graustufenHSB(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btGraustufen:859002:
|
||||
|
||||
public void btBildLadenClick(GButton source, GEvent event) { //_CODE_:btBildLaden:362917:
|
||||
background(255);
|
||||
selectInput("Wähle ein Bild:", "fileSelected");
|
||||
} //_CODE_:btBildLaden:362917:
|
||||
|
||||
public void opWeichzeichnenClicked(GOption source, GEvent event) { //_CODE_:opWeichzeichnen:515433:
|
||||
println("opWeichzeichnen - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opWeichzeichnen:515433:
|
||||
|
||||
public void opSchaerfenClicked(GOption source, GEvent event) { //_CODE_:opSchaerfen:681076:
|
||||
println("opSchaerfen - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opSchaerfen:681076:
|
||||
|
||||
public void opReliefClicked(GOption source, GEvent event) { //_CODE_:opRelief:281383:
|
||||
println("opRelief - GOption >> GEvent." + event + " @ " + millis());
|
||||
} //_CODE_:opRelief:281383:
|
||||
|
||||
public void btFaltungClicked(GButton source, GEvent event) { //_CODE_:btFaltung:907937:
|
||||
if (opWeichzeichnen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, weichzeichnen);
|
||||
} else if (opSchaerfen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, schaerfen);
|
||||
} else {
|
||||
bildNeu = faltung(bildAlt, relief);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFaltung:907937:
|
||||
|
||||
public void btTauschRGClicked(GButton source, GEvent event) { //_CODE_:btTauschRG:897884:
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTauschRG:897884:
|
||||
|
||||
public void btFarbaenderungClicked(GButton source, GEvent event) { //_CODE_:btFarbaenderung:610399:
|
||||
bildNeu = farbaenderung(bildAlt, slFaktorRot.getValueF(), slFaktorGruen.getValueF(), slFaktorBlau.getValueF());
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFarbaenderung:610399:
|
||||
|
||||
public void slFaktorRotChanged(GSlider source, GEvent event) { //_CODE_:slFaktorRot:988001:
|
||||
noStroke();
|
||||
rect(lbRot.getX(), lbRot.getY(), lbRot.getWidth(), lbRot.getHeight());
|
||||
lbRot.setText(""+Math.round(10.0*slFaktorRot.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorRot:988001:
|
||||
|
||||
public void slFaktorGruenChanged(GSlider source, GEvent event) { //_CODE_:slFaktorGruen:632440:
|
||||
noStroke();
|
||||
rect(lbGruen.getX(), lbGruen.getY(), lbGruen.getWidth(), lbGruen.getHeight());
|
||||
lbGruen.setText(""+Math.round(10.0*slFaktorGruen.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorGruen:632440:
|
||||
|
||||
public void slFaktorBlauChanged(GSlider source, GEvent event) { //_CODE_:slFaktorBlau:377268:
|
||||
noStroke();
|
||||
rect(lbBlau.getX(), lbBlau.getY(), lbBlau.getWidth(), lbBlau.getHeight());
|
||||
lbBlau.setText(""+Math.round(10.0*slFaktorBlau.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorBlau:377268:
|
||||
|
||||
public void btSpeichernClicked(GButton source, GEvent event) { //_CODE_:btSpeichern:713724:
|
||||
selectOutput("Dateinamen wählen:", "fileSelectedSave");
|
||||
} //_CODE_:btSpeichern:713724:
|
||||
|
||||
public void btRueckgaengigClicked(GButton source, GEvent event) { //_CODE_:btRueckgaengig:565159:
|
||||
background(255);
|
||||
image(bildVorher, x_start, y_start);
|
||||
bildAlt = bildVorher;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btRueckgaengig:565159:
|
||||
|
||||
public void btOriginalClicked(GButton source, GEvent event) { //_CODE_:btOriginal:928763:
|
||||
image(bildOriginal, x_start, y_start);
|
||||
bildAlt = bildOriginal;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btOriginal:928763:
|
||||
|
||||
public void btTupfenClick(GButton source, GEvent event) { //_CODE_:btTupfen:311847:
|
||||
bildNeu = tupfen(bildAlt, int(tfDurchmesser.getText()), int(tfTupfAnzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTupfen:311847:
|
||||
|
||||
public void btStrichelnClick(GButton source, GEvent event) { //_CODE_:btStricheln:882489:
|
||||
bildNeu = stricheln(bildAlt, int(tfStiftdicke.getText()), int(tfStrichlaenge.getText()), int(tfStrichanzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btStricheln:882489:
|
||||
|
||||
public void btHSBClick(GButton source, GEvent event) { //_CODE_:btHSBFarbaenderung:845799:
|
||||
bildNeu = farbaenderungHSB(bildAlt, int(tfHSBFarbton.getText()), int(tfHSBSaettigung.getText()), int(tfHSBHelligkeit.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btHSBFarbaenderung:845799:
|
||||
|
||||
|
||||
|
||||
// Create all the GUI controls.
|
||||
// autogenerated do not edit
|
||||
public void createGUI(){
|
||||
G4P.messagesEnabled(false);
|
||||
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
|
||||
G4P.setMouseOverEnabled(false);
|
||||
surface.setTitle("Bildbearbeitung");
|
||||
btSpiegleHorizontal = new GButton(this, 650, 50, 120, 30);
|
||||
btSpiegleHorizontal.setText("Bild spiegeln");
|
||||
btSpiegleHorizontal.addEventHandler(this, "btSpiegleHorizontalClick");
|
||||
grSpiegeln = new GToggleGroup();
|
||||
opHorizontal = new GOption(this, 650, 10, 120, 20);
|
||||
opHorizontal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHorizontal.setText("horizontal");
|
||||
opHorizontal.setOpaque(false);
|
||||
opHorizontal.addEventHandler(this, "opHorizontalClicked");
|
||||
opVertikal = new GOption(this, 650, 30, 120, 20);
|
||||
opVertikal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opVertikal.setText("vertikal");
|
||||
opVertikal.setOpaque(false);
|
||||
opVertikal.addEventHandler(this, "opVertikalClicked");
|
||||
grSpiegeln.addControl(opHorizontal);
|
||||
opHorizontal.setSelected(true);
|
||||
grSpiegeln.addControl(opVertikal);
|
||||
grDrehen = new GToggleGroup();
|
||||
opDreheLinks = new GOption(this, 650, 90, 120, 20);
|
||||
opDreheLinks.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheLinks.setText("nach links");
|
||||
opDreheLinks.setOpaque(false);
|
||||
opDreheLinks.addEventHandler(this, "opDreheLinksClicked");
|
||||
opDreheRechts = new GOption(this, 650, 110, 120, 20);
|
||||
opDreheRechts.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheRechts.setText("nach rechts");
|
||||
opDreheRechts.setOpaque(false);
|
||||
opDreheRechts.addEventHandler(this, "opDreheRechtsClicked");
|
||||
grDrehen.addControl(opDreheLinks);
|
||||
opDreheLinks.setSelected(true);
|
||||
grDrehen.addControl(opDreheRechts);
|
||||
btDrehen = new GButton(this, 650, 130, 120, 30);
|
||||
btDrehen.setText("Bild drehen");
|
||||
btDrehen.addEventHandler(this, "btDrehenClick");
|
||||
btInvertieren = new GButton(this, 650, 170, 120, 30);
|
||||
btInvertieren.setText("Farben invertieren");
|
||||
btInvertieren.addEventHandler(this, "btInvertierenClick");
|
||||
grGraustufen = new GToggleGroup();
|
||||
opMittelwert = new GOption(this, 650, 210, 120, 20);
|
||||
opMittelwert.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMittelwert.setText("Mittelwert");
|
||||
opMittelwert.setOpaque(false);
|
||||
opMittelwert.addEventHandler(this, "opMittelwertClicked");
|
||||
opMinimum = new GOption(this, 650, 230, 120, 20);
|
||||
opMinimum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMinimum.setText("Minimum");
|
||||
opMinimum.setOpaque(false);
|
||||
opMinimum.addEventHandler(this, "opMinimumClicked");
|
||||
opMaximum = new GOption(this, 650, 250, 120, 20);
|
||||
opMaximum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMaximum.setText("Maximum");
|
||||
opMaximum.setOpaque(false);
|
||||
opMaximum.addEventHandler(this, "opMaximumClicked");
|
||||
opNatuerlich = new GOption(this, 650, 270, 120, 20);
|
||||
opNatuerlich.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opNatuerlich.setText("Natürlich");
|
||||
opNatuerlich.setOpaque(false);
|
||||
opNatuerlich.addEventHandler(this, "opNatuerlichClicked");
|
||||
opHSB = new GOption(this, 650, 290, 120, 20);
|
||||
opHSB.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHSB.setText("HSB");
|
||||
opHSB.setOpaque(false);
|
||||
grGraustufen.addControl(opMittelwert);
|
||||
opMittelwert.setSelected(true);
|
||||
grGraustufen.addControl(opMinimum);
|
||||
grGraustufen.addControl(opMaximum);
|
||||
grGraustufen.addControl(opNatuerlich);
|
||||
grGraustufen.addControl(opHSB);
|
||||
btGraustufen = new GButton(this, 650, 310, 120, 30);
|
||||
btGraustufen.setText("Graustufen");
|
||||
btGraustufen.addEventHandler(this, "btGraustufenClick");
|
||||
btBildLaden = new GButton(this, 0, 0, 118, 30);
|
||||
btBildLaden.setText("Bild laden");
|
||||
btBildLaden.addEventHandler(this, "btBildLadenClick");
|
||||
grFaltung = new GToggleGroup();
|
||||
opWeichzeichnen = new GOption(this, 650, 360, 120, 20);
|
||||
opWeichzeichnen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opWeichzeichnen.setText("Weichzeichnen");
|
||||
opWeichzeichnen.setOpaque(false);
|
||||
opWeichzeichnen.addEventHandler(this, "opWeichzeichnenClicked");
|
||||
opSchaerfen = new GOption(this, 650, 380, 120, 20);
|
||||
opSchaerfen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opSchaerfen.setText("Schärfen");
|
||||
opSchaerfen.setOpaque(false);
|
||||
opSchaerfen.addEventHandler(this, "opSchaerfenClicked");
|
||||
opRelief = new GOption(this, 650, 400, 120, 20);
|
||||
opRelief.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opRelief.setText("Relief");
|
||||
opRelief.setOpaque(false);
|
||||
opRelief.addEventHandler(this, "opReliefClicked");
|
||||
grFaltung.addControl(opWeichzeichnen);
|
||||
opWeichzeichnen.setSelected(true);
|
||||
grFaltung.addControl(opSchaerfen);
|
||||
grFaltung.addControl(opRelief);
|
||||
btFaltung = new GButton(this, 650, 420, 120, 30);
|
||||
btFaltung.setText("Faltung ausführen");
|
||||
btFaltung.addEventHandler(this, "btFaltungClicked");
|
||||
btTauschRG = new GButton(this, 650, 460, 120, 30);
|
||||
btTauschRG.setText("Tausche Rot - Grün");
|
||||
btTauschRG.addEventHandler(this, "btTauschRGClicked");
|
||||
btFarbaenderung = new GButton(this, 650, 660, 120, 30);
|
||||
btFarbaenderung.setText("Farbänderung");
|
||||
btFarbaenderung.addEventHandler(this, "btFarbaenderungClicked");
|
||||
slFaktorRot = new GSlider(this, 650, 510, 120, 40, 10.0);
|
||||
slFaktorRot.setShowLimits(true);
|
||||
slFaktorRot.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorRot.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorRot.setOpaque(false);
|
||||
slFaktorRot.addEventHandler(this, "slFaktorRotChanged");
|
||||
lbRotFaktor = new GLabel(this, 650, 500, 80, 20);
|
||||
lbRotFaktor.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRotFaktor.setText("Faktor Rot:");
|
||||
lbRotFaktor.setOpaque(false);
|
||||
lbRot = new GLabel(this, 720, 500, 50, 20);
|
||||
lbRot.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRot.setText("1.0");
|
||||
lbRot.setOpaque(false);
|
||||
slFaktorGruen = new GSlider(this, 650, 560, 120, 40, 10.0);
|
||||
slFaktorGruen.setShowLimits(true);
|
||||
slFaktorGruen.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorGruen.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorGruen.setOpaque(false);
|
||||
slFaktorGruen.addEventHandler(this, "slFaktorGruenChanged");
|
||||
lbFaktorGruen = new GLabel(this, 650, 550, 80, 20);
|
||||
lbFaktorGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorGruen.setText("Faktor Grün: ");
|
||||
lbFaktorGruen.setOpaque(false);
|
||||
lbGruen = new GLabel(this, 720, 550, 50, 20);
|
||||
lbGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbGruen.setText("1.0");
|
||||
lbGruen.setOpaque(false);
|
||||
slFaktorBlau = new GSlider(this, 650, 610, 120, 40, 10.0);
|
||||
slFaktorBlau.setShowLimits(true);
|
||||
slFaktorBlau.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorBlau.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorBlau.setOpaque(false);
|
||||
slFaktorBlau.addEventHandler(this, "slFaktorBlauChanged");
|
||||
lbFaktorBlau = new GLabel(this, 650, 600, 80, 20);
|
||||
lbFaktorBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorBlau.setText("Faktor Blau: ");
|
||||
lbFaktorBlau.setOpaque(false);
|
||||
lbBlau = new GLabel(this, 720, 600, 50, 20);
|
||||
lbBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbBlau.setText("1.0");
|
||||
lbBlau.setOpaque(false);
|
||||
btSpeichern = new GButton(this, 120, 0, 110, 30);
|
||||
btSpeichern.setText("Bild speichern");
|
||||
btSpeichern.addEventHandler(this, "btSpeichernClicked");
|
||||
btRueckgaengig = new GButton(this, 300, 0, 160, 30);
|
||||
btRueckgaengig.setText("Rückgängig");
|
||||
btRueckgaengig.setLocalColorScheme(GCScheme.GOLD_SCHEME);
|
||||
btRueckgaengig.addEventHandler(this, "btRueckgaengigClicked");
|
||||
btOriginal = new GButton(this, 470, 0, 160, 30);
|
||||
btOriginal.setText("Originalbild");
|
||||
btOriginal.addEventHandler(this, "btOriginalClicked");
|
||||
btTupfen = new GButton(this, 120, 660, 110, 30);
|
||||
btTupfen.setText("Bild tupfen");
|
||||
btTupfen.addEventHandler(this, "btTupfenClick");
|
||||
btStricheln = new GButton(this, 390, 660, 120, 30);
|
||||
btStricheln.setText("Bild stricheln");
|
||||
btStricheln.addEventHandler(this, "btStrichelnClick");
|
||||
label1 = new GLabel(this, 0, 610, 130, 20);
|
||||
label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label1.setText("Durchmesser Tupfen:");
|
||||
label1.setOpaque(false);
|
||||
tfDurchmesser = new GTextField(this, 80, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfDurchmesser.setText("10");
|
||||
tfDurchmesser.setOpaque(true);
|
||||
label2 = new GLabel(this, 130, 610, 100, 20);
|
||||
label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label2.setText("Tupfen-Anzahl:");
|
||||
label2.setOpaque(false);
|
||||
tfTupfAnzahl = new GTextField(this, 180, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfTupfAnzahl.setText("5000");
|
||||
tfTupfAnzahl.setOpaque(true);
|
||||
label3 = new GLabel(this, 270, 610, 80, 20);
|
||||
label3.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label3.setText("Stiftdicke:");
|
||||
label3.setOpaque(false);
|
||||
tfStiftdicke = new GTextField(this, 300, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStiftdicke.setText("5");
|
||||
tfStiftdicke.setOpaque(true);
|
||||
label4 = new GLabel(this, 350, 610, 80, 20);
|
||||
label4.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label4.setText("Strichlänge:");
|
||||
label4.setOpaque(false);
|
||||
tfStrichlaenge = new GTextField(this, 380, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichlaenge.setText("10");
|
||||
tfStrichlaenge.setOpaque(true);
|
||||
label5 = new GLabel(this, 430, 610, 80, 20);
|
||||
label5.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label5.setText("Strichanzahl:");
|
||||
label5.setOpaque(false);
|
||||
tfStrichanzahl = new GTextField(this, 460, 630, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichanzahl.setText("5000");
|
||||
tfStrichanzahl.setOpaque(true);
|
||||
btHSBFarbaenderung = new GButton(this, 520, 660, 120, 30);
|
||||
btHSBFarbaenderung.setText("Farbänderung HSB");
|
||||
btHSBFarbaenderung.addEventHandler(this, "btHSBClick");
|
||||
label6 = new GLabel(this, 530, 500, 110, 20);
|
||||
label6.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label6.setText("Änderung Farbton:");
|
||||
label6.setOpaque(false);
|
||||
tfHSBFarbton = new GTextField(this, 590, 520, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBFarbton.setText("5");
|
||||
tfHSBFarbton.setPromptText(">= 0");
|
||||
tfHSBFarbton.setOpaque(true);
|
||||
label7 = new GLabel(this, 520, 550, 120, 20);
|
||||
label7.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label7.setText("Änderung Sättigung:");
|
||||
label7.setOpaque(false);
|
||||
tfHSBSaettigung = new GTextField(this, 590, 570, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBSaettigung.setText("1");
|
||||
tfHSBSaettigung.setPromptText("0 bis 2");
|
||||
tfHSBSaettigung.setOpaque(true);
|
||||
label8 = new GLabel(this, 520, 600, 120, 20);
|
||||
label8.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label8.setText("Änderung Helligkeit:");
|
||||
label8.setOpaque(false);
|
||||
tfHSBHelligkeit = new GTextField(this, 590, 620, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBHelligkeit.setText("1");
|
||||
tfHSBHelligkeit.setPromptText("0 bis 2");
|
||||
tfHSBHelligkeit.setOpaque(true);
|
||||
}
|
||||
|
||||
// Variable declarations
|
||||
// autogenerated do not edit
|
||||
GButton btSpiegleHorizontal;
|
||||
GToggleGroup grSpiegeln;
|
||||
GOption opHorizontal;
|
||||
GOption opVertikal;
|
||||
GToggleGroup grDrehen;
|
||||
GOption opDreheLinks;
|
||||
GOption opDreheRechts;
|
||||
GButton btDrehen;
|
||||
GButton btInvertieren;
|
||||
GToggleGroup grGraustufen;
|
||||
GOption opMittelwert;
|
||||
GOption opMinimum;
|
||||
GOption opMaximum;
|
||||
GOption opNatuerlich;
|
||||
GOption opHSB;
|
||||
GButton btGraustufen;
|
||||
GButton btBildLaden;
|
||||
GToggleGroup grFaltung;
|
||||
GOption opWeichzeichnen;
|
||||
GOption opSchaerfen;
|
||||
GOption opRelief;
|
||||
GButton btFaltung;
|
||||
GButton btTauschRG;
|
||||
GButton btFarbaenderung;
|
||||
GSlider slFaktorRot;
|
||||
GLabel lbRotFaktor;
|
||||
GLabel lbRot;
|
||||
GSlider slFaktorGruen;
|
||||
GLabel lbFaktorGruen;
|
||||
GLabel lbGruen;
|
||||
GSlider slFaktorBlau;
|
||||
GLabel lbFaktorBlau;
|
||||
GLabel lbBlau;
|
||||
GButton btSpeichern;
|
||||
GButton btRueckgaengig;
|
||||
GButton btOriginal;
|
||||
GButton btTupfen;
|
||||
GButton btStricheln;
|
||||
GLabel label1;
|
||||
GTextField tfDurchmesser;
|
||||
GLabel label2;
|
||||
GTextField tfTupfAnzahl;
|
||||
GLabel label3;
|
||||
GTextField tfStiftdicke;
|
||||
GLabel label4;
|
||||
GTextField tfStrichlaenge;
|
||||
GLabel label5;
|
||||
GTextField tfStrichanzahl;
|
||||
GButton btHSBFarbaenderung;
|
||||
GLabel label6;
|
||||
GTextField tfHSBFarbton;
|
||||
GLabel label7;
|
||||
GTextField tfHSBSaettigung;
|
||||
GLabel label8;
|
||||
GTextField tfHSBHelligkeit;
|
||||
|
|
@ -0,0 +1,485 @@
|
|||
// Need G4P library
|
||||
import g4p_controls.*;
|
||||
|
||||
|
||||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
PImage bildAlt, bildNeu, bildOriginal, bildVorher;
|
||||
|
||||
float[][] weichzeichnen = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}};
|
||||
float[][] schaerfen = {{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}};
|
||||
float[][] relief = {{-2, -1, 0}, {-1, 1, 1}, {0, 1, 2}};
|
||||
|
||||
int x_start = 0; // Position der linken oberen Bildecke bei der Anzeige
|
||||
int y_start = 50;
|
||||
|
||||
boolean bildgewaehlt = false;
|
||||
|
||||
String dateiname;
|
||||
|
||||
public void setup() {
|
||||
|
||||
size(800, 700, JAVA2D);
|
||||
background(255);
|
||||
createGUI();
|
||||
customGUI();
|
||||
// Place your setup code here
|
||||
bildLaden("kuehe.jpg");
|
||||
}
|
||||
|
||||
void fileSelected(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
bildgewaehlt = true;
|
||||
dateiname = selection.getAbsolutePath();
|
||||
// bildLaden(selection.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
void fileSelectedSave(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
dateiname = selection.getAbsolutePath();
|
||||
bildNeu.save(dateiname+".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void draw() {
|
||||
if (bildgewaehlt) {
|
||||
bildLaden(dateiname);
|
||||
}
|
||||
bildgewaehlt = false;
|
||||
}
|
||||
|
||||
// Use this method to add additional statements
|
||||
// to customise the GUI controls
|
||||
public void customGUI() {
|
||||
}
|
||||
|
||||
public void AnzeigenUndMerken(int x, int y) {
|
||||
// fuer die Anzeige des veränderten Bildes und speichern des Vorgängers
|
||||
// wird nur in Eventhandlern aufgerufen
|
||||
background(255);
|
||||
image(bildNeu, x, y);
|
||||
bildVorher = new PImage(bildNeu.width, bildNeu.height, RGB);
|
||||
bildVorher = bildAlt;
|
||||
bildAlt = bildNeu;
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
|
||||
void bildLaden(String pfad) {
|
||||
bildOriginal = loadImage(pfad);
|
||||
// bildAlt = new PImage(bildOriginal.width, bildOriginal.height, RGB);
|
||||
bildAlt = bildOriginal;
|
||||
image(bildAlt, x_start, y_start); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
// neue Pixel zunächst wie alte, damit Rand kopiert wird:
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 9: HSB-Farbmodell - Graustufen
|
||||
PImage graustufenHSB(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
colorMode(HSB, 360, 100, 100);
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
float h = hue(pixelAlt[x][y]); // Farbton wird übernommen
|
||||
float s = 0; // Sättigung wird auf 0 gesetzt
|
||||
float b = brightness(pixelAlt[x][y]); // Helligkeit wird übernommen
|
||||
pixelNeu[x][y]= color(int(h), int(s), int(b));
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
// zurücksetzen Farbmodus:
|
||||
colorMode(RGB, 255, 255, 255);
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 9: Farbänderung HSB
|
||||
PImage farbaenderungHSB(PImage originalbild, float dHue, float fSaturation, float fBrightness) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
colorMode(HSB, 360, 100, 100);
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
float h = hue(pixelAlt[x][y]) + dHue;
|
||||
float s = saturation(pixelAlt[x][y]) * fSaturation;
|
||||
float b = brightness(pixelAlt[x][y]) * fBrightness;
|
||||
if (s>100) s = 100;
|
||||
if (s< 0) s = 0;
|
||||
if (b>100) b = 100;
|
||||
if (b<0) b = 0;
|
||||
pixelNeu[x][y]= color(int(h), int(s), int(b));
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
// zurücksetzen Farbmodus:
|
||||
colorMode(RGB, 255, 255, 255);
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, float[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
|
||||
// Blatt 8 - Tupfen und Stricheln
|
||||
// Methode ermöglicht Tupfen von Bildern
|
||||
PImage tupfen(PImage originalbild, int groesse, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
noStroke();
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = groesse/2 + int(random(breite-groesse));
|
||||
int y = groesse/2 + int(random(hoehe-groesse));
|
||||
fill(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
ellipse(x + x_start, y + y_start, groesse, groesse);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode ermöglicht Stricheln von Bildern
|
||||
PImage stricheln(PImage originalbild, int dicke, int laenge, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = laenge/2 + int(random(breite-laenge));
|
||||
int y = laenge/2 + int(random(hoehe-laenge));
|
||||
stroke(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
strokeWeight(dicke);
|
||||
// mit Pythagoras
|
||||
int schritt = round(laenge / sqrt(2));
|
||||
line(x + x_start, y + y_start, x + x_start+schritt, y + y_start - schritt);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
Eigenes Werk (Schaller):
|
||||
Baum1.jpg
|
||||
Baum2.jpg
|
||||
Katze.jpg
|
||||
maske1.jpg
|
||||
maske2.jpg
|
||||
rosen_normal.jpg
|
||||
rosen_ueberbelichtet.jpg
|
||||
rosen_unterbelichtet.jpg
|
||||
|
||||
Eigenes Werk (Eisenmann):
|
||||
buesche.jpg
|
||||
huetten.jpg
|
||||
kuehe.jpg
|
||||
rabe.jpg
|
||||
schmetterling.jpg
|
||||
see.jpg
|
||||
|
||||
Pixabay Licence:
|
||||
https://pixabay.com/de/illustations/haus-häuser-finde-den-unterschied-3208132/
|
||||
unterschiedfinden1.png
|
||||
unterschiedfinden2.png
|
||||
|
||||
CC-BY-SA 2.5 (https://creativecommons.org/licenses/by-sa/2.5/deed.de)
|
||||
Frenelsche Zonenplatte,
|
||||
Georg Wiora via Wikimedia Commons
|
||||
https://commons.wikimedia.org/wiki/File:Zonenplatte_Cosinus.png
|
||||
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 199 KiB |
|
|
@ -0,0 +1,465 @@
|
|||
/* =========================================================
|
||||
* ==== WARNING ===
|
||||
* =========================================================
|
||||
* The code in this tab has been generated from the GUI form
|
||||
* designer and care should be taken when editing this file.
|
||||
* Only add/edit code inside the event handlers i.e. only
|
||||
* use lines between the matching comment tags. e.g.
|
||||
|
||||
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
|
||||
// It is safe to enter your event code here
|
||||
} //_CODE_:button1:12356:
|
||||
|
||||
* Do not rename this tab!
|
||||
* =========================================================
|
||||
*/
|
||||
|
||||
public void btSpiegleHorizontalClick(GButton source, GEvent event) { //_CODE_:btSpiegleHorizontal:794212:
|
||||
if (opHorizontal.isSelected()) {
|
||||
bildNeu = spiegleHorizontal(bildAlt);
|
||||
} else {
|
||||
bildNeu = spiegleVertikal(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btSpiegleHorizontal:794212:
|
||||
|
||||
public void btDrehenClick(GButton source, GEvent event) { //_CODE_:btDrehen:314298:
|
||||
if (opDreheLinks.isSelected()) {
|
||||
bildNeu = dreheLinks(bildAlt);
|
||||
} else if (opDreheRechts.isSelected()) {
|
||||
bildNeu = dreheRechts(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btDrehen:314298:
|
||||
|
||||
public void btInvertierenClick(GButton source, GEvent event) { //_CODE_:btInvertieren:524942:
|
||||
bildNeu = invertiere(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btInvertieren:524942:
|
||||
|
||||
public void btGraustufenClick(GButton source, GEvent event) { //_CODE_:btGraustufen:859002:
|
||||
if (opMittelwert.isSelected()) {
|
||||
bildNeu = graustufenDurchschnitt(bildAlt);
|
||||
} else if (opMinimum.isSelected()) {
|
||||
bildNeu = graustufenMin(bildAlt);
|
||||
} else if (opMaximum.isSelected()) {
|
||||
bildNeu = graustufenMax(bildAlt);
|
||||
} else if (opNatuerlich.isSelected()) {
|
||||
bildNeu = graustufenNatuerlich(bildAlt);
|
||||
} else if (opHSB.isSelected()) {
|
||||
bildNeu = graustufenHSB(bildAlt);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btGraustufen:859002:
|
||||
|
||||
public void btBildLadenClick(GButton source, GEvent event) { //_CODE_:btBildLaden:362917:
|
||||
background(255);
|
||||
selectInput("Wähle ein Bild:", "fileSelected");
|
||||
} //_CODE_:btBildLaden:362917:
|
||||
|
||||
public void btFaltungClicked(GButton source, GEvent event) { //_CODE_:btFaltung:907937:
|
||||
if (opWeichzeichnen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, weichzeichnen);
|
||||
} else if (opSchaerfen.isSelected()) {
|
||||
bildNeu = faltung(bildAlt, schaerfen);
|
||||
} else {
|
||||
bildNeu = faltung(bildAlt, relief);
|
||||
}
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFaltung:907937:
|
||||
|
||||
public void btTauschRGClicked(GButton source, GEvent event) { //_CODE_:btTauschRG:897884:
|
||||
bildNeu = tauscheRotGruen(bildAlt);
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTauschRG:897884:
|
||||
|
||||
public void btFarbaenderungClicked(GButton source, GEvent event) { //_CODE_:btFarbaenderung:610399:
|
||||
bildNeu = farbaenderung(bildAlt, slFaktorRot.getValueF(), slFaktorGruen.getValueF(), slFaktorBlau.getValueF());
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btFarbaenderung:610399:
|
||||
|
||||
public void slFaktorRotChanged(GSlider source, GEvent event) { //_CODE_:slFaktorRot:988001:
|
||||
noStroke();
|
||||
rect(lbRot.getX(), lbRot.getY(), lbRot.getWidth(), lbRot.getHeight());
|
||||
lbRot.setText(""+Math.round(10.0*slFaktorRot.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorRot:988001:
|
||||
|
||||
public void slFaktorGruenChanged(GSlider source, GEvent event) { //_CODE_:slFaktorGruen:632440:
|
||||
noStroke();
|
||||
rect(lbGruen.getX(), lbGruen.getY(), lbGruen.getWidth(), lbGruen.getHeight());
|
||||
lbGruen.setText(""+Math.round(10.0*slFaktorGruen.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorGruen:632440:
|
||||
|
||||
public void slFaktorBlauChanged(GSlider source, GEvent event) { //_CODE_:slFaktorBlau:377268:
|
||||
noStroke();
|
||||
rect(lbBlau.getX(), lbBlau.getY(), lbBlau.getWidth(), lbBlau.getHeight());
|
||||
lbBlau.setText(""+Math.round(10.0*slFaktorBlau.getValueF())/10.0);
|
||||
} //_CODE_:slFaktorBlau:377268:
|
||||
|
||||
public void btSpeichernClicked(GButton source, GEvent event) { //_CODE_:btSpeichern:713724:
|
||||
selectOutput("Dateinamen wählen (.jpg wird automatisch ergänzt):", "fileSelectedSave");
|
||||
} //_CODE_:btSpeichern:713724:
|
||||
|
||||
public void btRueckgaengigClicked(GButton source, GEvent event) { //_CODE_:btRueckgaengig:565159:
|
||||
background(255);
|
||||
image(bildVorher, x_start, y_start);
|
||||
bildAlt = bildVorher;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btRueckgaengig:565159:
|
||||
|
||||
public void btOriginalClicked(GButton source, GEvent event) { //_CODE_:btOriginal:928763:
|
||||
image(bildOriginal, x_start, y_start);
|
||||
bildAlt = bildOriginal;
|
||||
schreibeBildinArray(bildAlt);
|
||||
} //_CODE_:btOriginal:928763:
|
||||
|
||||
public void btTupfenClick(GButton source, GEvent event) { //_CODE_:btTupfen:311847:
|
||||
bildNeu = tupfen(bildAlt, int(tfDurchmesser.getText()), int(tfTupfAnzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btTupfen:311847:
|
||||
|
||||
public void btStrichelnClick(GButton source, GEvent event) { //_CODE_:btStricheln:882489:
|
||||
bildNeu = stricheln(bildAlt, int(tfStiftdicke.getText()), int(tfStrichlaenge.getText()), int(tfStrichanzahl.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btStricheln:882489:
|
||||
|
||||
public void btHSBClick(GButton source, GEvent event) { //_CODE_:btHSBFarbaenderung:845799:
|
||||
bildNeu = farbaenderungHSB(bildAlt, int(tfHSBFarbton.getText()), int(tfHSBSaettigung.getText()), int(tfHSBHelligkeit.getText()));
|
||||
AnzeigenUndMerken(x_start, y_start);
|
||||
} //_CODE_:btHSBFarbaenderung:845799:
|
||||
|
||||
public void btBild2LadenClick(GButton source, GEvent event) { //_CODE_:btBild2Laden:546387:
|
||||
selectInput("Wähle ein zweites Bild:", "file2Selected");
|
||||
} //_CODE_:btBild2Laden:546387:
|
||||
|
||||
public void btKombinierenClick(GButton source, GEvent event) { //_CODE_:btKombinieren:320769:
|
||||
if (opAddieren.isSelected()) {
|
||||
bildKombi = addition(bildAlt, bildZwei);
|
||||
} else if (opSubtrahieren.isSelected()) {
|
||||
bildKombi = subtraktion(bildAlt, bildZwei);
|
||||
} else if (opMultiplizieren.isSelected()) {
|
||||
bildKombi = multiplikation(bildAlt, bildZwei);
|
||||
}
|
||||
image(bildKombi, x_start + bildAlt.width / 2, y_start + bildAlt.height);
|
||||
} //_CODE_:btKombinieren:320769:
|
||||
|
||||
public void btKombiSpeichernClick(GButton source, GEvent event) { //_CODE_:btKombiSpeichern:240511:
|
||||
selectOutput("Dateinamen wählen (.jpg wird automatisch ergänzt):", "kombiFileSelectedSave");
|
||||
} //_CODE_:btKombiSpeichern:240511:
|
||||
|
||||
|
||||
|
||||
// Create all the GUI controls.
|
||||
// autogenerated do not edit
|
||||
public void createGUI(){
|
||||
G4P.messagesEnabled(false);
|
||||
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
|
||||
G4P.setMouseOverEnabled(false);
|
||||
surface.setTitle("Bildbearbeitung");
|
||||
btSpiegleHorizontal = new GButton(this, 1070, 50, 120, 30);
|
||||
btSpiegleHorizontal.setText("Bild spiegeln");
|
||||
btSpiegleHorizontal.addEventHandler(this, "btSpiegleHorizontalClick");
|
||||
grSpiegeln = new GToggleGroup();
|
||||
opHorizontal = new GOption(this, 1070, 10, 120, 20);
|
||||
opHorizontal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHorizontal.setText("horizontal");
|
||||
opHorizontal.setOpaque(false);
|
||||
opVertikal = new GOption(this, 1070, 30, 120, 20);
|
||||
opVertikal.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opVertikal.setText("vertikal");
|
||||
opVertikal.setOpaque(false);
|
||||
grSpiegeln.addControl(opHorizontal);
|
||||
opHorizontal.setSelected(true);
|
||||
grSpiegeln.addControl(opVertikal);
|
||||
grDrehen = new GToggleGroup();
|
||||
opDreheLinks = new GOption(this, 1070, 90, 120, 20);
|
||||
opDreheLinks.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheLinks.setText("nach links");
|
||||
opDreheLinks.setOpaque(false);
|
||||
opDreheRechts = new GOption(this, 1070, 110, 120, 20);
|
||||
opDreheRechts.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opDreheRechts.setText("nach rechts");
|
||||
opDreheRechts.setOpaque(false);
|
||||
grDrehen.addControl(opDreheLinks);
|
||||
opDreheLinks.setSelected(true);
|
||||
grDrehen.addControl(opDreheRechts);
|
||||
btDrehen = new GButton(this, 1070, 130, 120, 30);
|
||||
btDrehen.setText("Bild drehen");
|
||||
btDrehen.addEventHandler(this, "btDrehenClick");
|
||||
btInvertieren = new GButton(this, 1070, 170, 120, 30);
|
||||
btInvertieren.setText("Farben invertieren");
|
||||
btInvertieren.addEventHandler(this, "btInvertierenClick");
|
||||
grGraustufen = new GToggleGroup();
|
||||
opMittelwert = new GOption(this, 1070, 210, 120, 20);
|
||||
opMittelwert.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMittelwert.setText("Mittelwert");
|
||||
opMittelwert.setOpaque(false);
|
||||
opMinimum = new GOption(this, 1070, 230, 120, 20);
|
||||
opMinimum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMinimum.setText("Minimum");
|
||||
opMinimum.setOpaque(false);
|
||||
opMaximum = new GOption(this, 1070, 250, 120, 20);
|
||||
opMaximum.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMaximum.setText("Maximum");
|
||||
opMaximum.setOpaque(false);
|
||||
opNatuerlich = new GOption(this, 1070, 270, 120, 20);
|
||||
opNatuerlich.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opNatuerlich.setText("Natürlich");
|
||||
opNatuerlich.setOpaque(false);
|
||||
opHSB = new GOption(this, 1070, 290, 120, 20);
|
||||
opHSB.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opHSB.setText("HSB");
|
||||
opHSB.setOpaque(false);
|
||||
grGraustufen.addControl(opMittelwert);
|
||||
opMittelwert.setSelected(true);
|
||||
grGraustufen.addControl(opMinimum);
|
||||
grGraustufen.addControl(opMaximum);
|
||||
grGraustufen.addControl(opNatuerlich);
|
||||
grGraustufen.addControl(opHSB);
|
||||
btGraustufen = new GButton(this, 1070, 310, 120, 30);
|
||||
btGraustufen.setText("Graustufen");
|
||||
btGraustufen.addEventHandler(this, "btGraustufenClick");
|
||||
btBildLaden = new GButton(this, 0, 0, 118, 30);
|
||||
btBildLaden.setText("Bild laden");
|
||||
btBildLaden.addEventHandler(this, "btBildLadenClick");
|
||||
grFaltung = new GToggleGroup();
|
||||
opWeichzeichnen = new GOption(this, 1070, 360, 120, 20);
|
||||
opWeichzeichnen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opWeichzeichnen.setText("Weichzeichnen");
|
||||
opWeichzeichnen.setOpaque(false);
|
||||
opSchaerfen = new GOption(this, 1070, 380, 120, 20);
|
||||
opSchaerfen.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opSchaerfen.setText("Schärfen");
|
||||
opSchaerfen.setOpaque(false);
|
||||
opRelief = new GOption(this, 1070, 400, 120, 20);
|
||||
opRelief.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opRelief.setText("Relief");
|
||||
opRelief.setOpaque(false);
|
||||
grFaltung.addControl(opWeichzeichnen);
|
||||
opWeichzeichnen.setSelected(true);
|
||||
grFaltung.addControl(opSchaerfen);
|
||||
grFaltung.addControl(opRelief);
|
||||
btFaltung = new GButton(this, 1070, 420, 120, 30);
|
||||
btFaltung.setText("Faltung ausführen");
|
||||
btFaltung.addEventHandler(this, "btFaltungClicked");
|
||||
btTauschRG = new GButton(this, 1070, 460, 120, 30);
|
||||
btTauschRG.setText("Tausche Rot - Grün");
|
||||
btTauschRG.addEventHandler(this, "btTauschRGClicked");
|
||||
btFarbaenderung = new GButton(this, 1070, 650, 120, 30);
|
||||
btFarbaenderung.setText("Farbänderung");
|
||||
btFarbaenderung.addEventHandler(this, "btFarbaenderungClicked");
|
||||
slFaktorRot = new GSlider(this, 1070, 510, 120, 40, 10.0);
|
||||
slFaktorRot.setShowLimits(true);
|
||||
slFaktorRot.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorRot.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorRot.setOpaque(false);
|
||||
slFaktorRot.addEventHandler(this, "slFaktorRotChanged");
|
||||
lbRotFaktor = new GLabel(this, 1060, 500, 80, 20);
|
||||
lbRotFaktor.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRotFaktor.setText("Faktor Rot:");
|
||||
lbRotFaktor.setOpaque(false);
|
||||
lbRot = new GLabel(this, 1140, 500, 50, 20);
|
||||
lbRot.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbRot.setText("1.0");
|
||||
lbRot.setOpaque(false);
|
||||
slFaktorGruen = new GSlider(this, 1070, 560, 120, 40, 10.0);
|
||||
slFaktorGruen.setShowLimits(true);
|
||||
slFaktorGruen.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorGruen.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorGruen.setOpaque(false);
|
||||
slFaktorGruen.addEventHandler(this, "slFaktorGruenChanged");
|
||||
lbFaktorGruen = new GLabel(this, 1060, 550, 80, 20);
|
||||
lbFaktorGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorGruen.setText("Faktor Grün: ");
|
||||
lbFaktorGruen.setOpaque(false);
|
||||
lbGruen = new GLabel(this, 1140, 550, 50, 20);
|
||||
lbGruen.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbGruen.setText("1.0");
|
||||
lbGruen.setOpaque(false);
|
||||
slFaktorBlau = new GSlider(this, 1070, 610, 120, 40, 10.0);
|
||||
slFaktorBlau.setShowLimits(true);
|
||||
slFaktorBlau.setLimits(1.0, 0.0, 5.0);
|
||||
slFaktorBlau.setNumberFormat(G4P.DECIMAL, 2);
|
||||
slFaktorBlau.setOpaque(false);
|
||||
slFaktorBlau.addEventHandler(this, "slFaktorBlauChanged");
|
||||
lbFaktorBlau = new GLabel(this, 1060, 600, 80, 20);
|
||||
lbFaktorBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbFaktorBlau.setText("Faktor Blau: ");
|
||||
lbFaktorBlau.setOpaque(false);
|
||||
lbBlau = new GLabel(this, 1140, 600, 50, 20);
|
||||
lbBlau.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
lbBlau.setText("1.0");
|
||||
lbBlau.setOpaque(false);
|
||||
btSpeichern = new GButton(this, 120, 0, 110, 30);
|
||||
btSpeichern.setText("Bild speichern");
|
||||
btSpeichern.addEventHandler(this, "btSpeichernClicked");
|
||||
btRueckgaengig = new GButton(this, 300, 0, 160, 30);
|
||||
btRueckgaengig.setText("Rückgängig");
|
||||
btRueckgaengig.setLocalColorScheme(GCScheme.GOLD_SCHEME);
|
||||
btRueckgaengig.addEventHandler(this, "btRueckgaengigClicked");
|
||||
btOriginal = new GButton(this, 470, 0, 160, 30);
|
||||
btOriginal.setText("Originalbild");
|
||||
btOriginal.addEventHandler(this, "btOriginalClicked");
|
||||
btTupfen = new GButton(this, 120, 760, 110, 30);
|
||||
btTupfen.setText("Bild tupfen");
|
||||
btTupfen.addEventHandler(this, "btTupfenClick");
|
||||
btStricheln = new GButton(this, 390, 760, 120, 30);
|
||||
btStricheln.setText("Bild stricheln");
|
||||
btStricheln.addEventHandler(this, "btStrichelnClick");
|
||||
label1 = new GLabel(this, 0, 700, 130, 20);
|
||||
label1.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label1.setText("Durchmesser Tupfen:");
|
||||
label1.setOpaque(false);
|
||||
tfDurchmesser = new GTextField(this, 80, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfDurchmesser.setText("10");
|
||||
tfDurchmesser.setOpaque(true);
|
||||
label2 = new GLabel(this, 130, 700, 100, 20);
|
||||
label2.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label2.setText("Tupfen-Anzahl:");
|
||||
label2.setOpaque(false);
|
||||
tfTupfAnzahl = new GTextField(this, 180, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfTupfAnzahl.setText("5000");
|
||||
tfTupfAnzahl.setOpaque(true);
|
||||
label3 = new GLabel(this, 260, 700, 80, 20);
|
||||
label3.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label3.setText("Stiftdicke:");
|
||||
label3.setOpaque(false);
|
||||
tfStiftdicke = new GTextField(this, 290, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStiftdicke.setText("5");
|
||||
tfStiftdicke.setOpaque(true);
|
||||
label4 = new GLabel(this, 340, 700, 80, 20);
|
||||
label4.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label4.setText("Strichlänge:");
|
||||
label4.setOpaque(false);
|
||||
tfStrichlaenge = new GTextField(this, 370, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichlaenge.setText("10");
|
||||
tfStrichlaenge.setOpaque(true);
|
||||
label5 = new GLabel(this, 420, 700, 80, 20);
|
||||
label5.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label5.setText("Strichanzahl:");
|
||||
label5.setOpaque(false);
|
||||
tfStrichanzahl = new GTextField(this, 450, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfStrichanzahl.setText("5000");
|
||||
tfStrichanzahl.setOpaque(true);
|
||||
btHSBFarbaenderung = new GButton(this, 760, 760, 120, 30);
|
||||
btHSBFarbaenderung.setText("Farbänderung HSB");
|
||||
btHSBFarbaenderung.addEventHandler(this, "btHSBClick");
|
||||
label6 = new GLabel(this, 530, 700, 110, 20);
|
||||
label6.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label6.setText("Änderung Farbton:");
|
||||
label6.setOpaque(false);
|
||||
tfHSBFarbton = new GTextField(this, 590, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBFarbton.setText("5");
|
||||
tfHSBFarbton.setPromptText(">= 0");
|
||||
tfHSBFarbton.setOpaque(true);
|
||||
label7 = new GLabel(this, 640, 700, 120, 20);
|
||||
label7.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label7.setText("Änderung Sättigung:");
|
||||
label7.setOpaque(false);
|
||||
tfHSBSaettigung = new GTextField(this, 710, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBSaettigung.setText("1");
|
||||
tfHSBSaettigung.setPromptText("0 bis 2");
|
||||
tfHSBSaettigung.setOpaque(true);
|
||||
label8 = new GLabel(this, 760, 700, 120, 20);
|
||||
label8.setTextAlign(GAlign.CENTER, GAlign.MIDDLE);
|
||||
label8.setText("Änderung Helligkeit:");
|
||||
label8.setOpaque(false);
|
||||
tfHSBHelligkeit = new GTextField(this, 830, 720, 50, 30, G4P.SCROLLBARS_NONE);
|
||||
tfHSBHelligkeit.setText("1");
|
||||
tfHSBHelligkeit.setPromptText("0 bis 2");
|
||||
tfHSBHelligkeit.setOpaque(true);
|
||||
btBild2Laden = new GButton(this, 650, 0, 160, 30);
|
||||
btBild2Laden.setText("Zweites Bild laden");
|
||||
btBild2Laden.setLocalColorScheme(GCScheme.GREEN_SCHEME);
|
||||
btBild2Laden.addEventHandler(this, "btBild2LadenClick");
|
||||
btKombinieren = new GButton(this, 1070, 750, 120, 30);
|
||||
btKombinieren.setText("Bilder kombinieren");
|
||||
btKombinieren.setLocalColorScheme(GCScheme.GREEN_SCHEME);
|
||||
btKombinieren.addEventHandler(this, "btKombinierenClick");
|
||||
grKombination = new GToggleGroup();
|
||||
opAddieren = new GOption(this, 1070, 690, 120, 20);
|
||||
opAddieren.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opAddieren.setText("addieren");
|
||||
opAddieren.setOpaque(false);
|
||||
opSubtrahieren = new GOption(this, 1070, 710, 120, 20);
|
||||
opSubtrahieren.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opSubtrahieren.setText("subtrahieren");
|
||||
opSubtrahieren.setOpaque(false);
|
||||
opMultiplizieren = new GOption(this, 1070, 730, 120, 20);
|
||||
opMultiplizieren.setIconAlign(GAlign.LEFT, GAlign.MIDDLE);
|
||||
opMultiplizieren.setText("multiplizieren");
|
||||
opMultiplizieren.setOpaque(false);
|
||||
grKombination.addControl(opAddieren);
|
||||
opAddieren.setSelected(true);
|
||||
grKombination.addControl(opSubtrahieren);
|
||||
grKombination.addControl(opMultiplizieren);
|
||||
btKombiSpeichern = new GButton(this, 1070, 790, 120, 30);
|
||||
btKombiSpeichern.setText("Kombination speichern");
|
||||
btKombiSpeichern.setLocalColorScheme(GCScheme.GREEN_SCHEME);
|
||||
btKombiSpeichern.addEventHandler(this, "btKombiSpeichernClick");
|
||||
}
|
||||
|
||||
// Variable declarations
|
||||
// autogenerated do not edit
|
||||
GButton btSpiegleHorizontal;
|
||||
GToggleGroup grSpiegeln;
|
||||
GOption opHorizontal;
|
||||
GOption opVertikal;
|
||||
GToggleGroup grDrehen;
|
||||
GOption opDreheLinks;
|
||||
GOption opDreheRechts;
|
||||
GButton btDrehen;
|
||||
GButton btInvertieren;
|
||||
GToggleGroup grGraustufen;
|
||||
GOption opMittelwert;
|
||||
GOption opMinimum;
|
||||
GOption opMaximum;
|
||||
GOption opNatuerlich;
|
||||
GOption opHSB;
|
||||
GButton btGraustufen;
|
||||
GButton btBildLaden;
|
||||
GToggleGroup grFaltung;
|
||||
GOption opWeichzeichnen;
|
||||
GOption opSchaerfen;
|
||||
GOption opRelief;
|
||||
GButton btFaltung;
|
||||
GButton btTauschRG;
|
||||
GButton btFarbaenderung;
|
||||
GSlider slFaktorRot;
|
||||
GLabel lbRotFaktor;
|
||||
GLabel lbRot;
|
||||
GSlider slFaktorGruen;
|
||||
GLabel lbFaktorGruen;
|
||||
GLabel lbGruen;
|
||||
GSlider slFaktorBlau;
|
||||
GLabel lbFaktorBlau;
|
||||
GLabel lbBlau;
|
||||
GButton btSpeichern;
|
||||
GButton btRueckgaengig;
|
||||
GButton btOriginal;
|
||||
GButton btTupfen;
|
||||
GButton btStricheln;
|
||||
GLabel label1;
|
||||
GTextField tfDurchmesser;
|
||||
GLabel label2;
|
||||
GTextField tfTupfAnzahl;
|
||||
GLabel label3;
|
||||
GTextField tfStiftdicke;
|
||||
GLabel label4;
|
||||
GTextField tfStrichlaenge;
|
||||
GLabel label5;
|
||||
GTextField tfStrichanzahl;
|
||||
GButton btHSBFarbaenderung;
|
||||
GLabel label6;
|
||||
GTextField tfHSBFarbton;
|
||||
GLabel label7;
|
||||
GTextField tfHSBSaettigung;
|
||||
GLabel label8;
|
||||
GTextField tfHSBHelligkeit;
|
||||
GButton btBild2Laden;
|
||||
GButton btKombinieren;
|
||||
GToggleGroup grKombination;
|
||||
GOption opAddieren;
|
||||
GOption opSubtrahieren;
|
||||
GOption opMultiplizieren;
|
||||
GButton btKombiSpeichern;
|
||||
|
|
@ -0,0 +1,618 @@
|
|||
// Need G4P library
|
||||
import g4p_controls.*;
|
||||
|
||||
|
||||
color[][] pixelNeu; // zweidim. Array für die Pixel des neues Bildes
|
||||
color[][] pixelAlt; // zweidim. Array für die Pixel des alten Bildes
|
||||
color[][] pixelZwei;
|
||||
color[][] pixelKombi;
|
||||
PImage bildAlt, bildNeu, bildOriginal, bildVorher;
|
||||
PImage bildZwei, bildKombi;
|
||||
|
||||
float[][] weichzeichnen = {{1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}, {1.0/9, 1.0/9, 1.0/9}};
|
||||
float[][] schaerfen = {{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}};
|
||||
float[][] relief = {{-2, -1, 0}, {-1, 1, 1}, {0, 1, 2}};
|
||||
|
||||
int x_start = 0; // Position der linken oberen Bildecke bei der Anzeige
|
||||
int y_start = 50;
|
||||
|
||||
boolean bildgewaehlt = false;
|
||||
boolean bild2gewaehlt = false; // für zweites Bild (Blatt 12)
|
||||
|
||||
String dateiname;
|
||||
|
||||
public void setup() {
|
||||
|
||||
size(1200, 850, JAVA2D); // für zweites Bild erweitert auf Blatt 12
|
||||
background(255);
|
||||
createGUI();
|
||||
customGUI();
|
||||
// Place your setup code here
|
||||
bildLaden("kuehe.jpg");
|
||||
}
|
||||
|
||||
void fileSelected(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
bildgewaehlt = true;
|
||||
dateiname = selection.getAbsolutePath();
|
||||
// bildLaden(selection.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
// für Blatt 12 - Bildkombinationen
|
||||
void file2Selected(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
bild2gewaehlt = true;
|
||||
dateiname = selection.getAbsolutePath();
|
||||
// bildLaden(selection.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void fileSelectedSave(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
dateiname = selection.getAbsolutePath();
|
||||
bildNeu.save(dateiname+".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
// für Blatt 12 - Bildkombinationen
|
||||
void kombiFileSelectedSave(File selection) {
|
||||
if (selection == null) {
|
||||
println("Window was closed or the user hit cancel.");
|
||||
} else {
|
||||
println("User selected " + selection.getAbsolutePath());
|
||||
dateiname = selection.getAbsolutePath();
|
||||
bildKombi.save(dateiname+".jpg");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void draw() {
|
||||
if (bildgewaehlt) {
|
||||
bildLaden(dateiname);
|
||||
}
|
||||
if (bild2gewaehlt) {
|
||||
bild2Laden(dateiname);
|
||||
}
|
||||
bildgewaehlt = false;
|
||||
bild2gewaehlt = false;
|
||||
}
|
||||
|
||||
// Use this method to add additional statements
|
||||
// to customise the GUI controls
|
||||
public void customGUI() {
|
||||
}
|
||||
|
||||
public void AnzeigenUndMerken(int x, int y) {
|
||||
// fuer die Anzeige des veränderten Bildes und speichern des Vorgängers
|
||||
// wird nur in Eventhandlern aufgerufen
|
||||
background(255);
|
||||
image(bildNeu, x, y);
|
||||
bildVorher = new PImage(bildNeu.width, bildNeu.height, RGB);
|
||||
bildVorher = bildAlt;
|
||||
bildAlt = bildNeu;
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
|
||||
void bildLaden(String pfad) {
|
||||
bildOriginal = loadImage(pfad);
|
||||
// bildAlt = new PImage(bildOriginal.width, bildOriginal.height, RGB);
|
||||
bildAlt = bildOriginal;
|
||||
image(bildAlt, x_start, y_start); // Anzeige von bildAlt; linke obere Ecke: (0,0)
|
||||
schreibeBildinArray(bildAlt);
|
||||
}
|
||||
|
||||
// zweites Bild laden für Blatt 12 - Bildkombinationen
|
||||
void bild2Laden(String pfad) {
|
||||
bildZwei = loadImage(pfad);
|
||||
image(bildZwei, x_start + bildAlt.width, y_start); // Anzeige von bildZwei neben Bild 1
|
||||
schreibeBildinArray(bildZwei);
|
||||
}
|
||||
|
||||
|
||||
// Methode schreibt die einzelnen Pixel eines Bildes in beide zweidim. Array
|
||||
void schreibeBildinArray(PImage bild) {
|
||||
int breite = bild.width;
|
||||
int hoehe = bild.height;
|
||||
if (bild == bildZwei) {
|
||||
pixelZwei = new color[breite][hoehe];
|
||||
pixelKombi = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelZwei[x][y] = bild.get(x, y);
|
||||
pixelKombi[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pixelAlt = new color[breite][hoehe];
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelAlt[x][y] = bild.get(x, y);
|
||||
pixelNeu[x][y] = bild.get(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
color invertiereFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(255-r, 255-g, 255-b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color tauscheRotGruenFarbanteile(color farbe) {
|
||||
float r = red(farbe);
|
||||
float g = green(farbe);
|
||||
float b = blue(farbe);
|
||||
color neueFarbe = color(g, r, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
color aendereFarbanteile(color farbe, float faktor_r, float faktor_g, float faktor_b) {
|
||||
float r = red(farbe)*faktor_r;
|
||||
if (r>255) {
|
||||
r = 255;
|
||||
} else if (r<0) {
|
||||
r = 0;
|
||||
}
|
||||
float g = green(farbe)*faktor_g ;
|
||||
if (g>255) {
|
||||
g = 255;
|
||||
} else if (g<0) {
|
||||
g = 0;
|
||||
}
|
||||
|
||||
float b = blue(farbe)*faktor_b;
|
||||
if (b>255) {
|
||||
b = 255;
|
||||
} else if (b<0) {
|
||||
b = 0;
|
||||
}
|
||||
|
||||
color neueFarbe = color(r, g, b);
|
||||
return neueFarbe;
|
||||
}
|
||||
|
||||
|
||||
// Methode spiegelt Bild horizontal
|
||||
PImage spiegleHorizontal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-x][y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 10: Methode spiegelt Bild vertikal
|
||||
PImage spiegleVertikal(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[x][hoehe-1-y];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 15: Methode dreht Bild nach links
|
||||
PImage dreheLinks(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[breite-1-y][x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Aufgabe 16: Methode dreht Bild nach rechts
|
||||
PImage dreheRechts(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[hoehe][breite];
|
||||
PImage neuesBild = createImage(hoehe, breite, RGB);
|
||||
for (int x = 0; x < hoehe; x++) {
|
||||
for (int y = 0; y < breite; y++) {
|
||||
pixelNeu[x][y]= pixelAlt[y][hoehe-1-x];
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
// Methode bestimmt Mittelwert der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenDurchschnitt(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = (r+g+b)/3;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Minimum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMin(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = min(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Maximum der Farbwerte, liefert Bild in Graustufen
|
||||
PImage graustufenMax(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = max(r, g, b);
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode bestimmt Graustufe mit gewichteten Farbanteilen
|
||||
PImage graustufenNatuerlich(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
float m = 0;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
r = red(pixelAlt[x][y]); // Rotanteil des Pixels
|
||||
g = green(pixelAlt[x][y]); // Gruenanteil des Pixels
|
||||
b = blue(pixelAlt[x][y]); // Blauanteil des Pixels
|
||||
m = 0.299*r + 0.587*g + 0.114*b;
|
||||
pixelNeu[x][y]= color(m);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 9: HSB-Farbmodell - Graustufen
|
||||
PImage graustufenHSB(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
colorMode(HSB, 360, 100, 100);
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
float h = hue(pixelAlt[x][y]); // Farbton wird übernommen
|
||||
float s = 0; // Sättigung wird auf 0 gesetzt
|
||||
float b = brightness(pixelAlt[x][y]); // Helligkeit wird übernommen
|
||||
pixelNeu[x][y]= color(int(h), int(s), int(b));
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
// zurücksetzen Farbmodus:
|
||||
colorMode(RGB, 255, 255, 255);
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 9: Farbänderung HSB
|
||||
PImage farbaenderungHSB(PImage originalbild, float dHue, float fSaturation, float fBrightness) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
colorMode(HSB, 360, 100, 100);
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
float h = hue(pixelAlt[x][y]) + dHue;
|
||||
float s = saturation(pixelAlt[x][y]) * fSaturation;
|
||||
float b = brightness(pixelAlt[x][y]) * fBrightness;
|
||||
if (s>100) s = 100;
|
||||
if (s< 0) s = 0;
|
||||
if (b>100) b = 100;
|
||||
if (b<0) b = 0;
|
||||
pixelNeu[x][y]= color(int(h), int(s), int(b));
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
// zurücksetzen Farbmodus:
|
||||
colorMode(RGB, 255, 255, 255);
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Methode invertiert Farbanteile und gibt verändertes Bild aus
|
||||
PImage invertiere(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= invertiereFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage tauscheRotGruen(PImage originalbild) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= tauscheRotGruenFarbanteile(pixelAlt[x][y]);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode tauscht rote und grüne Farbanteile und gibt verändertes Bild aus
|
||||
PImage farbaenderung(PImage originalbild, float faktor_r, float faktor_g, float faktor_b) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = 0; x < breite; x++) {
|
||||
for (int y = 0; y < hoehe; y++) {
|
||||
pixelNeu[x][y]= aendereFarbanteile(pixelAlt[x][y], faktor_r, faktor_g, faktor_b);
|
||||
neuesBild.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Schreiben der Methoden aus den Aufgaben 1 bis 3
|
||||
|
||||
PImage faltung(PImage originalbild, float[][] filter) {
|
||||
// Größe der Filtermatrix bestimmen
|
||||
int laenge = filter.length;
|
||||
int halb = laenge / 2;
|
||||
|
||||
// Erzeuge neues Bild
|
||||
PImage bild_neu = createImage(originalbild.width, originalbild.height, RGB);
|
||||
|
||||
// Faltung berechnen
|
||||
// Schleife über alle Spalten
|
||||
for (int x = halb; x<originalbild.width-halb; x++) {
|
||||
// Schleife über alle Zeilen
|
||||
for (int y = halb; y<originalbild.height-halb; y++) {
|
||||
// Deklarieren der neuen Farbkomponenten
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
//Koordinaten des Pixels links oben in der Ecke der Filtermatrix
|
||||
int xx = x - halb;
|
||||
int yy = y - halb;
|
||||
//Schleifen über jeden Punkt der Filtermatrix
|
||||
for (int i =0; i<laenge; i++) {
|
||||
for (int j=0; j<laenge; j++) {
|
||||
// Summiere die gewichteten Farbkomponenten der Originalpixel
|
||||
rot += filter[i][j] * red(pixelAlt[xx+i][yy+j]);
|
||||
gruen += filter[i][j] * green(pixelAlt[xx+i][yy+j]);
|
||||
blau += filter[i][j] * blue(pixelAlt[xx+i][yy+j]);
|
||||
}
|
||||
}
|
||||
// Begrenzung auf zulässigen Bereich
|
||||
if (rot < 0.0) rot = 0.0;
|
||||
if (rot > 255.0) rot = 255.0;
|
||||
if (gruen < 0.0) gruen = 0.0;
|
||||
if (gruen > 255.0) gruen = 255.0;
|
||||
if (blau < 0.0) blau = 0.0;
|
||||
if (blau > 255.0) blau = 255.0;
|
||||
|
||||
// Definiere Farbe des neuen Pixels
|
||||
pixelNeu[x][y] = color((int)rot, (int)gruen, (int)blau);
|
||||
bild_neu.set(x, y, pixelNeu[x][y]);
|
||||
}
|
||||
}
|
||||
return bild_neu;
|
||||
}
|
||||
|
||||
// Blatt 8 - Tupfen und Stricheln
|
||||
// Methode ermöglicht Tupfen von Bildern
|
||||
PImage tupfen(PImage originalbild, int groesse, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
noStroke();
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = groesse/2 + int(random(breite-groesse));
|
||||
int y = groesse/2 + int(random(hoehe-groesse));
|
||||
fill(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
ellipse(x + x_start, y + y_start, groesse, groesse);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Methode ermöglicht Stricheln von Bildern
|
||||
PImage stricheln(PImage originalbild, int dicke, int laenge, int anzahl) {
|
||||
int breite = originalbild.width;
|
||||
int hoehe = originalbild.height;
|
||||
|
||||
for (int i = 0; i < anzahl; i++) {
|
||||
int x = laenge/2 + int(random(breite-laenge));
|
||||
int y = laenge/2 + int(random(hoehe-laenge));
|
||||
stroke(red(pixelAlt[x][y]), green(pixelAlt[x][y]), blue(pixelAlt[x][y]));
|
||||
strokeWeight(dicke);
|
||||
// mit Pythagoras
|
||||
int schritt = round(laenge / sqrt(2));
|
||||
line(x + x_start, y + y_start, x + x_start+schritt, y + y_start - schritt);
|
||||
}
|
||||
// Pixel der Oberfläche in neues Bild übertragen, da das Bild ja nur übermalt wurde
|
||||
pixelNeu = new color[breite][hoehe];
|
||||
PImage neuesBild = createImage(breite, hoehe, RGB);
|
||||
for (int x = x_start; x < x_start+breite; x++) {
|
||||
for (int y = y_start; y < y_start+hoehe; y++) {
|
||||
pixelNeu[x-x_start][y-y_start] = get(x, y);
|
||||
neuesBild.set(x-x_start, y-y_start, pixelNeu[x-x_start][y-y_start]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
// Blatt 12 - Bildkombinationen
|
||||
PImage addition(PImage bild1, PImage bild2) {
|
||||
int b_min = min(bild1.width, bild2.width);
|
||||
int h_min = min(bild1.height, bild1.height);
|
||||
|
||||
float rot = 255;
|
||||
float gruen = 255;
|
||||
float blau = 255;
|
||||
|
||||
pixelKombi = new color[b_min][h_min];
|
||||
PImage neuesBild = createImage(b_min, h_min, RGB);
|
||||
for (int i = 0; i< b_min; i++) {
|
||||
for (int j = 0; j < h_min; j++) {
|
||||
|
||||
rot = red(bild1.get(i, j))+red(bild2.get(i, j));
|
||||
gruen = green(bild1.get(i, j))+green(bild2.get(i, j));
|
||||
blau = blue(bild1.get(i, j))+blue(bild2.get(i, j));
|
||||
|
||||
if (rot > 255) rot = 255;
|
||||
if (gruen > 255) gruen = 255;
|
||||
if (blau > 255) blau = 255;
|
||||
|
||||
|
||||
pixelKombi[i][j] = color((int)rot, (int)gruen, (int)blau);
|
||||
neuesBild.set(i, j, pixelKombi[i][j]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
PImage subtraktion(PImage bild1, PImage bild2) {
|
||||
int b_min = min(bild1.width, bild2.width);
|
||||
int h_min = min(bild1.height, bild1.height);
|
||||
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
|
||||
pixelKombi = new color[b_min][h_min];
|
||||
PImage neuesBild = createImage(b_min, h_min, RGB);
|
||||
for (int i = 0; i< b_min; i++) {
|
||||
for (int j = 0; j < h_min; j++) {
|
||||
|
||||
rot = red(bild1.get(i, j))-red(bild2.get(i, j));
|
||||
gruen = green(bild1.get(i, j))-green(bild2.get(i, j));
|
||||
blau = blue(bild1.get(i, j))-blue(bild2.get(i, j));
|
||||
|
||||
if (rot < 0) rot = 0;
|
||||
if (gruen < 0) gruen = 0;
|
||||
if (blau < 0) blau = 0;
|
||||
|
||||
|
||||
pixelKombi[i][j] = color((int)rot, (int)gruen, (int)blau);
|
||||
neuesBild.set(i, j, pixelKombi[i][j]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
|
||||
PImage multiplikation(PImage bild1, PImage bild2) {
|
||||
int b_min = min(bild1.width, bild2.width);
|
||||
int h_min = min(bild1.height, bild1.height);
|
||||
|
||||
float rot = 0;
|
||||
float gruen = 0;
|
||||
float blau = 0;
|
||||
|
||||
pixelKombi = new color[b_min][h_min];
|
||||
PImage neuesBild = createImage(b_min, h_min, RGB);
|
||||
for (int i = 0; i< b_min; i++) {
|
||||
for (int j = 0; j < h_min; j++) {
|
||||
|
||||
rot = (red(bild1.get(i, j))*(red(bild2.get(i, j)))/255);
|
||||
gruen = (green(bild1.get(i, j))*green(bild2.get(i, j)))/255;
|
||||
blau = (blue(bild1.get(i, j))*blue(bild2.get(i, j)))/255;
|
||||
|
||||
pixelKombi[i][j] = color((int)rot, (int)gruen, (int)blau);
|
||||
neuesBild.set(i, j, pixelKombi[i][j]);
|
||||
}
|
||||
}
|
||||
return neuesBild;
|
||||
}
|
||||
16
6_processing_variante/readme.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
Es gibt zu allen grundlegenden Bildoperationen Arbeitsblätter und Lösungen,
|
||||
die für Processing angepasst wurden:
|
||||
01 - Bilder als Array
|
||||
02 - Farbmodell
|
||||
03 - Faltung
|
||||
04 - Faltung/Puzzle
|
||||
05 - GUI mit Aufnahme aller bisherigen Bildoperationen
|
||||
|
||||
Zusätzlich gibt es zu folgenden Erweiterungen Arbeitsblätter und Lösungen:
|
||||
08 - Stricheln und Tupfen
|
||||
09 - HSB-Farbmodell
|
||||
12 - Bildkombinationen
|
||||
(Hier wird jeweils auf der vorherigen Version aufgebaut bzw. diese ergänzt.)
|
||||
|
||||
In den Lösungen müssen die Bilder aus der Vorlage hinzugefügt werden. Die Informationen über die Bildrechte liegen in den Processing-Ordnern im Ordner data.
|
||||
|
||||