if ((int(old_cent[0]) - a) <= cent[0] <= (int(old_cent[0]) + a)) and ( (int(old_cent[1]) - a) <= cent[1] <= (int(old_cent[1]) + a)) and ( (int(old_cent[2]) - a) <= cent[2] <= (int(old_cent[2]) + a)): continue else: return False return True ''' file_path = '/Users/Rozen_mac/code/mining/K_means/sample.jpg' img = R.Read_JPG(file_path) for i in range(2, 6): px = img.load() k = Kmeans(img, k=i) reslut = k.fit() k.drawWindows(reslut, str(i)) ''' file_path = '/Users/Rozen_mac/code/mining/K_means/sample2.jpg' img = R.Read_JPG(file_path) px = img.load() #for i in range(2, 6): px = img.load() k = Kmeans(img, k=5) reslut = k.fit() k.drawWindows(reslut, str(4))
self.r = rgb[0] self.g = rgb[1] self.b = rgb[2] self.x = x self.y = y self.visited = False self.isnoise = False def show(self): return self.r, self.g, self.b if __name__ == '__main__': # read an image i = R.Read_JPG('sample.jpg') width, height = i.size cpixels = [] all_pixels = [] # list of tuples for x in range(width): for y in range(height): cpixel = i.getpixel((x, y)) cpixels.append(cpixel) all_pixels.append(DataSet(cpixel, x, y)) # Create object of DBSCAN class dbScan = DBSCAN() # Initialise dataSet dbScan.DB = all_pixels # build clusters