I have a MATLAB function get_mask defined like so:
function M = get_mask(path)
I = imread(path);
M = im2bw(I, graythresh(I));
end
The image I'm passing in is a 16bpp grayscale TIFF LZW compressed image. I call it from Python using the Python engine:
eng = matlab.engine.start_matlab()
result = eng.get_mask('some_path');
I then pass the result to imwrite:
eng.imwrite(result, r'ml_result.tif', nargout=0)
eng.quit()
The call to imwrite takes ages (3-4 minutes, a separate issue...) before failing with a "Too Many Output Arguments" error. I double checked the type of 'result' and it is indeed a 1040x1392 logical as I expected. However, if I do this instead:
eng.imwrite(matlab.logical([[0, 1, 0], [1, 0, 1]]), r'C:\ml_result.tif', nargout=0)
It works, no problem. I don't understand what the difference is here.