(X)
| 32 | |
| 33 | |
| 34 | def convolve_flatten(X): |
| 35 | # input will be (32, 32, 3, N) |
| 36 | # output will be (N, 32*32) |
| 37 | N = X.shape[-1] |
| 38 | flat = np.zeros((N, 32*32)) |
| 39 | for i in range(N): |
| 40 | #flat[i] = X[:,:,:,i].reshape(3072) |
| 41 | bw = X[:,:,:,i].mean(axis=2) # make it grayscale |
| 42 | Gx = convolve2d(bw, Hx, mode='same') |
| 43 | Gy = convolve2d(bw, Hy, mode='same') |
| 44 | G = np.sqrt(Gx*Gx + Gy*Gy) |
| 45 | G /= G.max() # normalize it |
| 46 | flat[i] = G.reshape(32*32) |
| 47 | return flat |
| 48 | |
| 49 | |
| 50 | def main(): |