Guest User

Untitled

a guest
Nov 17th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. def GAP(source,Encode=True): # GAP Prediction
  2. # Create array of output image
  3. GAP_out = np.zeros(source.shape);
  4. dy = source.shape[0];
  5. dx = source.shape[1];
  6. for j in range(2,dy):
  7. for i in range(2,dx-1):
  8. In = int(source[j-1,i]);
  9. Inn = int(source[j-2,i]);
  10. Ine = int(source[j-1,i+1]);
  11. Inne = int(source[j-2,i+1]);
  12. Inw = int(source[i-1,j-1]);
  13. Iw = int(source[j,i-1]);
  14. Iww = int(source[j,i-2]);
  15.  
  16.  
  17. # input to GAP
  18. dh = (abso(Iw,Iww) + abso(In,Inw) + abso(In,Ine));
  19. dv = (abso(Iw,Inw) + abso(In,Inn) + abso(Ine,Inne));
  20.  
  21. fc = dh-dv;
  22. sc = dv-dh;
  23.  
  24. # GAP Algorithm
  25. if(sc > 80):
  26. x = Iw;
  27. elif(fc > 80):
  28. x = In;
  29. else:
  30. x = (In+Iw)/2+(abso(Ine,Inw))/4;
  31. if(fc > 32):
  32. x = (x+In)/2;
  33. elif(sc > 32):
  34. x = (x+Iw)/2;
  35. elif(fc > 8):
  36. x = (3*x+In)/4;
  37. elif(sc > 8):
  38. x = (3*x+Iw)/4;
  39. # End to GAP Algorithm
  40. if(Encode): # Coding
  41. GAP_out[j,i] = np.uint8(x)
  42. print "Posicion = (",j,",",i,")", x,GAP_out[j,i].astype(np.uint8), source[j,i];
  43. else: # Decoding
  44. GAP_out[j,i] = x + error[j,i];
Add Comment
Please, Sign In to add comment