I'm trying to replicate MATLAB's imresize behavior in Python using skimage.transform.resize. Here's my test case:
Python
delta = np.array([
[0.1639, 0.2759, 0.4142, 0.1323, 0.1234, 0.2311, 0.3421],
[0.5213, 0.5566, 0.6580, 0.2131, 0.1923, 0.3422, 0.4312],
[0.7943, 0.8750, 1.0000, 0.4231, 0.1233, 0.2312, 0.5123],
[0.1212, 0.0012, 0.1232, 0.1021, 0.1530, 0.2313, 0.3412],
[0.4321, 0.5123, 0.6123, 0.3121, 0.2132, 0.3212, 0.4321],
[0.2312, 0.3412, 0.4512, 0.2211, 0.1234, 0.2345, 0.3456],
[0.6543, 0.7654, 0.8765, 0.4321, 0.3212, 0.4321, 0.5432]
])
filter_kernel = np.array([
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0.4050, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]
])
# Step 1: Convolve input with the delta filter
ys_filtered = convolve2d(delta, filter_kernel, mode='same', boundary='symm')
# Resize to 5x5 using bilinear interpolation
delta_resized = resize(
ys_filtered,
(5, 5),
order=1, # bilinear
mode='wrap', # mimic MATLAB edge replication
anti_aliasing=False, # no anti-aliasing to match MATLAB closely
preserve_range=False
)
print(delta_resized)
Matlab
delta = zeros(7,7);
delta(4,4) = 1; % single pixel in the middle
delta = [
0.1639, 0.2759, 0.4142, 0.1323, 0.1234, 0.2311, 0.3421;
0.5213, 0.5566, 0.6580, 0.2131, 0.1923, 0.3422, 0.4312;
0.7943, 0.8750, 1.0000, 0.4231, 0.1233, 0.2312, 0.5123;
0.1212, 0.0012, 0.1232, 0.1021, 0.1530, 0.2313, 0.3412;
0.4321, 0.5123, 0.6123, 0.3121, 0.2132, 0.3212, 0.4321;
0.2312, 0.3412, 0.4512, 0.2211, 0.1234, 0.2345, 0.3456;
0.6543, 0.7654, 0.8765, 0.4321, 0.3212, 0.4321, 0.5432
];
resized = imresize(delta, [5,5], 'bilinear'); % or your target size
disp(resized)
Problem:
Even though I’m using bilinear interpolation and trying different modes in Python (mode='edge', mode='reflect', etc.), the output from skimage.transform.resize does not match MATLAB's imresize.
I’ve also tried cv2.resize and scipy.ndimage.zoom, but the results are still different.
Question: Here i have generated a output for 7*7 matrix in matlab consisting of all 0 and center pixel 1 and used that output in python by first convolving it and then resizing it , but still for the same array in matlab and python output is different