- First, read the image and then resize it to reduce the dimensions and then plot the image:
> img = readImage("bird.jpg")> img_resize = resizeImage(img, 350, 350, method = 'bilinear') > imageShow(img_resize)
Here is the sample image:

- Now vectorize the image and check the image dimension:
> img_vector = apply(img_resize, 3, as.vector) # vectorize RGB> dim(img_vector)[1] 122500 3
- Next, we will use mini-batch-kmeans clustering on the image vector and then predict the vectorized image using the cluster centroid. Finally, we will apply the prediction and cluster centroid to generate the following new segmented image, shown ...