@photivra/engine 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CITATION.cff +23 -0
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +235 -0
- package/dist/camera/field-of-view.d.ts +37 -0
- package/dist/camera/field-of-view.d.ts.map +1 -0
- package/dist/camera/field-of-view.js +47 -0
- package/dist/camera/field-of-view.js.map +1 -0
- package/dist/camera/projected-object-size.d.ts +34 -0
- package/dist/camera/projected-object-size.d.ts.map +1 -0
- package/dist/camera/projected-object-size.js +57 -0
- package/dist/camera/projected-object-size.js.map +1 -0
- package/dist/core/calculation-result.d.ts +125 -0
- package/dist/core/calculation-result.d.ts.map +1 -0
- package/dist/core/calculation-result.js +175 -0
- package/dist/core/calculation-result.js.map +1 -0
- package/dist/core/validation.d.ts +30 -0
- package/dist/core/validation.d.ts.map +1 -0
- package/dist/core/validation.js +45 -0
- package/dist/core/validation.js.map +1 -0
- package/dist/exposure/exposure.d.ts +50 -0
- package/dist/exposure/exposure.d.ts.map +1 -0
- package/dist/exposure/exposure.js +62 -0
- package/dist/exposure/exposure.js.map +1 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/motion/projected-motion.d.ts +41 -0
- package/dist/motion/projected-motion.d.ts.map +1 -0
- package/dist/motion/projected-motion.js +84 -0
- package/dist/motion/projected-motion.js.map +1 -0
- package/dist/optics/aperture.d.ts +39 -0
- package/dist/optics/aperture.d.ts.map +1 -0
- package/dist/optics/aperture.js +62 -0
- package/dist/optics/aperture.js.map +1 -0
- package/dist/optics/circle-of-confusion.d.ts +23 -0
- package/dist/optics/circle-of-confusion.d.ts.map +1 -0
- package/dist/optics/circle-of-confusion.js +32 -0
- package/dist/optics/circle-of-confusion.js.map +1 -0
- package/dist/optics/depth-of-field.d.ts +53 -0
- package/dist/optics/depth-of-field.d.ts.map +1 -0
- package/dist/optics/depth-of-field.js +81 -0
- package/dist/optics/depth-of-field.js.map +1 -0
- package/dist/optics/diffraction.d.ts +26 -0
- package/dist/optics/diffraction.d.ts.map +1 -0
- package/dist/optics/diffraction.js +21 -0
- package/dist/optics/diffraction.js.map +1 -0
- package/dist/optics/thin-lens.d.ts +30 -0
- package/dist/optics/thin-lens.d.ts.map +1 -0
- package/dist/optics/thin-lens.js +33 -0
- package/dist/optics/thin-lens.js.map +1 -0
- package/dist/output/crop.d.ts +27 -0
- package/dist/output/crop.d.ts.map +1 -0
- package/dist/output/crop.js +26 -0
- package/dist/output/crop.js.map +1 -0
- package/dist/output/subject-framing-crop.d.ts +36 -0
- package/dist/output/subject-framing-crop.d.ts.map +1 -0
- package/dist/output/subject-framing-crop.js +42 -0
- package/dist/output/subject-framing-crop.js.map +1 -0
- package/dist/schema/camera.d.ts +34 -0
- package/dist/schema/camera.d.ts.map +1 -0
- package/dist/schema/camera.js +3 -0
- package/dist/schema/camera.js.map +1 -0
- package/dist/schema/scene.d.ts +69 -0
- package/dist/schema/scene.d.ts.map +1 -0
- package/dist/schema/scene.js +3 -0
- package/dist/schema/scene.js.map +1 -0
- package/dist/schema/validation.d.ts +25 -0
- package/dist/schema/validation.d.ts.map +1 -0
- package/dist/schema/validation.js +180 -0
- package/dist/schema/validation.js.map +1 -0
- package/dist/sensor/pixel-pitch.d.ts +21 -0
- package/dist/sensor/pixel-pitch.d.ts.map +1 -0
- package/dist/sensor/pixel-pitch.js +19 -0
- package/dist/sensor/pixel-pitch.js.map +1 -0
- package/dist/sensor/signal-noise.d.ts +37 -0
- package/dist/sensor/signal-noise.d.ts.map +1 -0
- package/dist/sensor/signal-noise.js +53 -0
- package/dist/sensor/signal-noise.js.map +1 -0
- package/dist/simulation/poc-simulation.d.ts +264 -0
- package/dist/simulation/poc-simulation.d.ts.map +1 -0
- package/dist/simulation/poc-simulation.js +449 -0
- package/dist/simulation/poc-simulation.js.map +1 -0
- package/dist/stabilization/camera-shake.d.ts +41 -0
- package/dist/stabilization/camera-shake.d.ts.map +1 -0
- package/dist/stabilization/camera-shake.js +79 -0
- package/dist/stabilization/camera-shake.js.map +1 -0
- package/docs/API_STYLE.md +65 -0
- package/docs/ARCHITECTURE.md +51 -0
- package/docs/MOTION_AND_SIGNAL.md +53 -0
- package/docs/PHYSICS_FOUNDATION.md +92 -0
- package/docs/POC_API.md +210 -0
- package/docs/PROVENANCE.md +87 -0
- package/docs/STABILIZATION.md +78 -0
- package/docs/USAGE.md +538 -0
- package/package.json +91 -0
package/CITATION.cff
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use Photivra in research or technical work, please cite it using the metadata below."
|
|
3
|
+
title: "Photivra"
|
|
4
|
+
type: software
|
|
5
|
+
authors:
|
|
6
|
+
- family-names: "Shackelford"
|
|
7
|
+
given-names: "William"
|
|
8
|
+
abstract: "An open TypeScript engine for the science and mathematics of photography and digital imaging."
|
|
9
|
+
repository-code: "https://github.com/photivra/photivra"
|
|
10
|
+
url: "https://photivra.com"
|
|
11
|
+
license: "Apache-2.0"
|
|
12
|
+
version: "0.1.0"
|
|
13
|
+
keywords:
|
|
14
|
+
- photography
|
|
15
|
+
- camera optics
|
|
16
|
+
- digital imaging
|
|
17
|
+
- imaging science
|
|
18
|
+
- depth of field
|
|
19
|
+
- exposure
|
|
20
|
+
- motion blur
|
|
21
|
+
- diffraction
|
|
22
|
+
- sensor sampling
|
|
23
|
+
- signal-to-noise
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Photivra
|
|
2
|
+
Copyright 2026 William Shackelford
|
|
3
|
+
|
|
4
|
+
This repository contains the Photivra scientific/business-logic engine.
|
|
5
|
+
|
|
6
|
+
Source code in this repository is made available under the Apache License,
|
|
7
|
+
Version 2.0. The Apache License does not grant permission to use Photivra
|
|
8
|
+
trade names, trademarks, service marks, product names, logos, or branding
|
|
9
|
+
except as allowed by applicable law and the license itself.
|
package/README.md
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# Photivra
|
|
2
|
+
|
|
3
|
+
Photivra is an open TypeScript engine for the science and mathematics of photography and digital imaging.
|
|
4
|
+
|
|
5
|
+
**Pronunciation (IPA):** /foʊˈtɪvɹə/
|
|
6
|
+
|
|
7
|
+
Photivra provides a reusable, tested API for camera geometry, optics, focus and depth of field, exposure, subject and camera motion, sensor sampling, diffraction, cropping and framing, stabilization approximations, and signal/noise calculations.
|
|
8
|
+
|
|
9
|
+
Its calculations use explicit units, documented assumptions, validation, provenance, and clearly labeled approximations so results are reproducible and their limitations are understandable.
|
|
10
|
+
|
|
11
|
+
The source is licensed under Apache-2.0.
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
Install the ESM package:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install @photivra/engine
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Calculate horizontal field of view for a 36 mm sensor dimension and 50 mm focal length:
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { calculateFieldOfView } from "@photivra/engine";
|
|
25
|
+
|
|
26
|
+
const horizontal = calculateFieldOfView({
|
|
27
|
+
focalLengthMm: 50,
|
|
28
|
+
sensorDimensionMm: 36
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log(horizontal.value.degrees);
|
|
32
|
+
console.log(horizontal.provenance);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
See the [Usage Guide](docs/USAGE.md) for the complete public API.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
- [Usage Guide](docs/USAGE.md)
|
|
40
|
+
- [Public API Style](docs/API_STYLE.md)
|
|
41
|
+
- [Architecture](docs/ARCHITECTURE.md)
|
|
42
|
+
- [Physics Foundation](docs/PHYSICS_FOUNDATION.md)
|
|
43
|
+
- [Motion and Signal Foundation](docs/MOTION_AND_SIGNAL.md)
|
|
44
|
+
- [Camera Shake and Stabilization](docs/STABILIZATION.md)
|
|
45
|
+
- [Scientific and Source Provenance](docs/PROVENANCE.md)
|
|
46
|
+
- [Local POC HTTP API](docs/POC_API.md)
|
|
47
|
+
|
|
48
|
+
## Getting help
|
|
49
|
+
|
|
50
|
+
Use [GitHub Issues](https://github.com/photivra/photivra/issues) for reproducible bugs, documentation problems, and feature discussions. For security vulnerabilities, follow [SECURITY.md](SECURITY.md).
|
|
51
|
+
|
|
52
|
+
## What is implemented
|
|
53
|
+
|
|
54
|
+
The root package exports deterministic or explicitly labeled approximate models across four areas.
|
|
55
|
+
|
|
56
|
+
### Optics and geometry
|
|
57
|
+
|
|
58
|
+
- [rectilinear field of view, with optional focus-aware thin-lens projection](docs/USAGE.md#field-of-view);
|
|
59
|
+
- [Gaussian thin-lens image distance and magnification](docs/USAGE.md#thin-lens-image-distance-and-magnification);
|
|
60
|
+
- [geometric depth of field and defocus-circle diameter](docs/USAGE.md#depth-of-field-and-defocus);
|
|
61
|
+
- [ideal circular-aperture first-zero Airy diameter](docs/USAGE.md#circular-aperture-diffraction);
|
|
62
|
+
- [ideal regular-polygon aperture geometry and sunstar direction symmetry](docs/USAGE.md#aperture-geometry-and-sunstar-directions).
|
|
63
|
+
|
|
64
|
+
### Exposure and motion
|
|
65
|
+
|
|
66
|
+
- [EV100, relative optical exposure, and equivalent ISO compensation](docs/USAGE.md#exposure-and-equivalent-iso);
|
|
67
|
+
- [constant-velocity projected point motion](docs/USAGE.md#projected-subject-motion);
|
|
68
|
+
- [a controlled yaw/pitch camera-shake and stabilization-equivalent approximation](docs/USAGE.md#camera-shake-and-stabilization-equivalent-approximation).
|
|
69
|
+
|
|
70
|
+
### Sensor and output
|
|
71
|
+
|
|
72
|
+
- [projected fronto-parallel object size and sensor-pixel sampling](docs/USAGE.md#projected-object-size-and-sensor-sampling);
|
|
73
|
+
- [pixel pitch](docs/USAGE.md#pixel-pitch);
|
|
74
|
+
- [centered crop and subject-height framing crop](docs/USAGE.md#centered-crop-and-subject-framing-crop);
|
|
75
|
+
- [mean photoelectron conversion and basic shot-noise/read-noise SNR primitives](docs/USAGE.md#photoelectron-and-snr-primitives).
|
|
76
|
+
|
|
77
|
+
### Data, validation, and composition
|
|
78
|
+
|
|
79
|
+
- [camera/scene schemas and runtime validation](docs/USAGE.md#camera-and-scene-schema-validation);
|
|
80
|
+
- [provenance plus optional uncertainty/quality metadata](docs/USAGE.md#provenance-uncertainty-and-quality-metadata);
|
|
81
|
+
- [the composed `simulatePocCamera()` proof-of-concept calculation](docs/USAGE.md#composed-poc-simulation).
|
|
82
|
+
|
|
83
|
+
The package has no runtime npm dependencies.
|
|
84
|
+
|
|
85
|
+
## Sample use case
|
|
86
|
+
|
|
87
|
+
A developer wants to model how a change in camera settings affects an image.
|
|
88
|
+
|
|
89
|
+
Using Photivra, the application can provide camera and scene parameters—such as sensor dimensions, focal length, aperture, shutter speed, focus distance, subject distance, and motion—and receive structured scientific results describing effects such as:
|
|
90
|
+
|
|
91
|
+
- field of view;
|
|
92
|
+
- projected subject size;
|
|
93
|
+
- depth of field and defocus;
|
|
94
|
+
- diffraction;
|
|
95
|
+
- subject-motion blur;
|
|
96
|
+
- camera-shake blur;
|
|
97
|
+
- pixel sampling;
|
|
98
|
+
- crop and framing;
|
|
99
|
+
- exposure relationships;
|
|
100
|
+
- basic signal and noise behavior.
|
|
101
|
+
|
|
102
|
+
Each result includes explicit units and model provenance, with approximations clearly identified rather than presented as exact physical measurements.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import {
|
|
106
|
+
calculateFieldOfView,
|
|
107
|
+
calculateDepthOfField,
|
|
108
|
+
calculateProjectedMotionBlur
|
|
109
|
+
} from "@photivra/engine";
|
|
110
|
+
|
|
111
|
+
const fieldOfView = calculateFieldOfView({
|
|
112
|
+
focalLengthMm: 200,
|
|
113
|
+
sensorDimensionMm: 36,
|
|
114
|
+
focusDistanceM: 22
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const depthOfField = calculateDepthOfField({
|
|
118
|
+
focalLengthMm: 200,
|
|
119
|
+
aperture: 5.6,
|
|
120
|
+
focusDistanceM: 22,
|
|
121
|
+
circleOfConfusionMm: 0.03
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const motion = calculateProjectedMotionBlur({
|
|
125
|
+
focalLengthMm: 200,
|
|
126
|
+
shutterSeconds: 1 / 1000,
|
|
127
|
+
positionM: { x: 0, y: 1, z: 22 },
|
|
128
|
+
velocityMps: { x: 10, y: 0, z: 0 },
|
|
129
|
+
focusDistanceM: 22,
|
|
130
|
+
pixelPitchMicrometers: 6
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
console.log(fieldOfView.value);
|
|
134
|
+
console.log(depthOfField.value);
|
|
135
|
+
console.log(motion.value);
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The calling application can then use those results while keeping the underlying photography calculations centralized, tested, and reproducible.
|
|
139
|
+
|
|
140
|
+
## Status
|
|
141
|
+
|
|
142
|
+
- Package version: `0.1.0`
|
|
143
|
+
- Engine API contract: `0.17.0`
|
|
144
|
+
- Stability: pre-1.0 / proof of concept
|
|
145
|
+
|
|
146
|
+
Package version and engine API version are intentionally separate. Public APIs may evolve before 1.0 while the scientific models and composition contracts are validated.
|
|
147
|
+
|
|
148
|
+
Making this GitHub repository public and publishing `@photivra/engine` to a package registry are separate release actions.
|
|
149
|
+
|
|
150
|
+
## Important scientific limits
|
|
151
|
+
|
|
152
|
+
Photivra deliberately avoids claiming more than the current models support.
|
|
153
|
+
|
|
154
|
+
- Focus-aware projection is ideal paraxial thin-lens geometry, not a real-lens focus-breathing or macro calibration model.
|
|
155
|
+
- Projected subject motion follows a representative point under constant linear velocity. It does not yet model scale blur of an extended object moving substantially along the optical axis.
|
|
156
|
+
- Camera shake is represented by one global yaw/pitch image-plane vector. Spatially varying rotational optical flow, roll, translation, and real IBIS/OIS behavior are not yet modeled.
|
|
157
|
+
- The Airy diagnostic assumes an ideal circular pupil. Polygon aperture geometry does not produce a polygon diffraction PSF.
|
|
158
|
+
- Signal/noise primitives require caller-supplied photon/electron quantities. The composed POC does not derive calibrated photon counts from scene imagery.
|
|
159
|
+
- No named commercial camera or lens performance is claimed.
|
|
160
|
+
|
|
161
|
+
See [Physics Foundation](docs/PHYSICS_FOUNDATION.md), [Motion and Signal Foundation](docs/MOTION_AND_SIGNAL.md), and [Camera Shake and Stabilization](docs/STABILIZATION.md) for details.
|
|
162
|
+
|
|
163
|
+
## Principles
|
|
164
|
+
|
|
165
|
+
- Independently implement established photography, optics, sensor, motion, and imaging mathematics.
|
|
166
|
+
- Do not copy code, datasets, calibration tables, model weights, or protected technical expression unless reuse rights are explicit and compatible with Apache-2.0 distribution.
|
|
167
|
+
- Treat publicly viewable material as reference material only; public availability is not permission to copy, and independent implementation does not by itself resolve third-party patent rights.
|
|
168
|
+
- Keep calculations deterministic and testable where the model itself is deterministic.
|
|
169
|
+
- Prefer explicit units, versioned schemas, consistent public APIs, and reproducible results.
|
|
170
|
+
- Label results by provenance: calculated, calibrated, estimated, or approximation.
|
|
171
|
+
- Report uncertainty/accuracy metadata only when it is defensible; never invent aggregate confidence or error bars.
|
|
172
|
+
- Keep the repository focused on reusable scientific/business logic, validation, schemas, tests, documentation, and contributor tooling.
|
|
173
|
+
|
|
174
|
+
## Runtime surfaces
|
|
175
|
+
|
|
176
|
+
The package is ESM-only.
|
|
177
|
+
|
|
178
|
+
The root export is the runtime-neutral scientific surface:
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
import {
|
|
182
|
+
calculateFieldOfView,
|
|
183
|
+
simulatePocCamera
|
|
184
|
+
} from "@photivra/engine";
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The root dependency graph is checked in CI so Node-only modules and the repository-local HTTP POC server cannot become reachable from that browser-facing surface.
|
|
188
|
+
|
|
189
|
+
The open repository still contains a minimal Node HTTP POC server under `src/api` for contributor integration testing. It is deliberately **not** exported by `@photivra/engine` and is excluded from the published npm package. It is unauthenticated and is **not** a production hosting recommendation.
|
|
190
|
+
|
|
191
|
+
When the package is installed directly from a Git repository using normal npm lifecycle scripts, `prepare` builds `dist` before consumption.
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
Development and Node-only tooling require Node.js 22.13 or newer. CI verifies Node.js 22.13 and Node.js 24; both are LTS release lines as of this documentation audit.
|
|
196
|
+
|
|
197
|
+
The reproducible npm workflow uses the committed lockfile:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
npm ci
|
|
201
|
+
npm run check
|
|
202
|
+
npm run coverage
|
|
203
|
+
npm run build
|
|
204
|
+
npm run pack:check
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Coverage gates are currently:
|
|
208
|
+
|
|
209
|
+
- 90% lines;
|
|
210
|
+
- 90% statements;
|
|
211
|
+
- 90% functions;
|
|
212
|
+
- 80% branches.
|
|
213
|
+
|
|
214
|
+
The deterministic fuzz/property suite uses fixed seeds so failures are reproducible.
|
|
215
|
+
|
|
216
|
+
Yarn and pnpm may be used for development, but the repository's release/CI dependency resolution is defined by `package-lock.json` and `npm ci`.
|
|
217
|
+
|
|
218
|
+
## Validation boundaries
|
|
219
|
+
|
|
220
|
+
TypeScript types are not treated as validation for untrusted data.
|
|
221
|
+
|
|
222
|
+
- Use `parseCameraConfiguration()` and `parseSceneDefinition()` for external camera/scene JSON.
|
|
223
|
+
- The repository-local Node POC HTTP layer has its own structural request parser before invoking `simulatePocCamera()`.
|
|
224
|
+
- Scientific range/domain validation remains in the calculation modules.
|
|
225
|
+
- Public `CalculationResult<T>` envelopes reject non-finite numeric output.
|
|
226
|
+
|
|
227
|
+
## Citation
|
|
228
|
+
|
|
229
|
+
GitHub can generate citation text from [CITATION.cff](CITATION.cff). Use that metadata when citing Photivra in research, technical documentation, or reproducible analyses.
|
|
230
|
+
|
|
231
|
+
## Licensing
|
|
232
|
+
|
|
233
|
+
Source code in this repository is licensed under Apache-2.0 unless a file clearly states otherwise. See [LICENSE](LICENSE), [NOTICE](NOTICE), and [THIRD_PARTY.md](THIRD_PARTY.md).
|
|
234
|
+
|
|
235
|
+
The Apache license does not grant trademark rights to the Photivra name, logos, or branding except as allowed by applicable law and the license itself.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type CalculationResult } from "../core/calculation-result.js";
|
|
2
|
+
export interface CalculateFieldOfViewInput {
|
|
3
|
+
/** Lens focal length in millimetres. */
|
|
4
|
+
focalLengthMm: number;
|
|
5
|
+
/** Sensor dimension corresponding to the requested field of view, in millimetres. */
|
|
6
|
+
sensorDimensionMm: number;
|
|
7
|
+
/**
|
|
8
|
+
* Optional focus distance in metres. When supplied, the ideal thin-lens
|
|
9
|
+
* image distance is used as the projection distance. Omit to preserve the
|
|
10
|
+
* infinity-focus/pinhole approximation.
|
|
11
|
+
*/
|
|
12
|
+
focusDistanceM?: number;
|
|
13
|
+
}
|
|
14
|
+
export interface FieldOfView {
|
|
15
|
+
/** Angular field of view in degrees. */
|
|
16
|
+
degrees: number;
|
|
17
|
+
/** Angular field of view in radians. */
|
|
18
|
+
radians: number;
|
|
19
|
+
/** Projection/image-plane distance used by the geometry, in millimetres. */
|
|
20
|
+
projectionDistanceMm: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Calculates rectilinear angular field of view as
|
|
24
|
+
* 2 * atan(sensorDimension / (2 * projectionDistance)).
|
|
25
|
+
*
|
|
26
|
+
* Without focusDistanceM, projectionDistance is nominal focal length for
|
|
27
|
+
* backwards-compatible infinity-focus/pinhole behavior. With focusDistanceM,
|
|
28
|
+
* projectionDistance is the ideal Gaussian thin-lens image distance for that
|
|
29
|
+
* focus plane.
|
|
30
|
+
*
|
|
31
|
+
* Neither mode models real-lens focus breathing or distortion.
|
|
32
|
+
*
|
|
33
|
+
* @param input Focal length, matching sensor dimension, and optional focus distance.
|
|
34
|
+
* @returns Angular field of view.
|
|
35
|
+
*/
|
|
36
|
+
export declare function calculateFieldOfView(input: CalculateFieldOfViewInput): CalculationResult<FieldOfView>;
|
|
37
|
+
//# sourceMappingURL=field-of-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-of-view.d.ts","sourceRoot":"","sources":["../../src/camera/field-of-view.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,+BAA+B,CAAC;AAIvC,MAAM,WAAW,yBAAyB;IACxC,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,qFAAqF;IACrF,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,wCAAwC;IACxC,OAAO,EAAE,MAAM,CAAC;IAChB,4EAA4E;IAC5E,oBAAoB,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,yBAAyB,GAC/B,iBAAiB,CAAC,WAAW,CAAC,CAqChC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { calculatedResult } from "../core/calculation-result.js";
|
|
3
|
+
import { requirePositiveFinite } from "../core/validation.js";
|
|
4
|
+
import { calculateThinLensImageDistance } from "../optics/thin-lens.js";
|
|
5
|
+
/**
|
|
6
|
+
* Calculates rectilinear angular field of view as
|
|
7
|
+
* 2 * atan(sensorDimension / (2 * projectionDistance)).
|
|
8
|
+
*
|
|
9
|
+
* Without focusDistanceM, projectionDistance is nominal focal length for
|
|
10
|
+
* backwards-compatible infinity-focus/pinhole behavior. With focusDistanceM,
|
|
11
|
+
* projectionDistance is the ideal Gaussian thin-lens image distance for that
|
|
12
|
+
* focus plane.
|
|
13
|
+
*
|
|
14
|
+
* Neither mode models real-lens focus breathing or distortion.
|
|
15
|
+
*
|
|
16
|
+
* @param input Focal length, matching sensor dimension, and optional focus distance.
|
|
17
|
+
* @returns Angular field of view.
|
|
18
|
+
*/
|
|
19
|
+
export function calculateFieldOfView(input) {
|
|
20
|
+
requirePositiveFinite("focalLengthMm", input.focalLengthMm);
|
|
21
|
+
requirePositiveFinite("sensorDimensionMm", input.sensorDimensionMm);
|
|
22
|
+
const focusProjection = input.focusDistanceM === undefined
|
|
23
|
+
? undefined
|
|
24
|
+
: calculateThinLensImageDistance({
|
|
25
|
+
focalLengthMm: input.focalLengthMm,
|
|
26
|
+
objectDistanceM: input.focusDistanceM
|
|
27
|
+
});
|
|
28
|
+
const projectionDistanceMm = focusProjection?.value.imageDistanceMm ?? input.focalLengthMm;
|
|
29
|
+
const radians = 2 * Math.atan(input.sensorDimensionMm / (2 * projectionDistanceMm));
|
|
30
|
+
return calculatedResult({
|
|
31
|
+
radians,
|
|
32
|
+
degrees: (radians * 180) / Math.PI,
|
|
33
|
+
projectionDistanceMm
|
|
34
|
+
}, focusProjection === undefined
|
|
35
|
+
? "rectilinear-field-of-view"
|
|
36
|
+
: "focus-aware-rectilinear-field-of-view", "1.0.0", focusProjection === undefined
|
|
37
|
+
? [
|
|
38
|
+
"Ideal rectilinear/pinhole projection",
|
|
39
|
+
"Nominal focal length represents the infinity-focus projection distance"
|
|
40
|
+
]
|
|
41
|
+
: [
|
|
42
|
+
"Ideal rectilinear paraxial thin-lens projection",
|
|
43
|
+
"Sensor plane uses the thin-lens image distance for the supplied focus distance",
|
|
44
|
+
"Real-lens focus breathing and distortion are not modeled"
|
|
45
|
+
]);
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=field-of-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"field-of-view.js","sourceRoot":"","sources":["../../src/camera/field-of-view.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EACL,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAwBxE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAgC;IAEhC,qBAAqB,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC5D,qBAAqB,CAAC,mBAAmB,EAAE,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAEpE,MAAM,eAAe,GACnB,KAAK,CAAC,cAAc,KAAK,SAAS;QAChC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,8BAA8B,CAAC;YAC7B,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,eAAe,EAAE,KAAK,CAAC,cAAc;SACtC,CAAC,CAAC;IACT,MAAM,oBAAoB,GACxB,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,aAAa,CAAC;IAChE,MAAM,OAAO,GACX,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC;IAEtE,OAAO,gBAAgB,CACrB;QACE,OAAO;QACP,OAAO,EAAE,CAAC,OAAO,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,EAAE;QAClC,oBAAoB;KACrB,EACD,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC,2BAA2B;QAC7B,CAAC,CAAC,uCAAuC,EAC3C,OAAO,EACP,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC;YACE,sCAAsC;YACtC,wEAAwE;SACzE;QACH,CAAC,CAAC;YACE,iDAAiD;YACjD,gFAAgF;YAChF,0DAA0D;SAC3D,CACN,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CalculationResult } from "../core/calculation-result.js";
|
|
2
|
+
export interface CalculateProjectedObjectSizeInput {
|
|
3
|
+
/** Lens focal length in millimetres. */
|
|
4
|
+
focalLengthMm: number;
|
|
5
|
+
/** Object width in metres. */
|
|
6
|
+
objectWidthM: number;
|
|
7
|
+
/** Object height in metres. */
|
|
8
|
+
objectHeightM: number;
|
|
9
|
+
/** Object-plane distance from the camera in metres. */
|
|
10
|
+
distanceM: number;
|
|
11
|
+
/** Optional focus distance in metres for focus-aware sensor-plane projection. */
|
|
12
|
+
focusDistanceM?: number;
|
|
13
|
+
/** Optional sensor pixel pitch in micrometres. */
|
|
14
|
+
pixelPitchMicrometers?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ProjectedObjectSize {
|
|
17
|
+
widthMm: number;
|
|
18
|
+
heightMm: number;
|
|
19
|
+
projectionDistanceMm: number;
|
|
20
|
+
widthPixels?: number;
|
|
21
|
+
heightPixels?: number;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Calculates the projected size of a fronto-parallel object plane.
|
|
25
|
+
*
|
|
26
|
+
* Without focusDistanceM, the function preserves ideal pinhole projection
|
|
27
|
+
* using nominal focal length. With focusDistanceM, it projects to the ideal
|
|
28
|
+
* thin-lens sensor plane selected by that focus distance.
|
|
29
|
+
*
|
|
30
|
+
* @param input Lens, object-size, distance, optional focus, and optional pixel-pitch inputs.
|
|
31
|
+
* @returns Projected object dimensions at the sensor plane.
|
|
32
|
+
*/
|
|
33
|
+
export declare function calculateProjectedObjectSize(input: CalculateProjectedObjectSizeInput): CalculationResult<ProjectedObjectSize>;
|
|
34
|
+
//# sourceMappingURL=projected-object-size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projected-object-size.d.ts","sourceRoot":"","sources":["../../src/camera/projected-object-size.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,+BAA+B,CAAC;AAIvC,MAAM,WAAW,iCAAiC;IAChD,wCAAwC;IACxC,aAAa,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,YAAY,EAAE,MAAM,CAAC;IACrB,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,uDAAuD;IACvD,SAAS,EAAE,MAAM,CAAC;IAClB,iFAAiF;IACjF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kDAAkD;IAClD,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;GASG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,iCAAiC,GACvC,iBAAiB,CAAC,mBAAmB,CAAC,CAgExC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { calculatedResult } from "../core/calculation-result.js";
|
|
3
|
+
import { requirePositiveFinite } from "../core/validation.js";
|
|
4
|
+
import { calculateThinLensImageDistance } from "../optics/thin-lens.js";
|
|
5
|
+
/**
|
|
6
|
+
* Calculates the projected size of a fronto-parallel object plane.
|
|
7
|
+
*
|
|
8
|
+
* Without focusDistanceM, the function preserves ideal pinhole projection
|
|
9
|
+
* using nominal focal length. With focusDistanceM, it projects to the ideal
|
|
10
|
+
* thin-lens sensor plane selected by that focus distance.
|
|
11
|
+
*
|
|
12
|
+
* @param input Lens, object-size, distance, optional focus, and optional pixel-pitch inputs.
|
|
13
|
+
* @returns Projected object dimensions at the sensor plane.
|
|
14
|
+
*/
|
|
15
|
+
export function calculateProjectedObjectSize(input) {
|
|
16
|
+
requirePositiveFinite("focalLengthMm", input.focalLengthMm);
|
|
17
|
+
requirePositiveFinite("objectWidthM", input.objectWidthM);
|
|
18
|
+
requirePositiveFinite("objectHeightM", input.objectHeightM);
|
|
19
|
+
requirePositiveFinite("distanceM", input.distanceM);
|
|
20
|
+
const focusProjection = input.focusDistanceM === undefined
|
|
21
|
+
? undefined
|
|
22
|
+
: calculateThinLensImageDistance({
|
|
23
|
+
focalLengthMm: input.focalLengthMm,
|
|
24
|
+
objectDistanceM: input.focusDistanceM
|
|
25
|
+
});
|
|
26
|
+
const projectionDistanceMm = focusProjection?.value.imageDistanceMm ?? input.focalLengthMm;
|
|
27
|
+
const widthMm = projectionDistanceMm * (input.objectWidthM / input.distanceM);
|
|
28
|
+
const heightMm = projectionDistanceMm * (input.objectHeightM / input.distanceM);
|
|
29
|
+
const model = focusProjection === undefined
|
|
30
|
+
? "fronto-parallel-pinhole-object-size"
|
|
31
|
+
: "focus-aware-thin-lens-object-size";
|
|
32
|
+
const assumptions = focusProjection === undefined
|
|
33
|
+
? [
|
|
34
|
+
"Ideal pinhole projection",
|
|
35
|
+
"Object plane is fronto-parallel to the sensor",
|
|
36
|
+
"Physical object dimensions are supplied by the caller"
|
|
37
|
+
]
|
|
38
|
+
: [
|
|
39
|
+
"Ideal paraxial thin-lens projection to the selected sensor plane",
|
|
40
|
+
"Object plane is fronto-parallel to the sensor",
|
|
41
|
+
"Physical object dimensions are supplied by the caller",
|
|
42
|
+
"Real-lens focus breathing and pupil magnification are not modeled"
|
|
43
|
+
];
|
|
44
|
+
if (input.pixelPitchMicrometers === undefined) {
|
|
45
|
+
return calculatedResult({ widthMm, heightMm, projectionDistanceMm }, model, "1.0.0", assumptions);
|
|
46
|
+
}
|
|
47
|
+
requirePositiveFinite("pixelPitchMicrometers", input.pixelPitchMicrometers);
|
|
48
|
+
const pitchMm = input.pixelPitchMicrometers / 1000;
|
|
49
|
+
return calculatedResult({
|
|
50
|
+
widthMm,
|
|
51
|
+
heightMm,
|
|
52
|
+
projectionDistanceMm,
|
|
53
|
+
widthPixels: widthMm / pitchMm,
|
|
54
|
+
heightPixels: heightMm / pitchMm
|
|
55
|
+
}, model, "1.0.0", assumptions);
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=projected-object-size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projected-object-size.js","sourceRoot":"","sources":["../../src/camera/projected-object-size.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EACL,gBAAgB,EAEjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAyBxE;;;;;;;;;GASG;AACH,MAAM,UAAU,4BAA4B,CAC1C,KAAwC;IAExC,qBAAqB,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC5D,qBAAqB,CAAC,cAAc,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;IAC1D,qBAAqB,CAAC,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAC5D,qBAAqB,CAAC,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;IAEpD,MAAM,eAAe,GACnB,KAAK,CAAC,cAAc,KAAK,SAAS;QAChC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,8BAA8B,CAAC;YAC7B,aAAa,EAAE,KAAK,CAAC,aAAa;YAClC,eAAe,EAAE,KAAK,CAAC,cAAc;SACtC,CAAC,CAAC;IACT,MAAM,oBAAoB,GACxB,eAAe,EAAE,KAAK,CAAC,eAAe,IAAI,KAAK,CAAC,aAAa,CAAC;IAChE,MAAM,OAAO,GACX,oBAAoB,GAAG,CAAC,KAAK,CAAC,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,QAAQ,GACZ,oBAAoB,GAAG,CAAC,KAAK,CAAC,aAAa,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;IACjE,MAAM,KAAK,GACT,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC,qCAAqC;QACvC,CAAC,CAAC,mCAAmC,CAAC;IAC1C,MAAM,WAAW,GACf,eAAe,KAAK,SAAS;QAC3B,CAAC,CAAC;YACE,0BAA0B;YAC1B,+CAA+C;YAC/C,uDAAuD;SACxD;QACH,CAAC,CAAC;YACE,kEAAkE;YAClE,+CAA+C;YAC/C,uDAAuD;YACvD,mEAAmE;SACpE,CAAC;IAER,IAAI,KAAK,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;QAC9C,OAAO,gBAAgB,CACrB,EAAE,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,EAC3C,KAAK,EACL,OAAO,EACP,WAAW,CACZ,CAAC;IACJ,CAAC;IAED,qBAAqB,CACnB,uBAAuB,EACvB,KAAK,CAAC,qBAAqB,CAC5B,CAAC;IACF,MAAM,OAAO,GAAG,KAAK,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAEnD,OAAO,gBAAgB,CACrB;QACE,OAAO;QACP,QAAQ;QACR,oBAAoB;QACpB,WAAW,EAAE,OAAO,GAAG,OAAO;QAC9B,YAAY,EAAE,QAAQ,GAAG,OAAO;KACjC,EACD,KAAK,EACL,OAAO,EACP,WAAW,CACZ,CAAC;AACJ,CAAC"}
|