numpy.int0

Here are the examples of the python api numpy.int0 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

Example 1

Project: EyeTab Source File: draw_utils.py
def draw_eyelids(eyelid_t, eyelid_b, eye_img):
    
    """ Draws the parabola for top eyelid and line for bottom eyelid (if they exist)
    """
    
    if eyelid_t is not None:
        a, b, c = eyelid_t
        lid_xs = [x * eye_img.shape[1] / 20 for x in range(21)]
        lid_ys = [a * x ** 2 + b * x + c for x in lid_xs]
        pts_as_array = np.array([[x, y] for (x, y) in zip(lid_xs, lid_ys)], np.int0)
        cv2.polylines(eye_img, [pts_as_array], False, (0, 255, 0))
    if eyelid_b is not None:
        a, b = eyelid_b
        start_pt, end_pt = (0, int(b)), (eye_img.shape[1], int(a * eye_img.shape[1] + b))
        cv2.line(eye_img, start_pt, end_pt, (0, 255, 0))

Example 2

Project: neupy Source File: kohonen.py
Function: predict
    def predict(self, input_data):
        raw_output = self.predict_raw(input_data)
        output = np.zeros(raw_output.shape, dtype=np.int0)
        max_args = raw_output.argmax(axis=1)
        output[range(raw_output.shape[0]), max_args] = 1
        return output

Example 3

Project: katarina Source File: navbox.py
def detectRoundel( frame, debug=False ):
    global g_mser
    global THRESHOLD_FRACTION
    if g_mser == None:
        g_mser = cv2.MSER( _delta = 10, _min_area=100, _max_area=300*50*2 )
    gray = cv2.cvtColor( frame, cv2.COLOR_BGR2GRAY )
    contours = g_mser.detect(gray, None)
    rectangles = []
    circles = []
    for cnt in contours:
        rect = cv2.minAreaRect(cnt)
        area = len(cnt) # MSER returns all points within area, not boundary points
        rectangleArea = float(rect[1][0]*rect[1][1])
        rectangleAspect = max(rect[1][0], rect[1][1]) / float(min(rect[1][0], rect[1][1]))
        if area/rectangleArea > 0.70 and rectangleAspect > 3.0:
            (x,y),(w,h),angle = rect
            rectangles.append( ((int(x+0.5),int(y+0.5)), (int(w+0.5),int(h+0.5)), int(angle)) )
        cir = cv2.minEnclosingCircle(cnt)
        (x,y),radius = cir
        circleArea = math.pi*radius*radius
        if area/circleArea > 0.64:
            circles.append( ((int(x+0.5),int(y+0.5)),int(radius+0.5)) )
    rectangles = removeDuplicities( rectangles )
    result = matchCircRect( circles=circles, rectangles=rectangles )
    if debug:
        for rect in rectangles:
            box = cv2.cv.BoxPoints(rect)
            box = np.int0(box)
            cv2.drawContours( frame,[box],0,(255,0,0),2)
        for cir in circles:
            (x,y),radius = cir
            center = (int(x),int(y))
            radius = int(radius)
            cv2.circle(frame, center, radius, (0,255,0), 2)
        if result:
            (x1,y1),(x2,y2) = result
            cv2.line(frame, (int(x1),int(y1)), (int(x2),int(y2)), (0,0,255), 3)
    return result

Example 4

Project: cgat Source File: gff_compare.py
Function: old
def Old():

    ref_nucleotides = numpy.zeros(max_end - min_start, numpy.int0)
    target_nucleotides = numpy.zeros(max_end - min_start, numpy.int0)

    # set range overlapping by reference
    for x in targets:
        target_nucleotides[x.start - min_start:x.end - min_start] = 1

    for x in references:
        ref_nucleotides[x.start - min_start:x.end - min_start] = 1

    not_ref = numpy.logical_not(ref_nucleotides)
    not_target = numpy.logical_not(target_nucleotides)

    v = numpy.logical_and(ref_nucleotides, target_nucleotides)
    tp = numpy.dot(v, v)

    v = numpy.logical_and(ref_nucleotides, not_target)
    fn = numpy.dot(v, v)

    v = numpy.logical_and(not_ref, target_nucleotides)
    fp = numpy.dot(v, v)

    v = numpy.logical_and(not_ref, not_target)
    tn = numpy.dot(v, v)

Example 5

Project: cgat Source File: gff_compare.py
def AnalyseOverlaps(references, targets):
    """calculate nucleotide overlap.

    All references and targets should be on the same chromsome.
    Name and strand are not checked.
    """

    if len(references) == 0 or len(targets) == 0:
        return((0, 0, 0, 0))

    targets_start = min([x.start for x in targets])
    targets_end = max([x.end for x in targets])

    refs_start = min([x.start for x in references])
    refs_end = max([x.end for x in references])

    min_start = min(targets_start, refs_start)
    max_end = max(targets_end, refs_end)

    nucleotides = numpy.zeros(max_end - min_start, numpy.int0)

    # set ranges: bit 0: target, bit 1: reference
    for x in targets[:100]:
        nucleotides[x.start - min_start:x.end - min_start] = 1

    for x in references[:100]:
        nucleotides[x.start - min_start:x.end - min_start] = \
            numpy.array([2] * (x.end - x.start), numpy.int0)

    tp = GetCounts(nucleotides, 3)
    fp = GetCounts(nucleotides, 1)
    tn = GetCounts(nucleotides, 0)
    fn = GetCounts(nucleotides, 2)

    return (tp, fp, tn, fn)