def modeling2color(model2, img1):
     for i in range(0,img1.shape[0]):
         for j in range(0,img1.shape[1]):
             if model2[i,j]>0:
                  img1[i,j,:] = [0,0,0]
     new_im = Image.fromarray(DominantService.croping(img1))
     return new_im, img1
 def afterFindingColor1(model6, img_correct, num_flg, colors123456, flag,
                        thresh, percentage):
     print(model6)
     colorCen = ColorCenter.colorCent(model6, img_correct, num_flg)
     model_new = Color2Service.reshaping(model6)
     s = DominantService.size_img(img_correct)
     #colors =colors123456
     num = num_flg + 1
     admat = FinalMerge.adMat(num, colorCen, thresh, flag)
     print(admat)
     print("num", num)
     model66, number1 = FinalMerge.mergeColor(model_new, num, admat)
     print("number1", number1)
     number, model1 = FinalMerge.modelEnhance1(model66, number1, percentage)
     print("number", number)
     return model1, number, colorCen, s
Exemple #3
0
    def start_clustering(self, socket):
        im = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        x = DominantService.getColors(im)
        flag1 = DominantService.rgbOrhsv(x, self.flag)
        thresh = 32
        #flag1 = 1
        if flag1 < 1:
            print('hi')
            model2, img1 = DominantService.RGB(x, img, thresh)
            #colorC1 = np.copy(x)
        else:
            print('bye')
            model2, img1, colorC1, x = DominantService.HSV(x, img, thresh)
        print("part 123")
        new_im, img1 = Color2Service.modeling23color(model2, img1)
        color_centre1 = Color2Service.colorfindergram(new_im, thresh)
        color12 = Color2Service.color2get(new_im, thresh)
        #color_centre1 = Color2Service.mergeColor(color_centre1, color12)
        model3 = Color2Service.finalModel(thresh, color_centre1, img1, model2,
                                          flag1, 4)
        model_new = Color2Service.reshaping(model3)
        s = DominantService.size_img(img)
        colorC23 = Color2Service.findColorC(model3, img)
        colors = Color2Service.colorConcat(color_centre1, x)
        print(colorC23)
        ############
        num = 3
        admat = FinalMerge.adMat(num, colors, thresh, flag1)
        print(admat)
        model2, number1 = FinalMerge.mergeColor(model_new, num, admat)
        print(np.size(model2))
        number, model1 = FinalMerge.modelEnhance(model2, num)
        print("part 101")
        ###################################################

        #        model1 = model_new
        #################################################
        serialized_data = json.dumps({
            "colors": colors.tolist(),
            "model_1d": model1.tolist(),
            "shape": s.tolist(),
            "number": number
        })
        socket.write_message(serialized_data)
Exemple #4
0
    def start_clustering(self, socket):    
        start = time.time()
        num_flg = 6
        number_color = 1
        flag_havingColor =  np.ones([6]);
        num_haveingColor = 1000;
        im  = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        median = cv2.medianBlur(img,5)
        #blur = cv2.bilateralFilter(median,9,75,75)
        img = cv2.bilateralFilter(median,10,100,100)
#        plt.imshow(img)
#        plt.show()
        img_correct = np.copy(img)
        x = DominantService.getColors(im)
        thresh = 38
        num_max = 0
        percentage = 0.08
        s = DominantService.size_img(img)
        model2, img1, colorC1, x, num_max, color1 = ColorAllService.color1(x, img, thresh)
        flag_havingColor[0] = Color3Service.havingColor(model2, flag_havingColor[0], num_haveingColor)
        if flag_havingColor[0] == 0:
            print('wow')
            number  = 1
            #colorCen = ColorCenter.colorCent(model2, img_correct, 1)
            #model1= Color2Service.reshaping(model2)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colorC1, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 1 is finished",sum(model2[model2==1]))
        colors12, model3, x1, num_max = ColorAllService.color2(model2, img1, thresh, self.flag, num_max, x, color1, flag_havingColor[0])
        flag_havingColor[1] = Color3Service.havingColor(model3, flag_havingColor[0], num_haveingColor)
        if flag_havingColor[1] == 0 and flag_havingColor[0] == 1:
            print('wow')
            number  = 2
            #colorCen = ColorCenter.colorCent(model3, img_correct, 2)
            #model1= Color2Service.reshaping(model3)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colors12, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 2 is finished",sum(model3[model3==2]))
        colors123, model4 = ColorAllService.color3(model3, img, self.flag, num_max, thresh, x, x1, colors12, flag_havingColor[1])
        flag_havingColor[2] = Color3Service.havingColor(model4, flag_havingColor[1], num_haveingColor)
        if flag_havingColor[2] == 0 and  flag_havingColor[1] == 1:
            print('wow')
            number  = 3
            #colorCen = ColorCenter.colorCent(model4, img_correct, 3)
            #model1= Color2Service.reshaping(model4)
            model1, number, colorCen, s = ColorAllService.afterFindingColor1(model2, img_correct, 1, colors123, self.flag, thresh, percentage)
            serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
            socket.write_message(serialized_data)
            return
        #print("part 3 is finished",sum(model4[model4==3]))
        modelN = model4
        colorsall = colors123
        #print(colorsall)
        for i in range(4,5):
            modelN, colorsall = ColorAllService.otherColors(img, colorsall, self.flag, num_max, thresh, modelN, flag_havingColor[i-2],i+1)
            #print(colorsall)
            flag_havingColor[i-1] = Color3Service.havingColor(modelN, flag_havingColor[i-2], num_haveingColor)
           # print("part  is finished",sum(modelN[modelN==i]))
            if (flag_havingColor[i-1] == 0 and  flag_havingColor[i-2] == 1)or i ==4:
                print('wow',i)
                model1, number, colorCen, s = ColorAllService.afterFindingColor1(modelN, img_correct, i, colorsall, self.flag, thresh, percentage)
                #model1, number, colorCen, s = ColorAllService.afterFindingColor(Color2Service.unreshaping(model1,img_correct), img_correct, number, colorCen, self.flag, thresh)
                #number  = i
                serialized_data = json.dumps({"colors": colorCen[0:number+1].tolist(), "model_1d": model1.tolist(), "shape":s.tolist(), "number":number })
                socket.write_message(serialized_data)
                return
                break
            
#            number = 6
        print('finish')
 def color1(x, img, thresh):
     model2, img1, colorC1, x, num_max, color1 = DominantService.HSV(
         x, img, thresh)
     return model2, img1, colorC1, x, num_max, color1
Exemple #6
0
    def start_clustering(self, socket):
        start = time.time()
        num_flg = 6
        im = DominantService.pilimread(self.url)
        img = CV2Service.cv2imread(self.url)
        img_correct = np.copy(img)
        x = DominantService.getColors(im)
        thresh = 35
        num_max = 0
        if self.flag < 1:
            print('hi')
            model2, img1 = DominantService.RGB(x, img, thresh)
            #colorC1 = np.copy(x)
        else:
            print('bye')
            model2, img1, colorC1, x, num_max, color1 = DominantService.HSV(
                x, img, thresh)
        print("part 1 is finished")
        #        if sum(model2[model2==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model2, img1)
        color2, x1, num_max = Color2Service.color2get(new_im, thresh, x,
                                                      self.flag, num_max)
        #color_centre1 = Color2Service.mergeColor(color_centre1, color12)
        model3 = Color2Service.finalModel(thresh, color2, img1, model2,
                                          self.flag, 3)
        colors12 = Color2Service.colorConcat(color2, color1)
        print("part 2 is finished")
        #        if sum(model3[model3==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model3, img)
        color3 = Color3Service.color3get(new_im, thresh, x, x1, self.flag,
                                         num_max)
        model4 = Color2Service.finalModel(thresh, color3, img1, model3,
                                          self.flag, 4)
        colors123 = Color3Service.colorConcat(color3, colors12)
        print("part 3 is finished")
        #        if sum(model4[model4==0]) < 10:
        #            num_flg= num_flg -1
        ##################################################################################
        new_im, img1 = Color2Service.modeling2color(model4, img)
        color4 = Color3Service.color4get(new_im, thresh + 10, colors123,
                                         self.flag, num_max)
        model5 = Color2Service.finalModel(thresh + 10, color4, img1, model4,
                                          self.flag, 5)
        colors1234 = Color3Service.colorConcat(color4, colors123)
        print("part 4 is finished")
        #        if sum(model5[model5==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model5, img)
        color5 = Color3Service.color4get(new_im, thresh + 20, colors1234,
                                         self.flag, num_max)
        model6 = Color2Service.finalModel(thresh + 20, color5, img1, model5,
                                          self.flag, 6)
        colors12345 = Color3Service.colorConcat(color5, colors1234)
        print("part 5 is finished")
        #        if sum(model6[model6==0]) < 10:
        #            num_flg= num_flg -1
        new_im, img1 = Color2Service.modeling2color(model6, img)
        print("6-1 finised")
        color6 = Color3Service.color4get(new_im, thresh + 20, colors12345,
                                         self.flag, num_max)
        print("6-2 finised")
        model6 = Color2Service.finalModel(thresh + 20, color6, img1, model6,
                                          self.flag, 7)
        print("6-3 finised")
        #        model6 = ImageAlter.enhancing(model6, 7)
        colors123456 = Color3Service.colorConcat(color6, colors12345)
        print("part 6 is finished", num_flg)
        colorCen = ColorCenter.colorCent(model6, img_correct, num_flg)
        print(np.shape(model6))
        print(np.shape(img_correct))
        print('shapes')
        model_new = Color2Service.reshaping(model6)
        s = DominantService.size_img(img)
        colors = colors123456

        ############
        num = num_flg + 1
        admat = FinalMerge.adMat(num, colorCen, thresh, self.flag)
        print(admat)
        model66, number1 = FinalMerge.mergeColor(model_new, num, admat)
        print(np.size(model2))
        number, model1 = FinalMerge.modelEnhance(model66, number1)

        print("Merge part")
        end = time.time()
        print(end - start)
        ###################################################

        #        model1 = model_new
        #        number =6
        #################################################
        serialized_data = json.dumps({
            "colors": colorCen[0:number + 1].tolist(),
            "model_1d": model1.tolist(),
            "shape": s.tolist(),
            "number": number
        })
        socket.write_message(serialized_data)