diff options
Diffstat (limited to 'Year_2/IandM/stretching')
-rw-r--r-- | Year_2/IandM/stretching/data/lena.png | bin | 0 -> 473831 bytes | |||
-rw-r--r-- | Year_2/IandM/stretching/stretching.pde | 32 |
2 files changed, 32 insertions, 0 deletions
diff --git a/Year_2/IandM/stretching/data/lena.png b/Year_2/IandM/stretching/data/lena.png Binary files differnew file mode 100644 index 0000000..59ef68a --- /dev/null +++ b/Year_2/IandM/stretching/data/lena.png diff --git a/Year_2/IandM/stretching/stretching.pde b/Year_2/IandM/stretching/stretching.pde new file mode 100644 index 0000000..0814190 --- /dev/null +++ b/Year_2/IandM/stretching/stretching.pde @@ -0,0 +1,32 @@ +void setup() { + size(512, 256); + PImage img = loadImage("lena.png"); + img.resize(256, 256); + img.filter(GRAY); + + image(img, 0, 0); + image(stretching(img), 256, 0); +} + +PImage stretching(PImage I) { + PImage out = I.copy(); + out.loadPixels(); + + float max = red(out.pixels[0]); + float min = max; + + for (int i = 0; i < out.pixels.length; ++i) { + float t = red(out.pixels[i]); + if (t < min) + min = t; + if (t > max) + max = t; + } + + for (int i = 0; i < out.pixels.length; ++i) { + out.pixels[i]= color(255*(red(out.pixels[i])-min)/(max-min)); + } + + out.updatePixels(); + return out; +} |