Amazing technological breakthrough possible @S-Logix pro@slogix.in

Office Address

  • #5, First Floor, 4th Street Dr. Subbarayan Nagar Kodambakkam, Chennai-600 024 Landmark : Samiyar Madam
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to display a hand written image in R?

Description

To display a hand written image in R

Data Sets:

Keras MNIST data set

Process

  Load required libraries

  Load the data set(Here the keras built in dataset MNIST is used)

  The MNIST data set is a data set of 60,000 28x28 grayscale images of the 10 digits

  Initialize the color palette

  Use the function par() to set or query graphical parameters along with its arguments

  Display the image

Sapmle Code

#loading keras library
library(keras)
#loading the keras inbuilt mnist dataset
data<-dataset_mnist()
train_x<-data$train$x
train_y<-data$train$y
##Color ramp
colors<-c(‘white’,’black’)
cus_col<-colorRampPalette(colors=colors)
## Plot the average image of each digit
par(mfrow=c(4,3),pty=’s’,mar=c(1,1,2,1),xaxt=’n’,yaxt=’n’)
#Digits before transposing and transforming the matrix
for(di in 1:12)
{
image(1:28,1:28,train_x[di,,],main=train_y[di],col=cus_col(256))
}
#Digits after transposing matrix
for(di in 1:12)
{
image(1:28,1:28,t(train_x[di,,]),main=train_y[di],col=cus_col(256))
}
#Digits after transforming the matrix
for(di in 1:12)
{
image(1:28,1:28,train_x[di,,][,28:1],main=train_y[di],col=cus_col(256))
}
#Digits after transposing and transforming the matrix
for(di in 1:12)
{
image(1:28,1:28,t(train_x[di,,])[,28:1],main=train_y[di],col=cus_col(256))
}

Screenshots
display a hand written image in R
Keras MNIST data set
loading keras library
Initialize the color palette