示例#1
0
def stack_images(img_array, scale, labels=[]):
    w_size = img_array[0][0].shape[1]
    h_size = img_array[0][0].shape[0]
    rows = len(img_array)
    cols = len(img_array[0])
    row_available = isinstance(img_array[0], list)

    if row_available:
        for x in range(0, rows):
            for y in range(0, cols):
                img_array[x][y] = cv2.resize(img_array[x][y], (w_size, h_size),
                                             None, scale, scale)

                if len(img_array[x][y].shape) == 2:
                    img_array[x][y] = cv2.cvtColor(img_array[x][y],
                                                   cv2.COLOR_GRAY2BAR)

        img_blank = np.zeros((h_size, w_size, 3), np.unit(8))
        hor = [img_blank] * rows
        hor_con = [img_blank] * rows

        for x in range(0, rows):
            hor[x] = np.hstack(img_array[x])
            hor_con[x] = np.concatenate(img_array[x])

        ver = np.vstack(hor)
        ver_con = np.concatenate(hor)
    else:
        for x in range(0, rows):
            img_array[x] = cv2.resize(img_array[x], (w_size, h_size), None,
                                      scale, scale)

            if len(img_array[x].shape) == 2:
                img_array[x] = cv2.cvtColor(img_array[x], cv2.COLOR_GRAY2BAR)

        hor = np.hstack(img_array)
        hor_con = np.concatenate(img_array)
        ver = hor

    if len(labels) != 0:
        each_img_width = int(ver.shape[1] / cols)
        each_img_height = int(ver.shape[0] / rows)

        for r in range(0, rows):
            for c in range(0, cols):
                cv2.rectangle(ver, (c * each_img_width, r * each_img_height),
                              (c * each_img_width + len(labels[r]) * 13 + 27,
                               30 + each_img_height * r), (255, 255, 255),
                              cv2.FILLED)
                cv2.putText(
                    ver, labels[r],
                    (c * each_img_width + 10, r * each_img_height + 20),
                    cv2.FONT_HERSHEY_COMPLEX, 0.7, (255, 0, 255), 2)

    return ver
示例#2
0
 def setUp(self):
     self.sltr = FermiHubbardSystem(sites=[5], repulsion=1, chemical_potential=0.5, hopping=2)
     self.state = Weighting(array([unit(5), unit(5)]))
示例#3
0
def greens_specimens():
    for it in [unit(2), unit(2)], [zero(2), unit(2)], [unit(2), zero(2)]:
        yield array(it)
示例#4
0
        s_clr = m_clr = b_clr = 0  #small, medium, big
        for k in range(sp[2]):  #找最小值
            if (biggest < img[i, j, k]):
                biggest = img[i, j, k]
                b_clr = k  # B or G or R 為最小
            if (smallest > img[i, j, k]):
                smallest = img[i, j, k]
                s_clr = k  # B or G or R 為最大
        for k in range(3):
            if (s_clr != k and b_clr != k):  # 第二大
                m_clr = k
                medium = img[i, j, k]

        if ((img[i, j, 0] == img[i, j, 1]) and (img[i, j, 1] == img[i, j, 2])):
            if (img[i, j, 0] == 0):  #(B,G,R) = (0,0,0) LLL
                index = np.unit(30)
                output_img[i, j] = lut[0][30]
            else:  #(B,G,R) = (1,1,1) or (10,10,10)... HHH
                num = img[i, j, 0] / 8
                index = int(num) + 224
                #output_img[i,j] = index
                output_img[i, j] = lut[0][index]

        else:
            if (biggest - medium > diff and medium - smallest < diff):  #1H 2L
                if (b_clr == 0):  #HLL
                    num = img[i, j, b_clr] / 25
                    index = int(num)
                    #output_img[i,j] = lut[0][index]
                    #output_img[i,j] = index
                elif (b_clr == 1):  #LHL