$$ \newcommand{\esp}[1]{\mathbb{E}\left(#1\right)} \newcommand{\var}[1]{\mbox{Var}\left(#1\right)} \newcommand{\deriv}[1]{\dot{#1}(t)} \newcommand{\prob}[1]{ \mathbb{P}\!(#1)} \newcommand{\eqdef}{\mathop{=}\limits^{\mathrm{def}}} \newcommand{\by}{\boldsymbol{y}} \newcommand{\bc}{\boldsymbol{c}} \newcommand{\bpsi}{\boldsymbol{\psi}} \def\pmacro{\texttt{p}} \def\like{{\cal L}} \def\llike{{\cal LL}} \def\logit{{\rm logit}} \def\probit{{\rm probit}} \def\one{{\rm 1\!I}} \def\iid{\mathop{\sim}_{\rm i.i.d.}} \def\simh0{\mathop{\sim}_{H_0}} \def\df{\texttt{df}} \def\res{e} \def\xomega{x} \newcommand{\argmin}[1]{{\rm arg}\min_{#1}} \newcommand{\argmax}[1]{{\rm arg}\max_{#1}} \newcommand{\Rset}{\mbox{$\mathbb{R}$}} \def\param{\theta} \def\setparam{\Theta} \def\xnew{x_{\rm new}} \def\fnew{f_{\rm new}} \def\ynew{y_{\rm new}} \def\nnew{n_{\rm new}} \def\enew{e_{\rm new}} \def\Xnew{X_{\rm new}} \def\hfnew{\widehat{\fnew}} \def\degree{m} \def\nbeta{d} \newcommand{\limite}[1]{\mathop{\longrightarrow}\limits_{#1}} \def\ka{k{\scriptstyle a}} \def\ska{k{\scriptscriptstyle a}} \def\kel{k{\scriptstyle e}} \def\skel{k{\scriptscriptstyle e}} \def\cl{C{\small l}} \def\Tlag{T\hspace{-0.1em}{\scriptstyle lag}} \def\sTlag{T\hspace{-0.07em}{\scriptscriptstyle lag}} \def\Tk{T\hspace{-0.1em}{\scriptstyle k0}} \def\sTk{T\hspace{-0.07em}{\scriptscriptstyle k0}} \def\thalf{t{\scriptstyle 1/2}} \newcommand{\Dphi}[1]{\partial_\pphi #1} \def\asigma{a} \def\pphi{\psi} \newcommand{\stheta}{{\theta^\star}} \newcommand{\htheta}{{\widehat{\theta}}} $$


Restore the following images using the ICM and the simulated annealing algorithms.

1 Image 1

n <- 12
m <- 10
foo <- matrix(c(1,2,3,2,3,1,3,1,2), nrow=3)
temp <- matrix(1,nrow=n/3,ncol=n/3) %x% foo
X.ori <- temp %x% matrix(1,nrow=m,ncol=m)

image(X.ori, axes=FALSE, frame.plot=FALSE)

p <- 0.1
N <- dim(X.ori)[1]
Y <- X.ori
Y1 <- Y[2:(N-1),2:(N-1)]
i1 <- which(runif(((N-2)^2)) < p)
Y1[i1] <- 1
i2 <- which(runif(((N-2)^2)) < p)
Y1[i2] <- 2
i3 <- which(runif(((N-2)^2)) < p)
Y1[i3] <- 3
Y[2:(N-1),2:(N-1)] <- Y1

image(Y, axes=FALSE, frame.plot=FALSE)



2 Image 2

n <- 10
m <- 10
temp <- matrix(1,nrow=n/2,ncol=n/2) %x% diag(2)
X.ori <- temp %x% matrix(1,nrow=m,ncol=m) +1

image(X.ori, axes=FALSE, frame.plot=FALSE)

N <- dim(X.ori)[1]
Y <- X.ori
Y[2:(N-1),2:(N-1)] <- Y[2:(N-1),2:(N-1)] + matrix(rnorm((N-2)^2)*0.7,ncol=N-2)

image(Y, axes=FALSE, frame.plot=FALSE)



3 Image 3

n <- 100
m <- 10
foo <- rep(rep(c(1,2),m/2),each=n/m)
X.ori <- matrix(1,nrow=n,ncol=n)
for (k in (1:n)) {
  X.ori[k,] <- foo
  foo <- c(foo[n], foo[1:(n-1)])
  }

image(X.ori, axes=FALSE, frame.plot=FALSE)

p <- 0.15
N <- dim(X.ori)[1]
Y <- X.ori
Y1 <- Y[2:(N-1),2:(N-1)]
i1 <- which(runif(((N-2)^2)) < p)
Y1[i1] <- 3-Y1[i1]
Y[2:(N-1),2:(N-1)] <- Y1

image(Y, axes=FALSE, frame.plot=FALSE)