clear;clc;close all;
%读入所有raw格式的文件
raw=dir('I:\picture data\新建文件夹\*.raw') ;
%进行排序
for i=1:length(raw)
for j=1:length(raw)-i
x=raw(i).date-raw(i+j).date;
for k=1:length(x)
if x(k)>0
a=raw(i);
raw(i)=raw(i+j);
raw(i+j)=a;
break
elseif x(k)<0
break
end
end
end
A{i,1}=raw(i).name;
end
disp('按时间顺序排列文件');disp(A);
%打开文件
pathname1=('I:\picture data\新建文件夹\');
pathname1=strcat(pathname1,raw(1).name);
fid=fopen(pathname1,'rb');%打开图片
raw0=fread(fid,[1000,1000],'uint16');%读取图片
raw0=abs(raw0'/16);
figure,imshow(raw0,[0 4096]);%显示图片
% 手动提取目标点
point_num=0;%no目标点
position=[];%目标点的位置
while 1
zoom on;
pause;
zoom off;
[x,y] = ginput(1);%鼠标取点
zoom out;
if isempty(x)
break;
end
x=round(x);
y=round(y);
position=[position;x y];
hold on;
plot(x,y,'y+','linewidth',1);
hold off;
point_num=point_num+1;
end
%开窗&边缘检测&找圆心
window=zeros(21,21);
center=[];
circle_center=[];
for i=1:point_num
window=raw0((position(i,2)-10:position(i,2)+10),((position(i,1)-10:position(i,1)+10)));
%进行边缘检测
edgeim = edge(window,'canny',[0.1 0.2],1);
figure(2),subplot(1,point_num,i);imshow(edgeim);
%找圆心
L=bwlabel(edgeim);
s=regionprops(L,'centroid');
centroids=cat(1,s.Centroid);
center=round(centroids);
[a,b]=size(center);
for i=1:a
if (center(i,1)-11)^2+(center(i,2)-11)^2<50
circle_center=[circle_center;center(i,1) center(i,2)];
hold on
plot(center(i,1),center(i,2),'r*')
hold off
end
end
end
%输出结果
circle_center=position-11+circle_center;
disp('选取的圆心坐标如下:')
disp(circle_center)
评论0