Advertisement
eriasu

ImagenesRLevano

May 12th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 1.99 KB | None | 0 0
  1. library(ripa)
  2. library(jpeg)
  3. library(neuralnet)
  4.  
  5. img1 <- readJPEG('E:\\Documentos\\Scripts\\1.jpg')
  6. img2 <- readJPEG('E:\\Documentos\\Scripts\\2.jpg')
  7. img3 <- readJPEG('E:\\Documentos\\Scripts\\3.jpg')
  8. img4 <- readJPEG('E:\\Documentos\\Scripts\\4.jpg')
  9. img5 <- readJPEG('E:\\Documentos\\Scripts\\5.jpg')
  10. x1 = imagematrix(img1[,,1])
  11. x2 = imagematrix(img2[,,1])
  12. x3 = imagematrix(img3[,,1])
  13. x4 = imagematrix(img4[,,1])
  14. x5 = imagematrix(img5[,,1])
  15. a = as.matrix(x1)
  16. b = as.matrix(x2)
  17. c = as.matrix(x3)
  18. d = as.matrix(x4)
  19. e = as.matrix(x5)
  20. for(i in 1:20){
  21.   for(j in 1:20){
  22.     if(a[i,j]<=0.6)
  23.       a[i,j]=1
  24.     else
  25.       a[i,j]=0
  26.   }
  27. }
  28. for(i in 1:20){
  29.   for(j in 1:20){
  30.     if(b[i,j]<=0.6)
  31.       b[i,j]=1
  32.     else
  33.       b[i,j]=0
  34.   }
  35. }
  36. for(i in 1:20){
  37.   for(j in 1:20){
  38.     if(c[i,j]<=0.6)
  39.       c[i,j]=1
  40.     else
  41.       c[i,j]=0
  42.   }
  43. }
  44. for(i in 1:20){
  45.   for(j in 1:20){
  46.     if(d[i,j]<=0.6)
  47.       d[i,j]=1
  48.     else
  49.       d[i,j]=0
  50.   }
  51. }
  52. for(i in 1:20){
  53.   for(j in 1:20){
  54.     if(e[i,j]<=0.6)
  55.       e[i,j]=1
  56.     else
  57.       e[i,j]=0
  58.   }
  59. }
  60. write.table(a,file="ima1.txt",col.names=FALSE,row.names=FALSE)
  61. write.table(b,file="ima1.txt",col.names=FALSE,row.names=FALSE)
  62. write.table(c,file="ima1.txt",col.names=FALSE,row.names=FALSE)
  63. write.table(d,file="ima1.txt",col.names=FALSE,row.names=FALSE)
  64. write.table(e,file="ima1.txt",col.names=FALSE,row.names=FALSE)
  65.  
  66. a1 = as.vector(a)
  67. a2 = as.vector(b)
  68. a3 = as.vector(c)
  69. a4 = as.vector(d)
  70. a5 = as.vector(e)
  71. data1 <-data.frame(a1,a2,a3,a4,a5)
  72. t1<-rep(1,400)
  73. t2<-rep(0,400)
  74. datos<-data.frame(data1,t1,t2)
  75.  
  76. red2 <- neuralnet(datos$t1+datos$t2~datos$a1+datos$a2+datos$a3+datos$a4+datos$a5,data=datos,hidden=9,rep=5)
  77. plot(red2,rep="best")
  78. nSalida <-compute(red2,covariate=matrix(c(datos$a1,datos$a2,datos$a3,datos$a4,datos$a5),byrow=TRUE,ncol=5))
  79. print(nSalida)
  80. salidaTEST <-cbind(datos,as.data.frame(nSalida$net.result))
  81. colnames(salidaTEST)<-c("E1","E2","E3","E4","E5","S1 ANN","S2 ANN","Resultado S1","Resultado S2")
  82. print(salidaTEST)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement