weixin_43001417
weixin_43001417
2018-12-22 13:02

想要用MATLAB求取光斑中能量占比所对用的角度,感觉程序少了很多,麻烦帮助一下啊

clear;
fig_test = imread('E:\光斑图\12.19.bmp');
dlmwrite('b1.txt',fig_test(:,:,1))

%%图像重构,建立三维图像并进行滤波处理
[size_x,size_y]=size(text);
count=1;
fig_new=reshape(size_x,size_y,count);

f=[1 2 1;2 4 2;1 2 1 ]/16;
for k=1:10
fig_new(:,:,1)=filter2(f,fig_new(:,:,1));
end

%方法3
fig_back=[128,128,128,128,128];%,112,128,128,144];%,1296,1280,1344,1360];%CCD统计本底,从CCD软件histgram中读取
fig_deback=zeros(size_x,size_y,count);
for i=1
fig_deback(:,:,i)=fig_new(:,:,i)-fig_back(i);
end

%%小于零的点归零处理
for k0=1
for i=1:size_x
for j=1:size_y
if fig_deback(i,j,k0)<0
fig_deback(i,j,k0)=0;
end
end
end
end

fig_db=double(fig_deback);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%注意更爱需要清除的内存变量,注意下面参数的数量要至少包含所使用的图,一般够用就不用改
clear fig1 fig2 fig3 fig4 fig5 fig6 fig7 fig8 fig9 fig10 fig11 fig12 fig13 fig14 fig15 fig16
clear fig_back fig_org fig_new fig_deback
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%计算能量质心
XM=zeros(1);YM=zeros(1);MM=zeros(1);
for k1=1
for i=1:size_x
for j=1:size_y
XM(k1)=fig_db(i,j,k1)*i+XM(k1);
YM(k1)=fig_db(i,j,k1)*j+YM(k1);
MM(k1)=fig_db(i,j,k1)+MM(k1);
end
end
XM(k1)=fix(XM(k1)/MM(k1));%X轴能量质心
YM(k1)=fix(YM(k1)/MM(k1));%Y轴能量质心
end
%%计算EE90和EE95的能量半径
R=zeros(1);r=zeros(1);EE=zeros(1);SUM=zeros(1);flag90=zeros(1);
R90=zeros(1);R95=zeros(1);flag95=zeros(1);
%为了节省时间给个初始的半径
for k3=1
while EE(k3)<=90%设定能量EE比值
for i=-r(k3):1:r(k3)
if 0 for j=-r(k3):1:r(k3)
if 0 if ((i^2+j^2)R(k3)^2)
SUM(k3)=fig_db(XM(k3)+i,YM(k3)+j,k3)+SUM(k3);
end
else
flag90(k3)=1;
continue;
end
end
else
flag90(k3)=1;
continue;
end
end
EE(k3)=(SUM(k3)+fig_db(XM(k3),YM(k3),k3))/MM(k3)*100;
R(k3)=r(k3);
r(k3)=r(k3)+1;
end
R90(k3)=R(k3);

while EE(k3)<=95%设定能力EE比值
for i=-r(k3):1:r(k3)
if 0 for j=-r(k3):1:r(k3)
if 0 if ((i^2+j^2)R(k3)^2)
SUM(k3)=fig_db(XM(k3)+i,YM(k3)+j,k3)+SUM(k3);
end
else
flag95(k3)=1;
continue;
end
end
else
flag95(k3)=1;
continue;
end
end
EE(k3)=(SUM(k3)+fig_db(XM(k3),YM(k3),k3))/MM(k3)*100;
R(k3)=r(k3);
r(k3)=r(k3)+1;
end
R95(k3)=R(k3);
end

RR90=R90*2*0.009;
RR95=R95*2*0.009;
%sprintf('\n%f\n%f,RR90,flag90)
sprintf('\n%f\n%f\n%f\n%f',RR90,flag90,RR95,flag95)

%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%保存EE90,EE95的光斑直径和光斑是否溢出的bajing 标记,X,Y方向的能量质心
save 'C:\E:\光斑图\R-XM-YM-flag6.mat' RR90 RR95 XM YM flag90 flag95
%%%% 注意更改数据保存路径,即更改 \R-XM-YM-flag.mat 之前的路径
function [X0,Y0,R] = Yuan(rgb) %定义函数,获得圆形区域的圆心坐标及半径
% MATLAB下寻找位图中圆形的圆心和半径
r = rgb(:,:,1); %红色分量
g = rgb(:,:,2); %绿色分量
b = rgb(:,:,3); %蓝色分量
I=0.59*r+0.11*g+0.3*b;%像素亮度计算公式
I = uint8(I);
[Height,Width]=size(I);
Thre=100; %预设阈值

for Row1 = 1:(Height/2) %循环寻找圆形区域上边界
CurRow_Bright = I(Row1,:);
Max = max(CurRow_Bright); %求取最大亮度值
Min = min(CurRow_Bright); %求取最小亮度值
Lim = Max-Min; %该扫描线的极限亮度差
if (Lim>Thre)
Ytop = Row1;
break;
end
end

for Row2 = Height:-1:(Height/2) %循环寻找圆形区域下边界
CurRow_Bright = I(Row2,:);
Max = max(CurRow_Bright); %求取最大亮度值
Min = min(CurRow_Bright); %求取最小亮度值
Lim = Max-Min; %该扫描线的极限亮度差
if (Lim>Thre)
Ybot = Row2;
break;
end
end

for Col1 = 1:(Width/2) %循环寻找圆形区域左边界
CurCol_Bright = I(:,Col1);
Max = max(CurCol_Bright); %求取最大亮度值
Min = min(CurCol_Bright); %求取最小亮度值
Lim = Max-Min; %该扫描线的极限亮度差
if (Lim>Thre)
Xleft = Col1;
break
end
end

for Col2 = Width:-1:Width/2 %循环寻找圆形区域右边界
CurCol_Bright = I(:,Col2);
Max = max(CurCol_Bright); %求取最大亮度值
Min = min(CurCol_Bright); %求取最小亮度值
Lim = Max-Min; %该扫描线的极限亮度差
if (Lim>Thre)
Xrig= Col2;
break
end
end
X0 = (Xleft+Xrig)/2;
Y0 = (Ytop+Ybot)/2;
Rx = floor((Xrig-Xleft)/2);
Ry = floor((Ytop-Ybot)/2);
R = max(Rx,Ry);
% %
% rgb(Ytop,Xleft:Xrig,1) = 255;
% rgb(Ytop,Xleft:Xrig,2) = 0;
% rgb(Ytop,Xleft:Xrig,3) = 0;
%
% rgb(Ybot,Xleft:Xrig,1) = 0;
% rgb(Ybot,Xleft:Xrig,2) = 255;
% rgb(Ybot,Xleft:Xrig,3) = 0;
%
% rgb(Ytop:Ybot,Xleft,1) = 0;
% rgb(Ytop:Ybot,Xleft,2) = 255;
% rgb(Ytop:Ybot,Xleft,3) = 0;
%
% rgb(Ytop:Ybot,Xrig,1) = 0;
% rgb(Ytop:Ybot,Xrig,2) = 0;
% rgb(Ytop:Ybot,Xrig,3) = 255;
%
% figure, imshow(rgb);
end
这是我所有的程序,感觉缺少了好多,想麻烦帮我改一下。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐