When I import an image from Matlab I get the following jumbled image
rather than the (224x224x3 RGB) image of a single elephant I expected
I write the image from Matlab as a binary file
function save_bin(filename, input_image) r = input_image(:,:,1); % dump image for input to python g = input_image(:,:,2); b = input_image(:,:,3); fid = fopen(filename,'wb'); fwrite(fid, r(:), 'float32'); fwrite(fid, g(:), 'float32'); fwrite(fid, b(:), 'float32'); fclose(fid); endfunction
And read it back into Python as follows
m_resized = np.reshape(np.fromfile('m_resized.bin', dtype=np.float32),(224,224,3)) image = Image.fromarray(np.uint8(m_resized), 'RGB') image.show()
I've investigated the slicing differences creating a 3x3x3 tensor in Matlab and importing it and there's a fundamental difference in the slicing syntax between Matlab Python but this alone doesn't explain what's going wrong
Note: The reason I'm using a binary format rather than a jpg image is that I want to compare a Matlab CNN model to a Numpy implementation at each stage and using an image is an intelligible means of comparison rather than comparing lots of numbers.