function zernikeAO(src,event,varargin)
%Retains data between function calls
persistent slmDisplay hFig plotData Table Piston TiltX TiltY Power AstigX AstigY ComaX ComaY PrimarySpherical TrefoilX TrefoilY SecondaryAstigX SecondaryAstigY SecondaryComaX SecondaryComaY SecondarySpherical TetrafoilX TetrafoilY TertiarySpherical QuaternarySpherical iteration
hSI = src.hSI; % get the handle to the ScanImage zerModel
range=10; % chart starts to scroll once this many points have been acquired
stepSize=0.5;
changeNumber=2*range/stepSize+1;
%Image = libpointer('uint8Ptr', zeros(width*height,1));
switch event.EventName
case 'focusStart'
addpath('C:\Program Files\Meadowlark Optics\Blink OverDrive Plus\SDK','-begin');
% Iteratively optimize image intensity by Zernike
% Instructions:
%
% * Add the directory containing this function to your path
% * In ScanImage go to Settings > User Functions and
% assign "ZernikeAO" to the events:
% focusStart
% frameAcquired
%
% * Ensure all are enabled
% * Set up to acquire data on channel 1
% * Press Focus
% * Try pressing Abort then focus again. See how the figure is cleared
% first before data are added.
%
%% load the SDK of SLM
% Load the DLL
% Blink_C_wrapper.dll, Blink_SDK.dll, ImageGen.dll, FreeImage.dll and wdapi1021.dll
% should all be located in the same directory as the program referencing the
% library
if ~libisloaded('Blink_C_wrapper')
loadlibrary('Blink_C_wrapper.dll', 'Blink_C_wrapper.h');
end
% This loads the image generation functions
if ~libisloaded('ImageGen')
loadlibrary('ImageGen.dll', 'ImageGen.h');
end
% Basic parameters for calling Create_SDK
bit_depth = 12; %bit depth = 8 for small 512, 12 for 1920
num_boards_found = libpointer('uint32Ptr', 0);
constructed_okay = libpointer('int32Ptr', 0);
is_nematic_type = 1;
RAM_write_enable = 1;
use_GPU = 1;
max_transients = 10;
wait_For_Trigger = 0; % This feature is user-settable; use 1 for 'on' or 0 for 'off'
timeout_ms = 5000;
%Both pulse options can be false, but only one can be true. You either generate a pulse when the new image begins loading to the SLM
%or every 1.184 ms on SLM refresh boundaries, or if both are false no output pulse is generated.
OutputPulseImageFlip = 0;
OutputPulseImageRefresh = 0; %only supported on 1920x1152, FW rev 1.8.
% - This regional LUT file is only used with Overdrive Plus, otherwise it should always be a null string
reg_lut = libpointer('string');
% Call the constructor
calllib('Blink_C_wrapper', 'Create_SDK', bit_depth, num_boards_found, constructed_okay, is_nematic_type, RAM_write_enable, use_GPU, max_transients, reg_lut);
% if isempty(iteration)
% iteration=1;
% else
% iteration=1+iteration;
% end
% constructed okay return of 0 is success, nonzero integer is an error
% if constructed_okay.value ~= 0
% disp('Blink SDK was not successfully constructed');
% disp(calllib('Blink_C_wrapper', 'Get_last_error_message'));
% calllib('Blink_C_wrapper', 'Delete_SDK');
% else
board_number = 1;
% disp('Blink SDK was successfully constructed');
% fprintf('Found %u SLM controller(s)\n', num_boards_found.value);
height = calllib('Blink_C_wrapper', 'Get_image_height', board_number);
width = calllib('Blink_C_wrapper', 'Get_image_width', board_number);
%allocate arrays for our images
Image = libpointer('uint8Ptr', zeros(width*height,1));
%WFC = libpointer('uint8Ptr', zeros(width*height,1));
%***you should replace *bit_linear.LUT with your custom LUT file***
%but for now open a generic LUT that linearly maps input graylevels to output voltages
%***Using *bit_linear.LUT does NOT give a linear phase response***
if width == 512
lut_file = 'C:\\Program Files\\Meadowlark Optics\\Blink OverDrive Plus\\LUT Files\\8bit_linear.LUT';
else
lut_file = 'C:\\Program Files\\Meadowlark Optics\\Blink OverDrive Plus\\LUT Files\\12bit_linear.LUT';
end
calllib('Blink_C_wrapper', 'Load_LUT_file', board_number, lut_file);
% Generate a blank wavefront correction image, you should load your
% custom wavefront correction that was shipped with your SLM.
% PixelValue = 0;
% calllib('ImageGen', 'Generate_Solid', WFC, width, height, PixelValue);
% WFC = reshape(WFC.Value, [width,height]);
% Start the SLM with a blank image
% calllib('Blink_C_wrapper', 'Write_image', board_number, WFC, width*height, wait_For_Trigger, OutputPulseImageFlip, OutputPulseImageRefresh, timeout_ms);
% calllib('Blink_C_wrapper', 'ImageWriteComplete', board_number, timeout_ms);
%% iteratively change the image of SLM and get data from scanimage
iteration=1;
[file,path] = uigetfile('*.xlsx*','select GRIN lens location file');
Table = readtable(fullfile(path,file));
% Look for a figure window that contains data from a previous
% run of meanFrame. Make one if it doesn't exist, wipe it if it
% does.
hFig = findobj(0,'Name','meanFramePlot');
if isempty(hFig)
hFig = figure;
hFig.Name='meanFramePlot';
end
figure(hFig)
tmpC = cla;
plotData=plot(tmpC, nan, 'r-o', 'LineWidth', 2); %Plot a nan
title('zernike mode 1 : Piston')
grid off
xlim([-range,range])
pupilimg=uint8(zeros(height,width));
for pupilnumber=1:size(Table,1)
% Generate a zernike
CenterX=Table.CxP(pupilnumber);
CenterY=Table.CyP(pupilnumber);
Radius=Table.Rp(pupilnumber);
Piston=-range;
TiltX=0;
TiltY=0;
Power=0;
AstigX=0;
AstigY=0;
ComaX=0;
ComaY=0;
PrimarySpherical=0;
TrefoilX=0;
TrefoilY=0;
SecondaryAstigX=0;
SecondaryAstigY=0;
SecondaryComaX=0;
SecondaryComaY=0;
SecondarySpherical=0;
TetrafoilX=0;
TetrafoilY=0;
TertiarySpherical=0;
QuaternarySpherical=0;
calllib('ImageGen','Generate_Zernike',Image,width,height,CenterX,CenterY,Radius,Piston,TiltX,TiltY,Power,AstigX,AstigY,ComaX,ComaY,PrimarySpherical,TrefoilX,TrefoilY,SecondaryAstigX,SecondaryAstigY,SecondaryComaX,SecondaryComaY, SecondarySpherical,TetrafoilX,TetrafoilY,TertiarySpherical,QuaternarySpherical)
img= reshape(Image.Value, [width,height]);
%Image = rot90(mod(Image+WFC, 256));
img = flipud(rot90(mod(img,256)));
%create a pupil mask
pupilMask=poly2mask(CenterX+Radius*cos(0:0.1:2*pi),CenterY+Radius*sin(0:0.1:2*pi),height,width);
pupilMask=uint8(pupilMask);
pupilimg=img.*pupilMask+pupilimg;
end
%write image returns on DMA complete, ImageWriteComplete returns when the hardware
%image buffer is ready to receive the next image. Breaking this into two functions is
%useful for external triggers. It is safe to apply a trigger when Write_image is complete
%and it is safe to write a new image when ImageWriteComplete returns
calllib('Blink_C_wrapper', 'Write_image', board_number, pupil
没有合适的资源?快使用搜索试试~ 我知道了~
基于Matlab的自适应光学Zernike.zip
共6个文件
m:5个
xlsx:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 105 浏览量
2024-02-19
00:25:10
上传
评论 1
收藏 20KB ZIP 举报
温馨提示
1.版本:matlab2014/2019a/2021a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
资源推荐
资源详情
资源评论
收起资源包目录
基于Matlab的自适应光学Zernike.zip (6个子文件)
基于Matlab的自适应光学Zernike
Adaptive-Optics-Zernike-main
zernikeTest.m 7KB
organizedZernikeAO.m 24KB
zernikeAO.m 25KB
test.m 22KB
GRIN lens position.xlsx 3KB
meanFrame.m 2KB
共 6 条
- 1
资源评论
- weixin_546006412024-04-17感谢资源主的分享,很值得参考学习,资源价值较高,支持!
matlab科研助手
- 粉丝: 2w+
- 资源: 2320
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功