马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
我有一组数据需要进行环拟合,现在已完成环的外圆拟合,内圆边界点提取一直不理想(如图),麻烦大家指点一下。
图中空白部分数据设定为NaN。
我的程序:
[filename, pathname] = uigetfile('*.txt','Open Data');
filepath = strcat(pathname,filename);
if length(filepath) == 0
return;
end
Data = textread(filepath,'','delimiter',';','emptyvalue',NaN);
pcolor(Data), axis equal,axis tight, shading interp;
colorbar; hold on;
% 找出圆环的外边界,并进行最小二乘圆拟合
BoundIdx = []; BoundIdy = [];
for k1=1:size(Data,1)
NaNIdx=find(isnan(Data(k1,:)));
JumpSize=diff(NaNIdx);
BI=find(JumpSize>=2);
BINum = length(BI);
if ~(isempty(BI))
BoundIdx = [BoundIdx NaNIdx(BI(1)) NaNIdx(BI(BINum)+1)];
BoundIdy = [BoundIdy k1 k1];
end
end
[xc,yc,R] = circfit(BoundIdx,BoundIdy);
t = linspace(0,pi*2,100);
z = xc+yc*i+R*exp(i*t);
%plot(BoundIdx,BoundIdy,'kx');
plot(z); hold on;
R = round(R); xc = round(xc); yc = round(yc);
% 找出圆环的内边界,并进行最小二乘圆拟合
BoundIdx = []; BoundIdy = [];
for k1=yc-R:yc+R
if ~(isnan(Data(k1,xc))&isnan(Data(2*yc-k1,xc)))
continue;
end
ValueIdx=find(~isnan(Data(k1,xc:xc+R)));
if ~(isempty(ValueIdx))
BoundIdx = [BoundIdx ValueIdx(1)-1+xc];
BoundIdy = [BoundIdy k1];
end
ValueIdx=find(~isnan(Data(k1,xc:-1:xc-R)));
if ~(isempty(ValueIdx))
BoundIdx = [BoundIdx -ValueIdx(1)+1+xc];
BoundIdy = [BoundIdy k1];
end
end
[xc2,yc2,R2] = circfit(BoundIdx,BoundIdy);
t = linspace(0,pi*2,100);
z = xc2+yc2*i+R2*exp(i*t);
plot(BoundIdx,BoundIdy,'bx');
plot(z); hold off; |