Skip to content

Instantly share code, notes, and snippets.

@sevas
Created November 27, 2010 21:00
Show Gist options
  • Save sevas/718264 to your computer and use it in GitHub Desktop.
Save sevas/718264 to your computer and use it in GitHub Desktop.
from __future__ import division
import numpy as np
from scipy.weave import inline, converters
def load_data(filename):
zbuf = np.fromfile(filename, dtype=np.float32, count=128*128*4)
zbuf.shape = (128,128)
return zbuf
def threshold(buf, t):
nx, ny = buf.shape
code = """
double tmp;
for (int i=0; i<nx; ++i) {
for (int j=0; j<ny; ++j) {
if(buf(i,j) < t)
{
buf(i, j) = 0.0f;
}
}
}
"""
inline(code,
['buf', 't', 'nx', 'ny'],
type_converters=converters.blitz,
compiler = 'gcc')
if __name__ == '__main__':
buf = load_data("zbuf.dat")
print buf.shape
res = threshold(buf, 200)
print buf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment