Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(ripa)
- library(jpeg)
- library(neuralnet)
- img1 <- readJPEG('E:\\Documentos\\Scripts\\1.jpg')
- img2 <- readJPEG('E:\\Documentos\\Scripts\\2.jpg')
- img3 <- readJPEG('E:\\Documentos\\Scripts\\3.jpg')
- img4 <- readJPEG('E:\\Documentos\\Scripts\\4.jpg')
- img5 <- readJPEG('E:\\Documentos\\Scripts\\5.jpg')
- x1 = imagematrix(img1[,,1])
- x2 = imagematrix(img2[,,1])
- x3 = imagematrix(img3[,,1])
- x4 = imagematrix(img4[,,1])
- x5 = imagematrix(img5[,,1])
- a = as.matrix(x1)
- b = as.matrix(x2)
- c = as.matrix(x3)
- d = as.matrix(x4)
- e = as.matrix(x5)
- for(i in 1:20){
- for(j in 1:20){
- if(a[i,j]<=0.6)
- a[i,j]=1
- else
- a[i,j]=0
- }
- }
- for(i in 1:20){
- for(j in 1:20){
- if(b[i,j]<=0.6)
- b[i,j]=1
- else
- b[i,j]=0
- }
- }
- for(i in 1:20){
- for(j in 1:20){
- if(c[i,j]<=0.6)
- c[i,j]=1
- else
- c[i,j]=0
- }
- }
- for(i in 1:20){
- for(j in 1:20){
- if(d[i,j]<=0.6)
- d[i,j]=1
- else
- d[i,j]=0
- }
- }
- for(i in 1:20){
- for(j in 1:20){
- if(e[i,j]<=0.6)
- e[i,j]=1
- else
- e[i,j]=0
- }
- }
- write.table(a,file="ima1.txt",col.names=FALSE,row.names=FALSE)
- write.table(b,file="ima1.txt",col.names=FALSE,row.names=FALSE)
- write.table(c,file="ima1.txt",col.names=FALSE,row.names=FALSE)
- write.table(d,file="ima1.txt",col.names=FALSE,row.names=FALSE)
- write.table(e,file="ima1.txt",col.names=FALSE,row.names=FALSE)
- a1 = as.vector(a)
- a2 = as.vector(b)
- a3 = as.vector(c)
- a4 = as.vector(d)
- a5 = as.vector(e)
- data1 <-data.frame(a1,a2,a3,a4,a5)
- t1<-rep(1,400)
- t2<-rep(0,400)
- datos<-data.frame(data1,t1,t2)
- red2 <- neuralnet(datos$t1+datos$t2~datos$a1+datos$a2+datos$a3+datos$a4+datos$a5,data=datos,hidden=9,rep=5)
- plot(red2,rep="best")
- nSalida <-compute(red2,covariate=matrix(c(datos$a1,datos$a2,datos$a3,datos$a4,datos$a5),byrow=TRUE,ncol=5))
- print(nSalida)
- salidaTEST <-cbind(datos,as.data.frame(nSalida$net.result))
- colnames(salidaTEST)<-c("E1","E2","E3","E4","E5","S1 ANN","S2 ANN","Resultado S1","Resultado S2")
- print(salidaTEST)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement