EPICS IOC Using MATLAB for Image Analysis of
EPICS IOC Using MATLAB for Image Analysis of Diagnostic Applications Speaker: Chih-Yu, Liao (廖志裕) Instrumentation & Control Group, NSRRC, Taiwan EPICS 2011 EPICS Collaboration Meeting Spring 2011
Outline 1. 2. 3. 4. Motivation Overview of infrastructure Application in image analysis Summary 2 2011 EPICS Meeting
Motivation • The most of machine parameters will be accessible as EPICS PV in future TPS (Taiwan Photon Source) facility. • We need a tool with the complex calculation and display ability that use EPICS PV as inputs. • Could we implement it by using current existing resources? • In this moment, we chose the MATLAB 3 2011 EPICS Meeting
Why MATLAB ? • MATLAB offers a familiar environment – Regular use of MATLAB in our group • Save development time and manpower – High level programming language – Extensive built-in functions and toolboxes – Powerful graphics capability • Adequate GUI capabilities – MATLAB's GUI Development Environment (GUIDE) • There are many resources available in internet • Easy communication with the EPICS 4 2011 EPICS Meeting
How EPICS interacts with MATLAB? • Tools for low level channel access to EPICS – Lab. CA (MATLAB Channel Access) – MCA (MATLAB Channel Access) – SCA (Simple Channel Access) Have not tried! • What is Lab. CA? – The Lab. CA package is one of the EPICS extensions, which provides an interface to the EPICS channel access client library and can be integrated with the MATLAB applications. 5 2011 EPICS Meeting
Channel Access in MATLAB via Lab. CA ü Start matlab: matlab ü Add the Lab. CA library – addpath /opt/epics/extensions/src/ labca_3_1/ bin/linux-x 86/labca ü Read value from PV – lca. Get(‘PV name’) ü Write value into PV – lca. Put(‘PV name’, value) • Advanced functions – lca. Get. Retry. Count, lca. Set. Timeout – lca. Get. Timeout, lca. Set. Retry. Count, … 6 2011 EPICS Meeting
Overview of infrastructure Ø Components – PC, Ethernet, EPICS environment – IOC, Compiled MATLAB program Ø EPICS IOC: Controlling devices and collecting data. Ø Client OPI: Monitoring/setting the devices and the MATLAB program Ø MATLAB program: Through the Lab. CA Read the database, Analyze it, then Store the results back to the database Client OPI Application (EDM, MATLAB) Channel Access Client Ethernet Channel Access Server/Client Lab. CA MATLAB Database Instrumentations 2011 EPICS Meeting TCP (raw), Modbus/TCP, VXI-11, … Device Support EPICS IOC + MATLAB 7
Application in Image Acquisition and Analysis Client OPI Application (EDM, MATLAB) Camera Control Panel MATLAB Display GUI TPS Control Network Acquisition EPICS IOC Private Ethernet ……… Gig. E Vision Cameras Instrumentations 2011 EPICS Meeting Analysis EPICS IOC MATLAB. Ø Two EPICS IOC: One for image acquisition, one for image analysis (running MATLAB app) Ø Devices: Gig. E vision cameras Ø Networks: One for cameras, one for control Ø Clients: Remote control the camera parameters, display the analysis results 8
EPICS IOC Record Usage • Image Acquisition IOC – – waveform (Image Raw Data) ai (Exposure Time) bi (Camera Control) mbbi (Trigger Mode) • Image Analysis IOC – stringin (Status Display) – waveform (Profiles) – ai (Results) Image Acquisition IOC waveform LI-DI-SM: image#: Array. Data ai LI-DI-SM: cam#: Acquire. Time bi LI-DI-SM: image#: Enable. Callbacks bi LI-DI-SM: cam#: Acquire mbbi LI-DI-SM: cam#: Trigger. Mode Image Raw Data 0~1 sec YES/NO 1/0 Soft/Free/Ext. Image Analysis IOC stringin LI-DI-SM: Status ai LI-DI-SM: Center. X Beam Center X ai LI-DI-SM: Center. Y Beam Center Y ai LI-DI-SM: Tilt. Ang Beam Tilt Angle ai LI-DI-SM: Sigma. X Beam Sigma X ai LI-DI-SM: Sigma. Y Beam Sigma Y ai LI-DI-SM: Factor mm/pixel ai LI-DI-SM: RMSEx Goodness of fit X ai LI-DI-SM: RMSEy Goodness of fit Y waveform LI-DI-SM: profile. X Image X Projection waveform LI-DI-SM: profile. Y Image Y Projection waveform LI-DI-SM: profile. Fit. X Fitting X Projection waveform LI-DI-SM: profile. Fit. Y Fitting Y Projection 9 2011 EPICS Meeting
Features of the MATLAB GUI l Two MATLAB GUIs (same interface, different functionality) – Analysis GUI, running only in dedicated computer – Display GUI, running in multiple clients simultaneously l Analysis GUI (analytical work) – – Analysis beam parameters (Center, Sigma, Tilt angle) Specify adjustable region-of-interest (ROI) Optional background subtraction & Software multiple exposure Store all analysis results into IOC PVs l Display GUI (display only) – Read / display the analysis results (PVs) – Export the data (raw image and analysis results) – Create a simulated beam profile 10 2011 EPICS Meeting
Analysis/Display GUI Menu: Save, Colormap, ROI, Simulation, Reset, Close Toolbar: Zoom in/out Control Panel Fitting Results Capture Date Hor. Projected Profile Gree: Raw, Blue: Fit Enable/Disable Fitting Threshold Camera ID Raw Image Ver. Projected Profile Gree: Raw, Blue: Fitting Parameters RMSE, Offset, Slope, Max Colorbar 2011 EPICS Meeting Fitting Elapsed Time 11
Flow Chart of MATLAB Analysis GUI MATLAB Program START “No Camera Active” Camera Enable. Callbacks Camera Acquired Camera Active? “Screen Not Ready” No Yes Screen Position “in/out” Pixel Mapping Factor Screen Ready? No Yes Image Data Array Image Size X, Y Get Image Data from Acquisition IOC Image Process Find Center & Tilt Gaussian Fitting Display Results and Store into Analysis IOC 2011 EPICS Meeting Reshape Image Array RIO selection Projection process SM ID, Image Projected Profiles X, Y Sigma, Central Position, Tilt Angle Fitting Parameters & Profiles 12
Flow Chart of MATLAB Display GUI MATLAB Program START Enable Simulation ? No Yes Create a Simulated Beam Image Gaussian Fitting Find Center & Tilt Display Results in GUI Get Analyzed Data from Analysis IOC SM ID, Image Projected Profiles X, Y Sigma, Central Position, Tilt Angle Fitting Parameters & Profiles 13 2011 EPICS Meeting
Performance • MATLAB Analysis GUI – Read/Write data < 60 ms – Fitting program < 80 ms – Updating GUI < 40 ms Total Max. processing rate < 180 ms > 5 Hz For TPS is OK!! 14 2011 EPICS Meeting
Summary • Using MATLAB to assist EPICS IOC – Improve the IOC calculation ability – An alternative solution for complex data analysis – Saves considerable time and effort • From performance point of view, there would be no problem running the application (screen monitor image analysis) on TPS (Injector repetition rate is 3 Hz). • Extended applications – Real-time oscilloscope waveform analysis – Synchrotron radiation monitor image analysis – Other equipments data processing Thanks for Your Attention! 2011 EPICS Meeting 15
- Slides: 15