Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 可以将这段Matlab脚本进一步矢量化吗?

因此,我要使用此代码执行的操作是找到图像的某一行上所有低于特定阈值的像素。但是,问题在于,该代码是在double for循环中执行的(是的,我知道:(),每个像素一次,所以它非常慢。我想知道是否还可以做其他事情。

一些技巧会很不错,因为我对MATLAB优化还很陌生,而且我只知道一些基础知识(尽量不要使用循环,或在内部函数中多次调用脚本,等等)。如果无法解决问题,我可能不得不求助于MEX文件,这对于我们小组中的其他研究人员而言将更加难以维护。谢谢!

for y = 1:y_len for x = 1:x_len %//...do stuff to calc slope and offset for the line, %//this can be vectorized pretty easily. yIndices = xIndices.*slope + offset; yIndices = round(yIndices); yIndices = yIndices + 1; xIndices = xIndices + 1; valid_points = (yIndices 0); %this line is bottle necking---------------------------------------- valid_points = yIndices(valid_points)+(xIndices(valid_points)-1)*308; %------------------------------------------------------------------- valid_points = valid_points(phaseMask_R(valid_points)); t_vals = abs(phase_R(valid_points)-currentPhase); point_vals = [XsR(valid_points);YsR(valid_points)] - 1; matchedPtsCoordsR = point_vals(:,(t_vals
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 01:14


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.