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)