def turnLightBlobsToParams()

in ParametricLights.py [0:0]


def turnLightBlobsToParams(all_lights, I):
    height, width = np.shape(I)[0:2]
    mx = int(np.amax(all_lights))
    lights = []

    for i in range(1, mx + 1):
        my_lights = 0 * all_lights.copy()
        my_lights[all_lights == i] = 1
        contours, _ = cv2.findContours(my_lights.astype(np.uint8), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        for c in contours:
            # find the centroid and axis of this light blob
            if len(c) > 5:
                (lx, ly), (mja, mna), angle = cv2.fitEllipse(c)
                if lx < 0 or ly < 0 or lx > width or ly > height:
                    (lx, ly), crad = cv2.minEnclosingCircle(c)
                    mja = mna = crad

            else:
                lx, ly = np.squeeze(np.mean(c, axis=0))
                mja = 1.0
                mna = 1.0

            mask = np.tile(np.expand_dims(my_lights, -1), (1, 1, 3))
            colr = np.sum(I * mask, axis=(0, 1)) / np.sum(mask[:, :, 0])
            el = (ly + 1.0) * 1.0 / height * np.pi
            az = (1.0 - (lx + 1.0) * 1.0 / (2.0 * height)) * 2.0 * np.pi
            xx = np.sin(el) * np.cos(az)
            yy = np.sin(el) * np.sin(az)
            zz = np.cos(el)
            sz = np.arccos(mja / mna)
            if sz == 0:
                sz = 2 * np.pi / (width * width)
            lights.append(([lx, ly, mja, mna,0], [el, az], [xx, yy, zz, sz], colr))

    return lights