Return a compressed image Quantizes an image into 2^b clusters and return a version of the image (the same size as the original) where each pixel's original colour is replaced with the nearest prototype colour.

compress(img, b)

Arguments

img

array, the image to be processed

b

integer, the desired number of bits

Value

array, returns the compressed image

Examples

old_img <- array(1:24, dim = c(3, 4, 2)) (compressed_img <- compress(old_img, 3L))
#> , , 1 #> #> [,1] [,2] [,3] [,4] #> [1,] 1.5 3.5 7.0 9.5 #> [2,] 1.5 5.0 8.0 11.5 #> [3,] 3.5 6.0 9.5 11.5 #> #> , , 2 #> #> [,1] [,2] [,3] [,4] #> [1,] 13.5 15.5 19.0 21.5 #> [2,] 13.5 17.0 20.0 23.5 #> [3,] 15.5 18.0 21.5 23.5 #>