aboutsummaryrefslogtreecommitdiffstats
path: root/bin/img2list.py
blob: 48d0de46aaaf143f3ece370e62a96bee34b9df35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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)