contae.lua v0.11 Raw meter based auto exposure for continuous shooting
- 1 Overview
- 2 Links
- 3 Script usage
- 4 Example
- 5 Script options
- 5.1 Meter width %
- 5.2 Meter height %
- 5.3 Meter step
- 5.4 Max Ev change
- 5.5 Use initial Ev as target
- 5.6 Ev Shift
- 5.7 Max Tv Sec/1000
- 5.8 Min Tv Sec/100K
- 5.9 Target ISO
- 5.10 ISO adj TV Sec/1000
- 5.11 Max ISO
- 5.12 ND Tv Sec/10000
- 5.13 Meter high thresh Ev
- 5.14 Meter high limit Ev
- 5.15 Meter high max weight
- 5.16 Meter low thresh Ev
- 5.17 Meter low limit Ev
- 5.18 Meter high max weight
- 5.19 Overexp thresh x/100k
- 5.20 Overexp Ev range
- 5.21 Overexp max weight
- 5.22 Overexp prio
- 5.23 Underexp thresh x/100k
- 5.24 Underexp -Ev
- 5.25 Underexp max weight
- 5.26 Underexp prio
- 5.27 Histogram step
- 5.28 Draw Debug info
- 5.29 Meter Area
- 5.30 Gauge Y offset %
- 5.31 Log mode
- 5.32 Raw hook sleep
- 6 Log file description
Overview[edit | edit source]
This script requires CHDK 1.4.1 or later
The basic idea is the script adjusts exposure after each shot in a continuous sequence to avoid over or under exposure in the next shot.
Change History[edit | edit source]
Version 0.12[edit | edit source]
- If "ISO Adj Tv" is set longer than "Max Tv", it is now set to "Max Tv", meaning the ISO adjustment will start when shutter adjestment ends. This fixes a bug where the "Max Tv" limit would be ignored. To disable ISO adjustment, set "Target ISO" and "Max ISO" to the same value. Thanks SkepticaLee for the report.
- Fixed bug that where some display would freeze until the end of the raw timeout at the end of a continuous burst.
Version 0.11[edit | edit source]
Fixed a bug that caused exposure to stop increasing when Max ISO was hit, regardless of Max Tv. Thanks udo for the report.
Links[edit | edit source]
Discussion / Bug reporting thread: http://chdk.setepontos.com/index.php?topic=12696.0
Download v0.12: https://app.box.com/s/d1xeg34h2lyla3jz30sb9khgqfg57ul8
Script usage[edit | edit source]
When the script is running, keys like set, up, down, left, right, half shoot are passed to the Canon firmware. Menu exits the script.
When full shoot is pressed, a shooting burst starts. The first shot in the burst uses the exposure set by the Canon firmware, possibly modified by Ev shift options described below. Exposure of subsequent shots in the burst are based on analyzing the raw buffer. The burst continues as long as the shutter is held down. If the camera is not in Canon continuous mode, the shooting is done by simulating holding half press and clicking full press for each shot. The shooting rate in this mode may be similar to, or slower than Canon continuous mode depending on the camera.
If you hold the shutter down while starting the script, it will half shoot and start a burst as soon as it is ready.
The metering is done using an adjustable sized rectangle in the middle of the sensor, and the script normally tries to keep this at the "neutral" value. Additionally, a histogram of the entire sensor is used to limit amount of over and under exposed pixels in the entire scene to user specified ranges.
This is under development and not completed. In particular:
- Doesn't handle aperture adjustments yet. This means the initial aperture value set by the Canon firmware or CHDK overrides will be used for every shot.
- ND filter control is only available on cameras without an adjustable aperture, and the ND value may be inaccurate if the canon firmware did not set the ND filter in for the first exposure.
- There are too many options, and their meanings are not clear.
- Not all Canon controls are passed though.
Earlier development discussion can be found in the script hook development thread: http://chdk.setepontos.com/index.php?topic=11081.msg119265#msg119265
Example[edit | edit source]
The sequence of images in this box.com folder shows the script in operation, with the debug overlay enabled.
Script options[edit | edit source]
Meter width %[edit | edit source]
Width of meter area, in percent of active area.
Meter height %[edit | edit source]
Height of meter area, in percent of active area.
Meter step[edit | edit source]
Ever step-th pixel is measured. To sample all colors, it should be odd. To prevent overflow, the total number of pixels (size/step)^2 must be less than unsigned_max / white_level. (~1M for 12 bpp, 250K for 14 bpp). Larger numbers of pixels will be slower.
Max Ev change[edit | edit source]
Maximum exposure change in a single step, in fractions of a stop.
Use initial Ev as target[edit | edit source]
Use the exposure of the initial shot as the target Ev instead of the pre-defined neutral value.
Ev Shift[edit | edit source]
Shift the target exposure by specified number of stops. If "Use initial Ev as target" is enabled, the shift is applied to the initial value. Otherwise, it is relative to the neutral value.
Max Tv Sec/1000[edit | edit source]
Longest shutter speed to use, in 1/1000ths of a sec. If required exposure is longer, ISO will be used up to ISO limits.
Min Tv Sec/100K[edit | edit source]
Shortest shutter speed to use, in 1/100000ths of a sec. If required exposure is shorter, it will be limited to this value.
Target ISO[edit | edit source]
ISO value to use if shutter limits (described below) not reached. Should normally be lowest ISO. In Canon UI units.
ISO adj TV Sec/1000[edit | edit source]
Shutter speed (in 1/1000ths of a sec) at which ISO will start to be increased. If the exposure time exceeds this value, exposure will changes are split 50/50 between shutter and ISO, subject to limits below. Set Max ISO equal to this value to disable ISO adjustment.
Max ISO[edit | edit source]
Absolute max ISO to be used. In Canon UI units.
ND Tv Sec/10000[edit | edit source]
Shutter speed (in 1/10000ths of a sec) below which ND filter is put in. Ignored on cameras with an adjustable aperture, even if they also have an ND filter. 0 disables.
Meter high thresh Ev[edit | edit source]
Meter value in to start limiting under exposure protection, in stops above neutral. As the meter value exceeds this value, the influence of under exposure protection is reduced.
Meter high limit Ev[edit | edit source]
Maximum meter value allowed from under exposure protection, in stops above neutral.
Meter high max weight[edit | edit source]
Controls the maximum influence of the meter high limit relative to histogram under exposure. The influence of the meter increases proportional to the square of the fraction by which it exceeds the threshold, such that the max weight value is be reached at the limit Ev. If set to 100 (the standard weight before threshold), this behavior is disabled.
Meter low thresh Ev[edit | edit source]
Meter value to start limiting over-exposure protection, in stops below neutral. As the meter value falls the number of stops specified below neutral, the amount that over exposure protection can reduce exposure is reduced.
Meter low limit Ev[edit | edit source]
Minimum meter value allowed from over exposure protection, in stops below neutral.
Meter high max weight[edit | edit source]
Controls the maximum influence of the meter high limit relative to histogram over exposure, similar to max weight.
Overexp thresh x/100k[edit | edit source]
The fraction in parts per 100,000 of pixels that must be near to white level to trigger over exposure protection. 0 Disables over exposure protection. Note: for low values to work, the histogram step (described below) must be set to allow a sufficient number of pixels to be sampled. If the threshold represents less than 10 pixels, are warning is recorded in the log.
Overexp Ev range[edit | edit source]
What fraction of a stop below white level is considered over exposed.
Overexp max weight[edit | edit source]
Maximum weight for over exposure protection. This controls how far beyond the overexposure threshold the weight continues to increase.
Overexp prio[edit | edit source]
Priority modifier for over exposure protection. If greater than 0, the weight of under exposure and meter driven exposure increases is reduced proportional to the amount of over exposure, such that the "prio" value is subtracted from the weight when overexp thresh is reached.
Underexp thresh x/100k[edit | edit source]
Similar to overexp thresh above, but for pixels near black level. 0 Disabled under exposure protection.
Underexp -Ev[edit | edit source]
Number of stops below neutral a value must be to count as underexposed. Pixels with 0-4 shot histogram value are not counted as underexposure, since this usually indicates defective pixels.
Underexp max weight[edit | edit source]
Maximum weight for under exposure protection, similar to Overexp max weight above.
Underexp prio[edit | edit source]
Priority modifier for under exposure protection, similar to Overexp prio above.
Histogram step[edit | edit source]
The step between pixels sampled for under / over protection. Smaller values sample more pixels, allowing smaller areas to be detected and lower under/over thresholds to be used, at the expense of increased processing time. On D10 (12 megapixel) a step of 11 samples ~100k pixels, and takes 60-70ms to process, equating to ~1500 pixels/msec.
Draw Debug info[edit | edit source]
Draw metering information on the raw buffer. From top to bottom
- A bar near the top of the screen, representing the metered value as a % of white level (log scale), with tick marks at 1 EV intervals. The larger ticks are black level, neutral, white level, and Ev shift if enabled. Yellow and red ticks above the bar show the meter thresh and limit values, respectively.
- A bar showing the change in exposure as a fraction of the max EV change value described below. The origin is at the center, with longer exposure to the right, and shorter exposure to the left.
- A bar extending from left to right, representing % underexposed pixels. Red if above threshold, max at middle of screen.
- A bar extending from right to left, representing % overexposed pixels. Red if above threshold, max at middle of screen.
- A box or reticle around the meter area, controlled by Meter Area option below
Drawing takes adds a small amount to shooting time (e.g. 20 ms on d10.) The log contains this information and much more, but having it in the images makes it easier to see what the code is doing.
Meter Area[edit | edit source]
Controls whether the metering area is drawn, either just the corners or a box
Gauge Y offset %[edit | edit source]
Controls the vertical location of the debug info, in % of full resolution jpeg area height. 0 uses a default offset of 80 pixels. Use to make the debug info visible on jpegs with a different aspect ration form the sensor.
Log mode[edit | edit source]
If enabled, the log is written to A/contae.csv
- None = do not record a log
- Append = append to existing log
- Replace = replace any existing log
Raw hook sleep[edit | edit source]
Insert a script sleep just before the raw hook is released. This appears to avoid issues with D10 taking some shots with the shutter closed when debug drawing is not enabled.
Log file description[edit | edit source]
The log is a CSV with a bunch of columns. Some of the more relevant/useful ones are described below.
sv, tv, av[edit | edit source]
exposure values for the shot with the image number indicated in the exp column.
bv96[edit | edit source]
Scene brightness. For pre-shoot, this comes from the Canon firmware. Otherwise, calculated from exposure params and meter value.
meter, meter96[edit | edit source]
the average value of the metered area. *96 gives this as an APEX96 value where the target exposure is 0. Negative values indicate an underexposure, positive is overexposure.
over_frac, under_frac[edit | edit source]
Fraction of pixel in the over and under ranges, in percent.
meter_weight, over_weight, underweight[edit | edit source]
Weights controlling the relative contribution of the meter area, under and over exposure protection to the final exposure change.
d_ev[edit | edit source]
exposure change requested for the next shot. Positive values mean more exposure (longer Tv, higher ISO)
desc[edit | edit source]
various cases in the metering process trigger messages here, e.g if shutter limits hit etc.