From 62f0b16f639a9ecb116a79819655bdf44e269443 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 16 May 2016 21:55:52 +0300 Subject: Initial commit Signed-off-by: Laurent Pinchart --- scripts/histo2png.py | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100755 scripts/histo2png.py (limited to 'scripts/histo2png.py') diff --git a/scripts/histo2png.py b/scripts/histo2png.py new file mode 100755 index 0000000..ff1da21 --- /dev/null +++ b/scripts/histo2png.py @@ -0,0 +1,81 @@ +#!/usr/bin/python + +import matplotlib.pyplot as plt +import struct +import sys + + +def usage(argv0): + print 'Usage: %s ' % argv0 + + +def main(argv): + + if len(argv) != 2: + usage(argv[0]) + return 1 + + data = file(argv[1], 'rb').read() + + if len(data) == (2 + 64) * 4 or len(data) == (2 + 256) * 4: + maxmin = struct.unpack('> 0) & 0xff, (maxmin[0] >> 16) & 0xff, sums[0]) + + print 'pixels (%u)' % sum(histo) + + plt.figure(figsize=(10, 10)) + plt.xlim([0, num_bins]) + plt.ylim([0, max(histo)]) + plt.bar(range(num_bins), histo, color='r'); + + elif len(data) == (6 + 64 * 3) * 4: + maxmin = struct.unpack('> 0) & 0xff, (maxmin[1] >> 0) & 0xff, (maxmin[2] >> 0) & 0xff, + (maxmin[0] >> 16) & 0xff, (maxmin[1] >> 16) & 0xff, (maxmin[2] >> 16) & 0xff, + sums[0], sums[1], sums[2]) + + print 'pixels RGB (%u,%u,%u)' % (sum(histo_r), sum(histo_g), sum(histo_b)) + + plt.figure(figsize=(10, 20)) + plt.subplot(3, 1, 1) + plt.xlim([0, num_bins]) + plt.ylim([0, max(histo_r)]) + plt.bar(range(num_bins), histo_r, color='r'); + plt.subplot(3, 1, 2) + plt.xlim([0, num_bins]) + plt.ylim([0, max(histo_g)]) + plt.bar(range(num_bins), histo_g, color='g'); + plt.subplot(3, 1, 3) + plt.xlim([0, num_bins]) + plt.ylim([0, max(histo_b)]) + plt.bar(range(num_bins), histo_b, color='b'); + + else: + print 'Invalid histogram length %u' % len(data) + return 1 + + plt.suptitle(title) + plt.savefig(argv[1].replace('bin', 'png'), dpi=72) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv)) + -- cgit v1.2.3