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 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (1개)
Vineet Ahirkar
2018년 10월 18일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!