aboutsummaryrefslogtreecommitdiffstats
path: root/bin/img2list.py
diff options
context:
space:
mode:
Diffstat (limited to 'bin/img2list.py')
-rw-r--r--bin/img2list.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/img2list.py b/bin/img2list.py
new file mode 100644
index 0000000..48d0de4
--- /dev/null
+++ b/bin/img2list.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+#
+# Aaron LI
+# 2015/06/23
+#
+
+
+import numpy as np
+from astropy.io import fits
+
+
+def img2list(imgdata, mask=None):
+ """
+ Convert a image matrix to list of point coordinates.
+ The input image matrix is taken as an integer matrix.
+ If one pixel has value n (>1), then it is repeated n times.
+ """
+ img = imgdata.astype(int)
+ points = []
+ ii, jj = np.nonzero(img >= 1)
+ while len(ii) > 0:
+ for i, j in zip(ii, jj):
+ points.append([i, j])
+ img[ii, jj] -= 1
+ ii, jj = np.nonzero(img >= 1)
+ return np.array(points)
+