summaryrefslogtreecommitdiff
path: root/Year_2/IandM/histogram
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-16 21:51:54 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-16 21:51:54 +0100
commit321b268bb74512289f9eb361560e8ceb9d30fe59 (patch)
treeb5ddb9ab187a952891fc2f988fb47088fc03a5f9 /Year_2/IandM/histogram
parent67438312a69f7b7aa1fdbc27610438897791ceef (diff)
i&m: add operations
Diffstat (limited to 'Year_2/IandM/histogram')
-rw-r--r--Year_2/IandM/histogram/data/lena.pngbin0 -> 473831 bytes
-rw-r--r--Year_2/IandM/histogram/histogram.pde33
2 files changed, 33 insertions, 0 deletions
diff --git a/Year_2/IandM/histogram/data/lena.png b/Year_2/IandM/histogram/data/lena.png
new file mode 100644
index 0000000..59ef68a
--- /dev/null
+++ b/Year_2/IandM/histogram/data/lena.png
Binary files differ
diff --git a/Year_2/IandM/histogram/histogram.pde b/Year_2/IandM/histogram/histogram.pde
new file mode 100644
index 0000000..58f365a
--- /dev/null
+++ b/Year_2/IandM/histogram/histogram.pde
@@ -0,0 +1,33 @@
+void setup() {
+ size(256, 256);
+ PImage img = loadImage("lena.png");
+ img.resize(256, 256);
+ img.filter(GRAY);
+
+ image(img, 0, 0);
+ float[] hist = histogram(img);
+ for(int i = 0; i < 256; ++i) {
+ println(i, hist[i]);
+ }
+}
+
+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;
+}