Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def GAP(source,Encode=True): # GAP Prediction
- # Create array of output image
- GAP_out = np.zeros(source.shape);
- dy = source.shape[0];
- dx = source.shape[1];
- for j in range(2,dy):
- for i in range(2,dx-1):
- In = int(source[j-1,i]);
- Inn = int(source[j-2,i]);
- Ine = int(source[j-1,i+1]);
- Inne = int(source[j-2,i+1]);
- Inw = int(source[i-1,j-1]);
- Iw = int(source[j,i-1]);
- Iww = int(source[j,i-2]);
- # input to GAP
- dh = (abso(Iw,Iww) + abso(In,Inw) + abso(In,Ine));
- dv = (abso(Iw,Inw) + abso(In,Inn) + abso(Ine,Inne));
- fc = dh-dv;
- sc = dv-dh;
- # GAP Algorithm
- if(sc > 80):
- x = Iw;
- elif(fc > 80):
- x = In;
- else:
- x = (In+Iw)/2+(abso(Ine,Inw))/4;
- if(fc > 32):
- x = (x+In)/2;
- elif(sc > 32):
- x = (x+Iw)/2;
- elif(fc > 8):
- x = (3*x+In)/4;
- elif(sc > 8):
- x = (3*x+Iw)/4;
- # End to GAP Algorithm
- if(Encode): # Coding
- GAP_out[j,i] = np.uint8(x)
- print "Posicion = (",j,",",i,")", x,GAP_out[j,i].astype(np.uint8), source[j,i];
- else: # Decoding
- GAP_out[j,i] = x + error[j,i];
Add Comment
Please, Sign In to add comment