diff --git a/script/cpython/image_functions.py b/script/cpython/image_functions.py new file mode 100644 index 0000000..1b09af6 --- /dev/null +++ b/script/cpython/image_functions.py @@ -0,0 +1,18 @@ +import numpy + +def img_get_int(fname, header, width, height, depth, x1,y1,x2,y2, bx1,by1,bx2,by2 ): + # read actual image file + img = numpy.fromfile(fname, dtype=numpy.uint32) + img.shape = height, width + # signal roi + area_I = ( x2 - x1 + 1) * ( y2 - y1 + 1) + I_sum = img[y1:y2, x1:x2].sum() + thresh1_count = len(numpy.where(img>thres1)[0]) + thresh2_count = len(numpy.where(img>thres2)[0]) + thresh3_count = len(numpy.where(img>thres3)[0]) + thresh4_count = len(numpy.where(img>thres4)[0]) + + # background roi + I_sum_bgr = img[by1:by2, bx1:bx2].sum() + area_bgr= (bx2 - bx1 + 1) * (by2 - by1 + 1) + return (I_sum, area_I, thresh1_count, thresh2_count, thresh3_count, thresh4_count, I_sum_bgr, area_bgr) \ No newline at end of file diff --git a/script/cpython/wrapper.py b/script/cpython/wrapper.py new file mode 100644 index 0000000..65cbc7d --- /dev/null +++ b/script/cpython/wrapper.py @@ -0,0 +1,11 @@ +from jeputils import * + +def img_get_int(fname, header, width, height, depth, x1,y1,x2,y2, bx1,by1,bx2,by2 ): + ret = call_jep("CPython/image_functions", "img_get_int", [fname, header, width, height, depth, x1,y1,x2,y2, bx1,by1,bx2,by2]) + return ret + + + +#def hfitoff(data, xdeg): +# ret = call_jep("CPython/hfitoff", "hfitoff", [to_npa(data),to_npa(xdeg)]) +# return (ret[0], ret[1], ret[2],ret[3], ret[4].data, ret[5].data) diff --git a/script/image_get_int.py b/script/image_get_int.py new file mode 100644 index 0000000..a89a1c5 --- /dev/null +++ b/script/image_get_int.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +import sys + +# parse aguments +# image info file +# threshold 1 +# threshold 2 +# threshold 3 +# threshold 4 +# median filter +# filter nsigma +info = sys.argv[1] +thres1 = int(sys.argv[2]) +thres2 = int(sys.argv[3]) +thres3 = int(sys.argv[4]) +thres4 = int(sys.argv[5]) + +filter_median = False +if len(sys.argv) > 6 and sys.argv[6] == '-median': + filter_median = True + +filter_nsigma = 0.0 +if len(sys.argv) > 7: + filter_nsigma = float(sys.argv[7]) + +# read image info text file +f = open(info) + +fname = f.next().strip() +timestamp = f.next().strip() +header = f.next().strip() +width, height, depth = [int(p) for p in f.next().strip().split()] +x1,y1,x2,y2 = [int(p) for p in f.next().strip().split()] +bx1,by1,bx2,by2 = [int(p) for p in f.next().strip().split()] + +f.close() + +# read actual image file +import numpy +img = numpy.fromfile(fname, dtype=numpy.uint32) +img.shape = height, width + +# signal roi +area_I = ( x2 - x1 + 1) * ( y2 - y1 + 1) + +I_sum = img[y1:y2, x1:x2].sum() +thresh1_count = len(numpy.where(img>thres1)[0]) +thresh2_count = len(numpy.where(img>thres2)[0]) +thresh3_count = len(numpy.where(img>thres3)[0]) +thresh4_count = len(numpy.where(img>thres4)[0]) + +# background roi +I_sum_bgr = img[by1:by2, bx1:bx2].sum() +area_bgr= (bx2 - bx1 + 1) * (by2 - by1 + 1) + +set_return ((I_sum, area_I, thresh1_count, thresh2_count, thresh3_count, thresh4_count, I_sum_bgr, area_bgr)) + +