col2im
and im2col
functions in matlab are important for image processing, however by googling there is no efficient implementation for python.
Especially I want to rewrite col2im for python using numpy
I have a matrix and I want to rearrange its columns into block.
The implemntations I found are not reliable by testing them it does not give the same result as matlab.
For im2col, the following implementation works fine
def im2col_sliding(A, size):
dy, dx = size
xsz = A.shape[1] - dx + 1
ysz = A.shape[0] - dy + 1
R = np.empty((xsz * ysz, dx * dy))
for i in xrange(ysz):
for j in xrange(xsz):
R[i * xsz + j, :] = A[i:i + dy, j:j + dx].ravel()
return R
But the related col2im is bogus !
Assume I a have matrix V of isze size(V) = 1 69169 By running in matlab:
X = col2im(V, [3 3], [265 265], 'sliding');
It gives me size(X) is 263 263
But, In the python implementation related to the code I posted for im2col, returns an ndarray of size (263 2) and not (263 263) and the values are incorrect !
any help