how can i make changes in the image without updating the image in given code?

Viewed 17
enter code herefrom re import X
               import numpy as np
               import math as m
               import cv2


               image=cv2.imread("I:\image segmentation\image5.png")
               K1 = input("No. Of Clusters : ")
               K = int(K1)
               h,w,c=image.shape
               X = image.ndim

               Clusters=np.random.randint(0,255,size=(K,3))
               print('init clusters', Clusters)

               img=image.copy()
               diff = np.zeros(K,int)



               for i in range(h):
                   for j in range(w):
                   pnt=img[i][j]

                      for l in range(K):
                          diff[l]=np.sqrt(np.sum(Clusters[l]-pnt)**2)
        
                      cent= np.argmin(diff)
                      img[i][j]=Clusters[cent]

here i want the clusters to be stored rather than be updated on image at same time. i want to make this changes(making cluster and segment image)but i don't want to update the image. what should i do?

0 Answers
Related