Computationally efficient algorithms for statistical image processing. Implementation in R