python保存为mat文件_用python在matlab中保存.mat文件

这篇博客探讨了如何从Python环境中调用Matlab脚本`demo.m`来创建`.mat`文件。博主遇到的问题是,当直接在Matlab中运行`demo.m`时,文件能成功创建,但从Python运行时,似乎没有保存任何数据。博客内容包括了`demo.m`的部分源码,显示了脚本中涉及的文件编译和图像处理步骤,以及尝试添加调试信息以确定脚本是否正确执行。
摘要由CSDN通过智能技术生成

当我直接运行demo.m时,demo.m中的这一行在MatLab中运行得很好:save('C:\PATH_TO_MY_FOLDER\boxes.mat', 'boxes');

所以当我检查这个文件夹时,我确实发现一个名为boxes.mat的文件已经创建,它包含一个2D数组。在

但是,当我从python运行demo.m(在下面的代码中),Matlab似乎打开了,但是{}似乎没有保存。在

^{pr2}$

我可能一开始就没有成功运行demo.m?

我加了句台词fprintf('hello');

在demo.m中保存boxes.mat文件的行之前,但也没有得到该输出。

如何确定demo.m是从Python执行的呢?我确实看到一个Matlab按钮出现在任务栏上。在

demo.m的代码稍作编辑,取自here:% This demo shows how to use the software described in our IJCV paper:

% Selective Search for Object Recognition,

% J.R.R. Uijlings, K.E.A. van de Sande, T. Gevers, A.W.M. Smeulders, IJCV 2013

%%

addpath('Dependencies');

fprintf('Demo of how to run the code for:\n');

fprintf(' J. Uijlings, K. van de Sande, T. Gevers, A. Smeulders\n');

fprintf(' Segmentation as Selective Search for Object Recognition\n');

fprintf(' IJCV 2013\n\n');

% Compile anisotropic gaussian filter

if(~exist('anigauss'))

fprintf('Compiling the anisotropic gauss filtering of:\n');

fprintf(' J. Geusebroek, A. Smeulders, and J. van de Weijer\n');

fprintf(' Fast anisotropic gauss filtering\n');

fprintf(' IEEE Transactions on Image Processing, 2003\n');

fprintf('Source code/Project page:\n');

fprintf(' http://staff.science.uva.nl/~mark/downloads.html#anigauss\n\n');

mex Dependencies/anigaussm/anigauss_mex.c Dependencies/anigaussm/anigauss.c -output anigauss

end

if(~exist('mexCountWordsIndex'))

mex Dependencies/mexCountWordsIndex.cpp

end

% Compile the code of Felzenszwalb and Huttenlocher, IJCV 2004.

if(~exist('mexFelzenSegmentIndex'))

fprintf('Compiling the segmentation algorithm of:\n');

fprintf(' P. Felzenszwalb and D. Huttenlocher\n');

fprintf(' Efficient Graph-Based Image Segmentation\n');

fprintf(' International Journal of Computer Vision, 2004\n');

fprintf('Source code/Project page:\n');

fprintf(' http://www.cs.brown.edu/~pff/segment/\n');

fprintf('Note: A small Matlab wrapper was made.\n');

% fprintf('

mex Dependencies/FelzenSegment/mexFelzenSegmentIndex.cpp -output mexFelzenSegmentIndex;

end

%%

% Parameters. Note that this controls the number of hierarchical

% segmentations which are combined.

colorTypes = {'Hsv', 'Lab', 'RGI', 'H', 'Intensity'};

colorType = colorTypes{1}; % Single color space for demo

% Here you specify which similarity functions to use in merging

simFunctionHandles = {@SSSimColourTextureSizeFillOrig, @SSSimTextureSizeFill, @SSSimBoxFillOrig, @SSSimSize};

simFunctionHandles = simFunctionHandles(1:2); % Two different merging strategies

% Thresholds for the Felzenszwalb and Huttenlocher segmentation algorithm.

% Note that by default, we set minSize = k, and sigma = 0.8.

k = 200; % controls size of segments of initial segmentation.

minSize = k;

sigma = 0.8;

% As an example, use a single image

images = {'000016.jpg'};

%images = {'C:\Users\Public\Pictures\Sample Pictures\Desert.jpg'};

im = imread(images{1});

% Perform Selective Search

[boxes blobIndIm blobBoxes hierarchy] = Image2HierarchicalGrouping(im, sigma, k, minSize, colorType, simFunctionHandles);

boxes = BoxRemoveDuplicates(boxes);

save('C:\work_asaaki\code\SelectiveSearchCodeIJCV\boxes.mat', 'boxes');

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值