![]() |
可以将这段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 |
所有时间均为北京时间。现在的时间是 01:08。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.