From 43ea696b267d981a0102943251c7694459a5c6a9 Mon Sep 17 00:00:00 2001 From: aaaakshat <33050725+aaaakshat@users.noreply.github.com> Date: Mon, 1 Nov 2021 19:20:56 -0400 Subject: [PATCH] Add single photon imaging demo --- ch08.r | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ch08.r b/ch08.r index 42fa871..659bf9d 100644 --- a/ch08.r +++ b/ch08.r @@ -47,6 +47,27 @@ lines(theta, L_df$"12", lwd=6) title(expression(paste("L(", theta, " | S = 12)"))) grid() +## ML estimation for single-photon imaging +# R code +library(imager) +lambda = as.data.frame(load.image("cameraman.tif")) +lambda = xtabs(value ~ x+y, data=lambda) +T = 100 +x = c() +for (i in 1:T) x = append(x, rpois(length(lambda), lambda)) +x = array(x, c(256, 256, 100)) +y = (x>=1) +mu = apply(y, c(1,2), mean) +lambdahat = -log(1-mu) +fig1 = x[,,1] + +# Flip matrix since image reads the matrix bottom up +flip_matrix = function(m) m[,nrow(m):1] + +image(flip_matrix(fig1), col=gray.colors(255)) + +image(flip_matrix(lambdahat), col=gray.colors(255)) ############# +