首页 > 解决方案 > 在 Python 中运行 MATLAB 脚本

问题描述

我正在寻找一种在不使用 MATLAB 的情况下在 python 文件中执行 MATLAB 代码的方法。这是我的 MATLAB 代码:

count = 0
for image_name in os.listdir(directory_segmentation):
    if count < n_displays:
        segmented_image = cv2.imread(directory_segmentation + "/" + image_name)

        segmented = Image.open(directory_segmentation + "/" + image_name)
        original = Image.open(directory_originals + "/" + image_name)

        font = ImageFont.truetype(font_path, font_size)

        d1 = ImageDraw.Draw(segmented)
        masked = self.create_mask_plaque(segmented_image, color_plaque)
        maxlevel = 3
        **v = self.waveletdescr(masked, maxlevel)**
        print(v)

    count += 1

它在 ** ** 之间的函数是在 MATLAB 中编码的。所以我需要给它一些参数并取回一个向量。可能吗?谢谢!!PD。MATLAB 脚本的结构如下所示:

function v = waveletdescr(im,maxlevel) ;
im = rgb2gray(im)
im = double(im);
[m,n] = size(im);
npix = m*n;

....

v = zeros( 3*maxlevel+1, 1 ); % the descriptors
end
  
v(end) = sum(sum( im.^2 )) / npix; 

function imf = filterh(im,l)
  d = size(im(end-1:-1:end-l,:))
  imf = 0.5*[im; im(end-1:-1:end-l,:)];
  imf = imf(1:end-l,:) + imf(l+1:end,:);

function imf = filterg(im,l)
  imf = 0.5*[im; im(end-1:-1:end-l,:)];
  imf = imf(l+1:end,:) - imf(1:end-l,:);

标签: pythonmatlab

解决方案


推荐阅读