Exemplo n.º 1
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
Exemplo n.º 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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
0
    color1[:, :, 0] = x[1][0]
    color1[:, :, 1] = x[1][1]
    color1[:, :, 2] = x[1][2]
    plt.imshow(color1.astype(int))
    plt.show()
    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)
###########################################Change First Color
for i in range(0, img.shape[0]):
    for j in range(0, img.shape[1]):
        if model2[i, j] == 1:
            imgH[i, j, 0] = 100
            imgH[i, j, 1] = 80
            if imgH[i, j, 2] < 70:
                imgH[i, j, 2] = 170
imgN2 = cv2.cvtColor(imgH, cv2.COLOR_HSV2RGB)
plt.imshow(imgN2)
plt.show()
imgN2 = cv2.cvtColor(imgN2, cv2.COLOR_BGR2RGB)
name_out = 'output/' + name_nat
cv2.imwrite(name_out, imgN2)
############################################Second Color
Exemplo n.º 6
0
    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]):
    for j in range(0, img.shape[1]):
        if model2[i, j] == 1:
            imgH[i, j, 0] = 10
            imgH[i, j, 1] = 200
            if imgH[i, j, 2] < 50:
                imgH[i, j, 2] = 170
imgN2 = cv2.cvtColor(imgH, cv2.COLOR_HSV2RGB)
plt.imshow(imgN2)
plt.show()
imgN2 = cv2.cvtColor(imgN2, cv2.COLOR_BGR2RGB)
name_out = 'output/1' + name_nat
cv2.imwrite(name_out, imgN2)