summaryrefslogtreecommitdiff
path: root/Year_2/IandM/gamma
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2/IandM/gamma')
-rw-r--r--Year_2/IandM/gamma/data/lena.pngbin0 -> 473831 bytes
-rw-r--r--Year_2/IandM/gamma/gamma.pde26
2 files changed, 26 insertions, 0 deletions
diff --git a/Year_2/IandM/gamma/data/lena.png b/Year_2/IandM/gamma/data/lena.png
new file mode 100644
index 0000000..59ef68a
--- /dev/null
+++ b/Year_2/IandM/gamma/data/lena.png
Binary files differ
diff --git a/Year_2/IandM/gamma/gamma.pde b/Year_2/IandM/gamma/gamma.pde
new file mode 100644
index 0000000..8317e75
--- /dev/null
+++ b/Year_2/IandM/gamma/gamma.pde
@@ -0,0 +1,26 @@
+void setup() {
+ size(512, 256);
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+
+ image(img, 0, 0);
+ image(gamma(img, 2), 256, 0);
+}
+
+PImage gamma(PImage I, float gm) {
+ PImage out = I.copy();
+ out.loadPixels();
+ float r, g, b;
+ float C = 1 / pow(255, gm-1);
+
+ for (int i = 0; i < out.pixels.length; ++i) {
+ r= C*pow(red(out.pixels[i]), gm);
+ g= C*pow(green(out.pixels[i]), gm);
+ b= C*pow(blue(out.pixels[i]), gm);
+
+ out.pixels[i] = color(r, g, b);
+ }
+
+ out.updatePixels();
+ return out;
+}