






from cva import COLOR_BGR2GRAY, cvtColor, imread, imshow, waitKey
from numpy import divide, inta, multiply, ravel, sort, zeros_like






def    UpperCAmelCase__	(						lowerCamelCase  : Union[str, Any] ,lowerCamelCase  : Dict=3						):
   lowerCamelCase											=int(mask / 2						)
   # copy image size
   lowerCamelCase											=zeros_like(lowerCamelCase						)
   for i in range(lowerCamelCase ,gray_img.shape[0] - bd						):
      for j in range(lowerCamelCase ,gray_img.shape[1] - bd						):
         # get mask according with mask
         lowerCamelCase											=ravel(gray_img[i - bd : i + bd + 1, j - bd : j + bd + 1]						)
         # calculate mask median
         lowerCamelCase											=sort(lowerCamelCase						)[inta(divide((multiply(lowerCamelCase ,lowerCamelCase						)) ,2						) + 1						)]
         lowerCamelCase											=median
   return median_img


if __name__ == "__main__":
   # read original image
   _UpperCAmelCase				:	Dict    						=    imread('../image_data/lena.jpg')
   # turn image in gray scale value
   _UpperCAmelCase				:	List[Any]    						=    cvtColor(img, COLOR_BGR2GRAY)

   # get values with two different mask size
   _UpperCAmelCase				:	List[str]    						=    median_filter(gray, 3)
   _UpperCAmelCase				:	Optional[Any]    						=    median_filter(gray, 5)

   # show result images
   imshow('median filter with 3x3 mask', medianaxa)
   imshow('median filter with 5x5 mask', medianaxa)
   waitKey(0)







from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier

# Load iris file
_UpperCAmelCase				:	Optional[int]    						=    load_iris()
iris.keys()


print(f"Target names: \n {iris.target_names} ")
print(f"\n Features: \n {iris.feature_names}")

# Train set e Test set
_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase						,						_UpperCAmelCase				:	List[Any]    						=    train_test_split(
    iris['data'], iris['target'], random_state=4
)

# KNN

_UpperCAmelCase				:	Optional[int]    						=    KNeighborsClassifier(n_neighbors=1)
knn.fit(X_train, y_train)

# new array to test
_UpperCAmelCase				:	List[Any]    						=    [[1, 2, 1, 4], [2, 3, 4, 5]]

_UpperCAmelCase				:	Tuple    						=    knn.predict(X_new)

print(
    f"\nNew array: \n {X_new}\n\nTarget Names Prediction: \n"
    f" {iris['target_names'][prediction]}"
)