def colorBBoxesBorders(im, T, shift = (0, 0) ):
    """
        takes an image @im and a Tree @T corresponding to the bounding box hierarchy (quad-tree partition)
        colors only the borders of bounding rectangles
    """

    w = 1  # the (symmetric) width of the border of rectangles to be colored

    im_1 = im.copy()
    (W, H) = im_1.size

    Boxes = T.getValues()

    for i in range( len(Boxes) ):
        z = Boxes[i]

        for u in range(z[0] + shift[0] , z[2] + shift[0] ):
            for v in range( z[1] + shift[1] - w, z[1] + shift[1] + w + 1 ):
                if ( (v >= 0 ) and (v < H) ):
                    im_1.putpixel( (u, v), (255, 0, 0, 0) )

            for v in range( z[3] + shift[1] - w, z[3] + shift[1] + w + 1 ):
                if ( (v >= 0) and ( v < H ) ):
                    im_1.putpixel( (u, v), (255, 0, 0, 0) )


        for u in range( z[1] + shift[1], z[3] + shift[1] ):
            for v in range( z[0] + shift[0] - w, z[0] + shift[0] + w + 1 ):
                if ( ( v >= 0 ) and ( v < W ) ):
                    im_1.putpixel( (v, u), (255, 0, 0, 0) )

            for v in range( z[2] + shift[0] - w, z[2] + shift[0] + w + 1 ):
                if ( ( v >= 0 ) and ( v < W ) ):
                    im_1.putpixel( (v, u), (255, 0, 0, 0) )


    return im_1