Metric
R2026bDescription
Add-On Required: This feature requires the Optical Design and Simulation Library for Image Processing Toolbox add-on.
Metric functions for analysis of optical system.
Creation
Create a collection of optical metric functions using the opticalMeritFunction function. The opticalMeritFunction
function creates a 1-by-n array of Metric
objects. Each element in the array is an object of one of these types of metric function
classes.
Examples
Import an optical system into the workspace.
opsys = zmximport("PhotographicLens.zmx");Create an empty optical merit function.
meritFcn = opticalMeritFunction;
Add a custom metric function that returns only the residual score. The custom function maxDistortionMetric is defined at the end of this example.
meritFcn = addCustomMetric(meritFcn,@maxDistortionMetric,Target=2.0,Name="Max Distortion (%)")meritFcn =
opticalMeritFunction with properties:
Metrics: [1×1 optics.metric.CustomMetric]
Weights: 1
MetricsTable: [1×3 table]
Evaluate the merit function for the optical system.
[score,rawMetricValues] = evaluate(meritFcn,opsys)
score = 1.8706
rawMetricValues = 1.8706
Custom Function
The maxDistortionMetric custom function measures the strongest lens distortion across the field, and computes how far it is from the desired target. If the target value is 0, the function returns the greatest distortion magnitude. Otherwise, it returns a normalized nonnegative score indicating how much that distortion exceeds the target.
function score = maxDistortionMetric(opsys,target) distResult = lensDistortion(opsys); maxDist = max(abs(distResult.Distortion),[],"all"); if target(1) == 0 score = maxDist; else score = max(0,(maxDist-target(1))/target(1)); end end
Import an optical system into the workspace.
opsys = zmximport("PhotographicLens.zmx");Create an empty optical merit function.
meritFcn = opticalMeritFunction;
Add a custom metric function that returns the residual and raw score. The custom function chromaticMetric is defined at the end of this example.
meritFcn = addCustomMetric(meritFcn,@chromaticMetric,Target=[0.001 0.005],Name="Lateral Chromatic Aberration")meritFcn =
opticalMeritFunction with properties:
Metrics: [1×1 optics.metric.CustomMetric]
Weights: 1
MetricsTable: [1×3 table]
Evaluate the merit function for the optical system.
[score,rawMetricValues] = evaluate(meritFcn,opsys)
score = 1.3402
rawMetricValues = 0.0117
Custom Function
The chromaticMetric custom function measures the strongest lateral chromatic aberration across the field, and penalizes deviations outside a desired limit or range. The function computes the maximum lateral chromatic aberration of the optical system as the raw metric value, and compares this value to a target range to compute the residual score. If the target is a single value, it returns a normalized score of how much the raw metric exceeds that value (0, if within the limit). If the target is a range, the score is 0 if the metric lies within the range. Otherwise, the function returns a normalized score of how far the metric is from the nearest boundary.
function [residualScore, metricValue] = chromaticMetric(opsys,target) caResult = chromaticAberration(opsys); % metricValue: the physically meaningful quantity (lateral chromatic aberration) metricValue = max(abs(caResult.Lateral.Aberration),[],"all"); % residualScore: unitless penalty relative to target if target(1)==target(2) if target(1) == 0 residualScore = metricValue; else residualScore = max(0,(metricValue-target(1))/target(1)); end else if metricValue >= target(1) && metricValue <= target(2) residualScore = 0; else diffs = abs(target - metricValue); [~,idx] = min(diffs); residualScore = abs(metricValue-target(idx))/target(idx); end end end
Version History
Introduced in R2026b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)