Skip to content

Instantly share code, notes, and snippets.

@statistic-on-air
Created August 29, 2011 08:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statistic-on-air/1178034 to your computer and use it in GitHub Desktop.
Save statistic-on-air/1178034 to your computer and use it in GitHub Desktop.
# Sierra 2-4a dithering filter
Sierra24aConvolution <- function(a){
c <- matrix(0, nrow=dim(a)[1], ncol=dim(a)[2])
for(i in 2:(dim(a)[1]-2)){
for(j in 2:(dim(a)[2]-2)){
P <- trunc(a[i,j]+0.5)
e <- a[i,j] - P
a[i,j] <- P
a[i,j+1] <- a[i,j+1] + (e * 2/4)
a[i+1,j-1] <- a[i+1,j-1] + (e * 1/4)
a[i+1,j] <- a[i+1,j] + (e * 1/4)
}
}
a
}
grey2S24adith <- function(img){
greyMatrix <- img[1:nrow(img),1:ncol(img)]
dim1 <- 2
dim2 <- 2
dim1x <- 2
dim2x <- 2
dim1a <- dim(greyMatrix)[1]
dim2a <- dim(greyMatrix)[2]
tempMatrix <- matrix(0.5, nrow=nrow(greyMatrix)+2*1, ncol=ncol(greyMatrix)+2*1)
tempMatrix[2:(nrow(tempMatrix)-1),2:(ncol(tempMatrix)-1)] <- greyMatrix
igrey <- Sierra24aConvolution(tempMatrix)
imagematrix(igrey[2:(nrow(igrey)-1),2:(ncol(igrey)-1)], type="grey", noclipping=TRUE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment