File:Integral image example.png

Summary

Description Integral image (right half) of a 2-bit greyscale pixel art (left half), normalised for visibility, by CMG Lee.
Source Own work
Author Cmglee
Display like so:
Integral image (right half) of a 2-bit greyscale pixel art (left half), normalised and magnified for visibility
Category:Four-color pixel art Category:Image processing

Python script to generate image with png.py

#!/usr/bin/env python
data = '''\
    +++++
  +++:+++++
 +++::::+++
 ++:::@@@+++
 +@@::+@.@++
  +@::::::+++
  +:+:::::++++
  +::@+::++++
 +++::::++++++
 +++++::::..++
  ++.::::....++
   ......::..
    :....::.
    :...::++
   +:::::++++
  +++::.++++++
  +:.....:++++
  ..:++:....:++
 ..:@@+++@@:...
.:@@++@@@++@@@:.'''
maps   = {' ':0,'@':0,'+':1,':':2,'.':3}
datass = [[maps[char] for char in (row + '       ')[:16][::-1]] for row in data.split('\n')]
height = len(datass)
width  = len(datass[0]) * 2
pixels = [0] * (width * height)
import  png, copy
integralss = copy.deepcopy(datass)

def draw_pixel(pixels, width, x, y, luma): pixels[width * y + x] = luma
def tabbify(cellss, separator='|'):
 cellpadss = [list(rows) + [''] * (len(max(cellss, key=len)) - len(rows)) for rows in cellss]
 fmts = ['%%%ds' % (max([len(str(cell)) for cell in cols])) for cols in zip(*cellpadss)]
 return '\n'.join([separator.join(fmts) % tuple(rows) for rows in cellpadss])

for  (y, datas) in enumerate(datass):
 for (x, data ) in enumerate(datas ):
  integralss[y][x] = (data
   + (0 if y < 1          else integralss[y - 1][x    ])
   + (0 if          x < 1 else integralss[y    ][x - 1])
   - (0 if y < 1 or x < 1 else integralss[y - 1][x - 1]))
integral_max = max(max(integralss))
print(tabbify(integralss))
print(integral_max)
for  (y, datas) in enumerate(datass):
 for (x, data ) in enumerate(datas ):
  draw_pixel(pixels, width, x             , y, data * 85)
  draw_pixel(pixels, width, x + width // 2, y, 255 * integralss[y][x] // integral_max)
png.Writer(width=width, height=height, alpha=False, greyscale=True).write_array(
 open('%s.png' % (__file__[:__file__.rfind('.')]), 'wb'), pixels)

Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Integral%20image%20example.png
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
Category:License migration redundant#Integral%20image%20example.pngCategory:GFDL#Integral%20image%20example.png
You may select the license of your choice.
Category:Self-published work
Category:CC-BY-SA-4.0 Category:Four-color pixel art Category:GFDL Category:Image processing Category:License migration redundant Category:Self-published work