diff options
Diffstat (limited to 'Year_2/IandM/logarithm')
-rw-r--r-- | Year_2/IandM/logarithm/data/lena.png | bin | 0 -> 473831 bytes | |||
-rw-r--r-- | Year_2/IandM/logarithm/logarithm.pde | 26 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Year_2/IandM/logarithm/data/lena.png b/Year_2/IandM/logarithm/data/lena.png Binary files differnew file mode 100644 index 0000000..59ef68a --- /dev/null +++ b/Year_2/IandM/logarithm/data/lena.png diff --git a/Year_2/IandM/logarithm/logarithm.pde b/Year_2/IandM/logarithm/logarithm.pde new file mode 100644 index 0000000..5fe02e7 --- /dev/null +++ b/Year_2/IandM/logarithm/logarithm.pde @@ -0,0 +1,26 @@ +void setup() { + size(512, 256); + PImage img = loadImage("lena.png"); + img.resize(256, 256); + + image(img, 0, 0); + image(logarithm(img, 100), 256, 0); +} + +PImage logarithm(PImage I, int k) { + PImage out = I.copy(); + out.loadPixels(); + float r, g, b; + float C = k/log(256); + + for (int i = 0; i < out.pixels.length; ++i) { + r= C*log(1+red(out.pixels[i])); + g= C*log(1+green(out.pixels[i])); + b= C*log(1+blue(out.pixels[i])); + + out.pixels[i] = color(r, g, b); + } + + out.updatePixels(); + return out; +} |