a2008.m
来自「利用matlab对图像进行读入与处理(运用在仿真领域)」· M 代码 · 共 40 行
M
40 行
%------------------------------------------------------------------------------------------------------
% center detect
% Designed by Zhengchun LIN. Start: 2008.9.19 Finished:
%------------------------------------------------------------------------------------------------------
clear;clc;
filename='A2008.bmp';
A=imread(filename);
A=rgb2gray(A);
image_size=size(A);
B=A;
t=100;
centers=[];
for i=1:image_size(1)
for j=1:image_size(2)
if A(i,j)<=t
[near_points,A]=near_area_detect(A,[i,j],t);
temp_center=[sum(near_points(:,1)),sum(near_points(:,2))]/size(near_points,1);
centers=[centers;temp_center];
end
end
end
disp('圆心坐标为:');disp(centers);
B_colormap=colormap(gray(256));
center_color=[1,0,0];center_gray=101;
B_colormap(center_gray,:)=center_color;
centers=round(centers);
for i=1:size(centers,1)
for ii=-3:3
x=centers(i,1);y=centers(i,2);
xx=x+ii;yy=y+ii;
if xx>0 & xx<=image_size(1)
B(xx,y)=center_gray;
end
if yy>0 & yy<=image_size(2)
B(x,yy)=center_gray;
end
end
end
figure;imshow(B,B_colormap);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?