How do I pass a matlab image array to a custom python function and receive back the image array output of the python function?

3 visualizaciones (últimos 30 días)
As the title suggests, I have a custom python function that processes images. I would like to read in an image using matlab, pass this image to the python function, and then receive the modified image that the python function returns. The caveat here is that the python function contains modifications from non-standard python library (such as PIL).
I've tried something as I've shown below, but judging by the off-base error messages I'm receiving, I don't think this was a promising thread. Therefore, I've opted not to show the error messages as I think they might mislead potential solutions.
% Import the python module mod = py.importlib.import_module('mymod');
% Read in the RGB image array inputImage = imread('image.jpg');
% Attempt to modify the image using the custom python function that utilizes PIL and return a modified image array modifiedImage = mod.mymod.some_function(inputImage);
Any help is greatly appreciated, thank you!

Respuestas (1)

Vineet Ahirkar
Vineet Ahirkar el 18 de Oct. de 2018
Hello Michael,
I assume that you are working in MATLAB R2018a.
From the code that you sent, it looks like you are trying to send an image from MATLAB to a python function, process it and send it back to MATLAB.
I would like to inform you that sending multi-dimensional arrays from MATLAB to python is supported only from R2018b and not supported in R2018a or before.
Please consider upgrading to MATLAB R2018b.
In R2018b, multi-dimensional arrays are sent to python in the form of memoryview which can be converted to a list or any other python data structure later.

Categorías

Más información sobre Call Python from MATLAB en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by