matlab交易速度慢,请大家帮忙优化Matlab代码,速度太慢了。非常感谢。

逃离我推掉我的手 2023-01-13 10:25 179阅读 0赞

下面是一个纹理图像分割代码的一部分。就只有几个简单函数和迭代,可是速度很慢。请高手帮忙查看一下。

function TexturedSeg2()

%non-informative reference priors

global MaxT alpha1 alpha2

alpha1 = 2.0;

alpha2 = 2.0;

global beta

beta = 1.5;

%MaxNt = 150;

MaxNt = 100;

MaxT = 100;

global ARCorr lumda

ARCorr = [-1,-2;0,-2;1,-2;-2,-1;-1,-1;0,-1;1,1;2,-1;-2,0;-1,0];

%The 10 Theta parameters for GMRF in the AR process.

lumda = 3;

global Tmax Tmin

Tmax = 2;

Tmin = 0.1;

CNum = 5;

ARPara = normrnd(0,lumda,CNum,10);

%NoiseMeanPara = floor( 10 * rand ( 1, 10 ) - 5 ); %(the mean and variance values of Gaussian noise model)

NoiseMeanPara = randint(1,CNum,[0,255]);

%NoiseVarPara = ( 1- rand(1,10) * 0.8 ).^(-2) * 0.01; % discrete these parameters can help later calculation. In the range [0.01 ,0.25], just 25 points are selected uniformly

NoiseVarPara = (1-0.8*rand(1,CNum)).^(-2);

IntensityData = imread(‘texturedIm.jpg’);

IntensityData = double(IntensityData);

global ImgLength ImgWidth

[ImgWidth,ImgLength] = size(IntensityData);

Y = IntensityData;

X = randint(ImgWidth,ImgLength,[1,CNum] );

%imshow(X.*50);

%

digits 500

P= vpa(zeros(1,CNum));

F = zeros(1,CNum);

for Nt = 1:MaxNt

for t = 1:MaxT

T = (MaxT-t)/MaxT * (Tmax-Tmin) + Tmin;

tic

for i = 1:ImgWidth

for j = 1:ImgLength

for C = 1:CNum

P(C) = (NoiseVarPara(C))^(-0.5)*exp(-1/T*((Y(i,j)-NoiseMeanPara(C)- RAError( Y, NoiseMeanPara(C), ARPara(C,:),i,j))^2*0.5/NoiseVarPara(C) + Potentials(X,i,j,C)));

end

F = cumsum(double(P));

F = F/F(end);

U = rand(1);

l = find( F>=U );

if( ~isempty(l) )

X(i,j) = l(1);

end

end

end

toc

figure

imshow(uint8(X*40));

end

end

[本帖最后由 mooni 于 2009-5-11 10:27 编辑]

发表评论

表情:
评论列表 (有 0 条评论,179人围观)

还没有评论,来说两句吧...

相关阅读

    相关 GitHub速度?试试这招

    为什么GitHub下载速度这么慢? GitHub,我们都知道是世界上最大的开源及私有软件项目的托管平台,全世界每天有海量优秀的开源软件在这里产生,而 GitHub 在国内