예제 #1
0
 def mergeColor(color_centre1, color12):
     if dist1(color_centre1[0, :], color12) < dist1(color_centre1[1, :],
                                                    color12):
         if dist1(color_centre1[0, :], color12) < 100:
             color_centre1[0, :] = (color_centre1[0, :] + color12[:]) / 2
     else:
         if dist1(color_centre1[1, :], color12) < 100:
             color_centre1[1, :] = (color_centre1[1, :] + color12[:]) / 2
     return color_centre1
예제 #2
0
 def model23maker(thresh, model2, color_centre1, img1):
     for i in range(0, model2.shape[0]):
         for j in range(0, model2.shape[1]):
             if model2[i, j] == 0:
                 temp = thresh + 10
                 index = 0
                 for ch in range(0, 2):
                     if dist1(color_centre1[ch, :], img1[i, j, :]) < temp:
                         temp = dist1(color_centre1[ch, :], img1[i, j, :])
                         index = ch + 2
                 model2[i, j] = index
     model3 = enhancing(model2, 4)
     return model3
예제 #3
0
 def makeModel(model, ColorCent, img, thresh, num):
     for i in range(0, img.shape[0]):
         for j in range(0, img.shape[1]):
             if dist1(ColorCent, img[i, j, :]) < thresh:
                 model[i, j] = num
     model2 = enhancing(model, num)
     return model2
예제 #4
0
 def RGB(x, img, thresh):
     color12 = np.zeros([3])
     color12[0] = x[1][0]
     color12[1] = x[1][1]
     color12[2] = x[1][2]
     img21 = np.zeros([img.shape[0], img.shape[1]])
     #imgH =cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
     img1 = np.copy(img)
     print('rgb')
     for i in range(0, img.shape[0]):
         for j in range(0, img.shape[1]):
             if dist1(color12, img[i, j, :]) < thresh:
                 img21[i, j] = 1
     model2 = enhancing(img21, 2)
     return model2, img1
예제 #5
0
 def colorfindergram(new_im, thresh):
     color_group = 4
     colorsG = colorgram.extract(new_im, color_group)
     color_zero = np.zeros([3])
     color_centre1 = np.zeros([2, 3])
     for i in range(0, color_group):
         a = colorsG[i]
         color_centre1[0, 0] = a.rgb.r
         color_centre1[0, 1] = a.rgb.g
         color_centre1[0, 2] = a.rgb.b
         if dist1(color_centre1[0, :], color_zero) > thresh:
             print(i)
             i = color_group
             break
     a = colorsG[2]
     color_centre1[1, 0] = a.rgb.r
     color_centre1[1, 1] = a.rgb.g
     color_centre1[1, 2] = a.rgb.b
     return color_centre1
예제 #6
0
 def HSV(x, img, thresh):
     imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
     im = Image.fromarray(imgH)
     img1 = np.copy(imgH)
     x = max(im.getcolors(im.size[0] * im.size[1]))
     cl = im.getcolors(im.size[0] * im.size[1])
     cl1 = sorted(cl, reverse=True)
     print('hsv')
     color12 = np.zeros([3])
     color12[0] = x[1][0]
     color12[1] = x[1][1]
     color12[2] = x[1][2]
     img21 = np.zeros([img.shape[0], img.shape[1]])
     for i in range(0, img.shape[0]):
         for j in range(0, img.shape[1]):
             if dist1(color12, imgH[i, j, :]) < thresh:
                 img21[i, j] = 1
     model2 = enhancing(img21, 2)
     return model2, img1
예제 #7
0
    def colorfinderhist(new_im, thresh):
        cl2 = new_im.getcolors(new_im.size[0] * new_im.size[1])
        cl12 = sorted(cl2, reverse=True)
        color_zero = np.zeros([3])
        for i in range(1, len(cl12)):
            x1 = cl12[i]
            if x1[1][1] < 240 and x1[1][0] < 240 and dist1(
                    x1[1][:], color_zero) > thresh:
                print(i)
                i = len(cl12)
                break
        color12 = np.zeros([3])

        color12[0] = x1[1][0]

        color12[1] = x1[1][1]

        color12[2] = x1[1][2]
        return color12
예제 #8
0
def meanColoring(im, thresh):
    cl = im.getcolors(im.size[0] * im.size[1])
    cl1 = sorted(cl, reverse=True)
    x = max(im.getcolors(im.size[0] * im.size[1]))
    i = 0
    if x[1] == (255, 255, 255):
        x = cl1[1]
        i = 1
    count = 1
    color = np.dot(x[1], x[0])
    sigma = x[0]
    for j in range(i + 1, len(cl1)):
        x1 = cl1[j]
        if dist1(x1[1][:], x[1][:]) < thresh + 5:
            count += 1
            color += np.dot(x1[1], x1[0])
            sigma += x1[0]
    color1 = np.dot(color, 1 / sigma)
    return color1
예제 #9
0
 def findDominantColor(img, thresh=32, hsv=0):
     if hsv == 1:
         new_im = FindColor.make_pil(FindColor.hsvImage(img))
     else:
         new_im = FindColor.make_pil(img)
     cl = new_im.getcolors(new_im.size[0] * new_im.size[1])
     cl1 = sorted(cl, reverse=True)
     color_zero = np.zeros([3])
     for i in range(1, len(cl1)):
         x1 = cl1[i]
         if x1[1][1] < 240 and x1[1][0] < 240 and x1[1][2] < 240 and dist1(
                 x1[1][:], color_zero) > thresh:
             print(i)
             i = len(cl1)
             break
     colorCent = np.zeros([3])
     colorCent[0] = x1[1][0]
     colorCent[1] = x1[1][1]
     colorCent[2] = x1[1][2]
     return colorCent
예제 #10
0
    color1[:, :, 0] = x[1][0]
    color1[:, :, 1] = x[1][1]
    color1[:, :, 2] = x[1][2]
    plt.imshow(color1.astype(int))
    plt.show()
    print('rgb')
    color12 = np.zeros([3])
    color12[0] = x[1][0]
    color12[1] = x[1][1]
    color12[2] = x[1][2]
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    img21 = np.zeros([img.shape[0], img.shape[1]])
    img1 = np.copy(imgH)
    for i in range(0, img.shape[0]):
        for j in range(0, img.shape[1]):
            if dist1(color12, img[i, j, :]) < thresh:
                img21[i, j] = 1

else:
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)

    #cv2.imwrite('hsv/imgh.png',imgH)
    #name1 = 'hsv/imgh.png'
    im = Image.fromarray(imgH)
    imgH1 = cv2.cvtColor(imgH, cv2.COLOR_BGR2RGB)
    img1 = np.copy(imgH)
    #im = Image.open(name1)
    x = max(im.getcolors(im.size[0] * im.size[1]))
    cl = im.getcolors(im.size[0] * im.size[1])
    cl1 = sorted(cl, reverse=True)
    #x = cl1[3]
예제 #11
0
    color1[:, :, 0] = x[1][0]
    color1[:, :, 1] = x[1][1]
    color1[:, :, 2] = x[1][2]
    plt.imshow(color1.astype(int))
    plt.show()
    print('rgb')
    color12 = np.zeros([3])
    color12[0] = x[1][0]
    color12[1] = x[1][1]
    color12[2] = x[1][2]
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    img21 = np.zeros([img.shape[0], img.shape[1]])
    img1 = np.copy(imgH)
    for i in range(0, img.shape[0]):
        for j in range(0, img.shape[1]):
            if dist1(color12, img[i, j, :]) < thresh:
                img21[i, j] = 1

else:
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    im = Image.fromarray(imgH)
    cv2.imwrite('hsv/imgh.png', imgH)
    name1 = 'hsv/imgh.png'
    imgH1 = cv2.cvtColor(imgH, cv2.COLOR_BGR2RGB)
    img1 = np.copy(imgH)
    #im = Image.open(name1)
    x = max(im.getcolors(im.size[0] * im.size[1]))
    cl = im.getcolors(im.size[0] * im.size[1])
    cl1 = sorted(cl, reverse=True)
    #x = cl1[3]
    color1 = np.zeros([2, 2, 3])
예제 #12
0
cl = im.getcolors(im.size[0] * im.size[1])
cl1 = sorted(cl, reverse=True)
if x[1] == (255, 255, 255):
    x = cl1[1]
thresh = 32
flag = 0
if (x[1][0] < 50 and x[1][1] < 50 and x[1][2] < 50) or flag == 1:
    print('rgb')
    color12 = meanColoring(im, thresh)
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    img21 = np.zeros([img.shape[0], img.shape[1]])
    img1 = np.copy(img)
    for i in range(0, img.shape[0]):
        for j in range(0, img.shape[1]):
            if dist1(color12, img[i, j, :]) < thresh:
                img21[i, j] = 1

else:
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    im = Image.fromarray(imgH)
    img1 = np.copy(imgH)
    color12 = meanColoring(im, thresh)
    img21 = np.zeros([img.shape[0], img.shape[1]])
    for i in range(0, img.shape[0]):
        for j in range(0, img.shape[1]):
            if dist1(color12, imgH[i, j, :]) < thresh:
                img21[i, j] = 1
model2 = enhancing(img21, 2)
###########################################Change First Color
for i in range(0, img.shape[0]):
예제 #13
0
    color1[:, :, 0] = x[1][0]
    color1[:, :, 1] = x[1][1]
    color1[:, :, 2] = x[1][2]
    plt.imshow(color1.astype(int))
    plt.show()
    print('rgb')
    color12 = np.zeros([3])
    color12[0] = x[1][0]
    color12[1] = x[1][1]
    color12[2] = x[1][2]
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    img21 = np.zeros([img.shape[0], img.shape[1]])
    img1 = np.copy(img)
    for i in range(0, img.shape[0]):
        for j in range(0, img.shape[1]):
            if dist1(color12, img[i, j, :]) < thresh:
                img21[i, j] = 1

else:
    imgH = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
    im = Image.fromarray(imgH)
    cv2.imwrite('hsv/imgh.png', imgH)
    name1 = 'hsv/imgh.png'
    imgH1 = cv2.cvtColor(imgH, cv2.COLOR_BGR2RGB)
    img1 = np.copy(imgH)
    #im = Image.open(name1)
    x = max(im.getcolors(im.size[0] * im.size[1]))
    cl = im.getcolors(im.size[0] * im.size[1])
    cl1 = sorted(cl, reverse=True)
    #x = cl1[3]
    color1 = np.zeros([2, 2, 3])
예제 #14
0
 def meaningColor(ColorCent, color_centre1):
     if dist1(color_centre1[:], ColorCent[:]) < 50:
         ColorCent[:] = (color_centre1[:] + ColorCent[:]) / 2
         return ColorCent