📄 rangedataread.m
字号:
%this progarm is read abs file and output z range bmpfile and 3d point
%file(asc)
l=dir(['*.abs']);
N=size(l,1);
for i=1:N
inputname=l(i).name;
f = fopen(inputname);
if (f == -1)
error('File open error.');
end
nr = fscanf(f,'%d rows\n',1);
nc = fscanf(f,'%d columns\n',1);
fgets(f); % skip 3rd line of header
flag = fscanf(f,'%d',[nc nr])';
XM = fscanf(f,'%f',[nc nr])';
YM = fscanf(f,'%f',[nc nr])';
ZM = fscanf(f,'%f',[nc nr])';
fclose(f);
pcount=0;
zmin=max(max(ZM));zmax=min(min(ZM));
A=zeros(nr,nc);
for i=1:nr
for j=1:nc
if flag(i,j)==1
pcount=pcount+1;
if ZM(i,j)>zmax
zmax=ZM(i,j);
end
if ZM(i,j)<zmin
zmin=ZM(i,j);
end
end
end
end
scale=255.0/(zmax-zmin);
for i=1:nr
for j=1:nc
if flag(i,j)==1
A(i,j)=scale*(ZM(i,j)-zmin);
end
end
end
%
A=uint8(A);
x=length(inputname);
outimage=inputname;
outimage=strcat('.\range\',outimage);
outimage(x-2)='b';outimage(x-1)='m';outimage(x)='p';
imwrite(A,outimage);
%
fflg=6;u=0;
if pcount>=200
outputname=input('Enter ASC(point cloud) file name:','s');
x=length(outimage);
outimage(x-2)='a';outimgea(x-1)='s';outimage(x)='c';
fout=fopen(outimage,'wt');
if (fout == -1)
error('File open for write error.')
end
fprintf(fout,'%d\n',fflg);
fprintf(fout,'%d %d %d %d\n',u,u,u,u);
ccount=(261*301);
fprintf(fout,'%d\n',ccount);
for i=1:nr
for j=1:nc
if (flag(i,j)==1)&(i>=180)&(i<=440)&(j>=100)&(j<=400)
fprintf(fout,'%f %f %f\n',XM(i,j),YM(i,j),ZM(i,j));
end
end
end
else
error('range data is wrong');
end
fclose(fout);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -