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