Last active
December 25, 2015 19:59
-
-
Save celoyd/7031645 to your computer and use it in GitHub Desktop.
World’s simplest band correlation visualizer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Simple script to scatterplot one band's values over another's into a third image. | |
# Usagi Yojimbo: corr.py band_1.tif band_2.tif 2_v_3.tif | |
# This is for quick testing; don't use it in place of proper statistics. | |
# It may overflow, will fail if the inputs are not identically formatted, etc. | |
# You may have to scale up the output (perhaps by increasing gamma). | |
import Image | |
from sys import argv | |
A = Image.open(argv[1]) | |
B = Image.open(argv[2]) | |
a, b = A.load(), B.load() | |
w, h = A.size | |
depth = 2**8 # assume the inputs are 8-bit by default | |
if A.mode == 'I;16': depth = 2**16 # check for 16-bit | |
C = Image.new('I;16', (depth, depth)) | |
c = C.load() | |
for y in range(h): | |
for x in range(w): | |
c[a[x, y], b[x, y]] += 1 # can overflow | |
C.save(argv[3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment