Beep6581 / RawTherapee

A powerful cross-platform raw photo processing program
https://rawtherapee.com
GNU General Public License v3.0
2.74k stars 311 forks source link

Introduce wide aperture raw scaling into camconst.json #1991

Closed Beep6581 closed 9 years ago

Beep6581 commented 9 years ago

Originally reported on Google Code with ID 2007

Some Canon cameras (maybe other brands too(?)) scale the raw values when a lens is shot
with wider aperture than f/2.8, to compensate for the light loss.

This changes white levels (maybe black level too?)

Being able to specify this behavior in the new camconst.json file would be great.

I could implement it, it's probably simple, but I need to know more details of how
this works. Example data for a 5D mark III or similar would be great to have, so we
can insert one camera with this feature in camconst.json.

Things we need to know

1. At which aperture does it start to scale?
2. Does it affect white level only, or black level too?
3. Does it scale for all wide aperture lenses the same way, or is it bound to specific
lens models? Ie will a Sigma 35mm 1.4 lens get the same scaling as a Cannon 50mm 1.4?
4. How is it affected by ISO?
5. Are there more brands than Canon doing this?

If we need a table per lens per ISO it could be a really loooong table, but maybe it's
simpler than that.

Reported by torger@ludd.ltu.se on 2013-10-16 14:20:24

Beep6581 commented 9 years ago
These links are relevant for the subject:

http://www.dxomark.com/en/Reviews/F-stop-blues

http://www.pages.drexel.edu/~par24/rawhistogram/CanonRawScaling/MartinEmail.htm

Seems like many/all brands is doing it, and it maybe is not bound to lens model but
only aperture in general (good). But as reported in issue 1736 maybe the lenses with
little electrical communication (ie zeiss) get no scaling. Messy indeed.

But maybe the lack of scaling is due to no aperture being reported to the camera? If
we don't know the aperture, no scaling will take place of course.

The simplest would be just a scale factor, like this:

 "aperture_scaling": [
    { "aperture": 1.2, "scale_factor": 1.15 },
    ...
 ]

and the scale factor would be applied on the white level, ie if it's 15760 for the
given ISO it would be scaled to 15760 x 1.15 = 18124 in this example.

The case with the unscaled lenses need to be verified though.

Reported by torger@ludd.ltu.se on 2013-10-17 08:05:19

Beep6581 commented 9 years ago
Done some testing on my 5D mark II, starting to get an idea how to do this. It's quite
little to gain though, on the 5D it's only 0.1 stop scaling from f/4.0 down to f/1.4.
But there are worse, according to DxOmark the Canon 7D has almost 0.6 stop gain at
f/1.2.

I'm also writing docs of how to measure white levels. It's important to be conservative
so the raw engine detects clipping. It may be tempting to set the clip level to the
highest value one have seen, but lowering 10 units you lose like 0.001 stop and make
sure clipping is proper.

Reported by torger@ludd.ltu.se on 2013-10-17 17:29:25

Beep6581 commented 9 years ago
Here's is a draft of the documentation of how to measure white levels I thought I'll
provide in camconst.json file, but perhaps it should be in the manual itself.

How to measure white levels:
----------------------------

Dcraw which provides the default values to RawTherapee often provides too high
white levels, and only provides a single value regardless of color channel, ISO
or aperture. If you open an image with a large clipped area and that is
rendered in a pink/magenta color rather than white it usually means that the
white level constant is too high. You can fix this by adjusting the
"Raw White Point" in the raw tab inside RawTherapee, or permanently fix it by
measuring and providing a more exact white level in camconst.json so
RawTherapee gets to know from start where the camera actually clips.

Here's a guide how to do it.

Shoot with your camera into a bright light source, such as a lamp, and make
sure the shutter speed is long enough to get overexposure (we want
clipping!). For a camera that has a fuzzy clipping level (eg some CCD based
cameras, not too common today) it's best to not overexpose the whole image
but have a transition into the overexposure so you can get a sense of where
to put the white level, ie at which level the camera stops providing sane
information, which can be as much as 1000 units or more from the "hard"
clip level.

Use f/5.6 or smaller aperture (=larger f-number) to avoid any raw scaling
the camera might have for large apertures. Open the file in a raw analyzer
such as Rawdigger and check the pixel values for the clipped areas (if you
are using Rawdigger, make sure you have disabled "subtract black" in
preferences or else sample values can be wrong). Clip levels can be
different on color channel (R, G1, B, G2, note the two greens, most often
both green channels have the same white level though) and vary depending
on ISO setting, so make one shoot for each ISO (even 1/3 steps, so yes it
can be quite a lot of pictures to shoot and check).

In addition, many cameras scale the raw values for large apertures. It's
generally not that important to cover this, but if you want to extract most
out of the camera you should cover this too. Then you need to shoot with a
wide aperture lens (ideally the widest available from the manufacturer) and
test each aperture (1/3 steps) from the widest (say f/1.2) until the camera
stops scaling the raw values (usually f/2.8 or f/4.0). If the camera also
have ISO scaling you need to shoot at these different ISOs to detect any
differences in scaling, there can be a bit of variation. If you don't have
access to the widest lens available for the system (say only an f/1.8 lens
instead of an f/1.2) it can still be valuable to have the values down to
what you can provide.

PROVIDE CONSERVATIVE VALUES. Most cameras have a little noise at the clipping
level, and CCD cameras can have a lot. In your raw analyzer, move around and
look at the values in the clipped areas to get a sense of the variation. CMOS
sensors typically have very little variation, say only +/-2 units, while some
CCDs could have +/-500 or more. There can also be camera-to-camera variation,
again CCDs are more likely to have larger variation than CMOS cameras.

If the white level is set too high RawTherapee will not think the pixels are
clipped and you can get discoloured highlights (usually pink), this is what
we want to avoid. If white level is set too low RawTherapee will clip early, ie
you lose a little highlight detail, but the color is rendered correctly and
highlight reconstruction can work properly, so this is not as bad. This is why
we want conservative values.

By conservative values we mean that if you see a clipping level of most often
15760 and occassionally 15759 (ie very small variation of clipping level which
today is the most common case), you set the white level 10 - 20 units below,
say at 15750 in this example, this way we get a little margin from noise and
camera variation. Since sensor raw values are linear you lose in this example
log2(1-10/15760) = -0.001 stop of detail, ie irrelevant. Thus it's better to
provide RawTherapee with knowledge where the image clips rather than keeping
that last 0.001 stop of highlight information and risking that clipping will
not be detected properly.

The aperture scaling feature is meant to raise the white level to not miss
out on highlight detail when the camera has scaled the raw values (and thus
raised white levels). Many cameras do this, but not all, and can only do it
for lenses that report aperture to the camera (ie you see it in the EXIF
data). Providing proper aperture scaling values is a bit more advanced task,
so if you are unsure we recommend to skip that part.

Beware that the raw format may have a ceiling so that it clips scaled values,
for example the Canon 5D mark II maxes out at 16383 which happens at f/1.8
for ISOs with the white level at 15750, but for ISO160 when the white level
is 12800 it does not max out. If there is such a raw limit it must also be
provided ("ranges":"white_max").

Note that aperture scaling can be quite small, for the 5D mark II it's only
0.1 stop down to f/1.4 and then it can be discussed if it's worthwhile to care.
The "worst" cameras scale about 0.6 stops though, and then it's more
valuable to compensate. If you skip aperture scaling you will clip too early
and miss that highlight detail, but you get no processing problems. Setting
unconservative scale factors can on the other hand cause a too high
whitelevel and break highlight processing, so be careful. Scaling can vary
sligthly depending on ISO (if white levels vary) so make sure to provide
conservative scalings so regardless of ISO you don't get a too high white
level. We recommend to keep a wider margin here than on the white levels,
ie 0.5-1% lower or so. For example if base (conservative!) white level is
15750 and the scaled is 16221 we have a scaling factor of 16221/15750=1.0299
ie +2.9% we set the factor to 1.02 or +2% to keep a margin.

Some cameras have different white levels on different color channels. For
example the Nikon D7000 has 16383 (16360 to be conservative!) for red and blue
and 15778 (15760 conservative) for the green channels. We support providing
separate clipping levels per channel, but it is not always a good idea to do so.
If the color matrix and scaling is designed with a single white level in mind
there can be color shift if we change to separate white levels. All dcraw's
matrices are designed for a single white level, so if we use a matrix from
there it should be a single white level. In this Nikon D7000 example we could
be conservative and set a single white level to 15760 which then is applied
to all channels, then we will clip away log2(1-623/16383)=0.056 stops of
highlight detail from the red and blue channels, and this is what we recommend
to do. On the other hand such a very minor change in white level as in this
example will not cause any visible color shift so it's a matter of taste how to
relate to this. If you have the means to also provide a color matrix adapted for
separate white levels please do!

Reported by torger@ludd.ltu.se on 2013-10-18 11:02:57

Beep6581 commented 9 years ago

Reported by torger@ludd.ltu.se on 2013-10-18 13:23:53

Beep6581 commented 9 years ago
Note: will probably add scaling code to accept channel-specific white levels without
needing a new matrix, so the doc will change to mirror that.

Reported by torger@ludd.ltu.se on 2013-10-18 13:59:12

Beep6581 commented 9 years ago
Dense documentation Torger, i don't think that i've understood everything, but other
may elaborate around it. But very useful, indeed!

Adding it to the offical documentation, in an Appendix section, would be great, once
finished :)

Reported by natureh.510 on 2013-10-20 00:24:18

Beep6581 commented 9 years ago
Here's a patch, with updated docs and updated camconst entry for the Canon 5Dmk2 now
including aperture scaling.

I also added a Nikon D7000 entry which has different white levels to show that concept.

Scalings are rather tiny for these cameras so you gain like 0.1 stop in extra highlight
detail, but for other camera models there can be a more significant gain.

A "hidden" fix in this patch is that I adjust pre_mul scalings when there's different
white levels to avoid color shifts, ie keep the exact same color as with a single white
level. (Dcraw's pre_mul expects only one, I blamed the color matrix before but it's
more correct to blame the channel multiplications).

Reported by torger@ludd.ltu.se on 2013-10-20 10:22:53


Beep6581 commented 9 years ago

Reported by torger@ludd.ltu.se on 2013-10-20 10:23:17

Beep6581 commented 9 years ago
torger, nice so far :)

About conservative values, I think you (we) have to expand a bit our conservatism from
around 10 levels mentioned in your doc to around (or more) 100/14bit or 25/12bit. There
are some cases where there is a distribution at saturation levels instead of a single
value and I think the safe way is to push all this distribution to clipped http://translate.google.com/translate?u=http%3A%2F%2Fwww.guillermoluijk.com%2Ftutorial%2Fsatlevel%2Findex.htm&langpair=es|en&hl=EN&ie=UTF-8.

This happens on Canon models also when black frame subtraction for long exposures is
enabled. I found a +/- 50 levels (gaussian ??) dist at ISO3200 and it can be more for
higher ISOs http://www.imaging-resource.com/PRODS/canon-5d-mkiii/E5D3LL0032007.CR2.HTM
By the way .. Adobe pushes around 300 levels to clipping (use a 15000 clip point when
the histogram shows it is really 15300) when converting CR2s to DNGs ..

Regarding scale factor .. do you calculate it on the full range or after Black Level
subtraction ?. I think the correct is after. The same about the influence of expanding
the White Level for wide appertures, it should be calculated after BL subtraction.

I have a set of CR2s for 5DIII (not mine, I downloaded them when 5DIII was launched)
and I will upload the measures tomorrow. 
Some settings are missing but I think it's safe to calculate (or guess) them. For example
the f/1.4 sample is very dark and there is no clipping at the histogram but it shows
1 gap after every 9 levels so the scale factor should be 10/9=1.11 ..

If you prefer the raw samples instead of the measures just ask .. and wait :).

Reported by iliasgiarimis on 2013-10-20 23:15:02

Beep6581 commented 9 years ago
Thanks for the feedback, I'll look into it. I'm aware of that DNG converter cuts away
quite a lot of the top, I thought we would not need to be *that* conservative (haven't
seen that variation you're mentioning myself), but I'll look into the links.

Scale factor is calculated on the full range. I don't think it should be calculated
after black level subtraction, seems to me that the black level on the Canon's is scaled
as well. And I think it's correct. The thing is if you would scale after black level
subtraction you would alter the contrast, so whitelevel divided by two would no longer
be half the light, ie you would distort the "stop scale" and not have true stops in
the data. If you scale before blacklevel subtraction (and thus scale black point as
well) you keep original contrast.

I have to look into scaling blacklevel though now when I think about it, don't need
to do it for most cameras as it's fetched from masked pixels (Canons etc), but if you
have a blacklevel constant that should be scaled too.

Reported by torger@ludd.ltu.se on 2013-10-21 05:58:18

Beep6581 commented 9 years ago
Concerning clip levels; I agree that it's better to push all to clipped, that's the
goal and that's why I emphasize conservative levels.

However I think that if you see a very stable clip level (ie variation 1-2 samples)
it's reasonably safe to assume that on that ISO for that camera model the variation
is rather small. If you see an unstable clip level one should be more conservative,
maybe I'll document a bit more detail how much. On the Canon 5Dmk3 ISO32000 example
picture I'd set the white level to 13300.

I did not know that CMOS sensors also could have this unstable clip levels (only seen
it on my CCD digital back previously) and that it could vary on ISO so I'll certainly
update the docs to mirror that.

If you think that we should be strongly conservative like DNG converter I'm okay with
that but I think that we in RawTherapee could be a little bit "more on the edge" --
it's easy to adjust if we happen to set levels too high, and I think it fits RT's style
to try to extract max, while the commercial converters are more conservative (not only
in white levels, but in all conversion highlight reconstruction etc) as it's more important
for them to be user-friendly and be safe to never show any artifact than to give you
the max from the file.

Reported by torger@ludd.ltu.se on 2013-10-21 06:23:26

Beep6581 commented 9 years ago
(checked the code, I already did scale black level too, if provided as a constant)

Reported by torger@ludd.ltu.se on 2013-10-21 06:39:09

Beep6581 commented 9 years ago
Updated the docs. Let me know if we need to be even more conservative. I did not change
the black level subtraction, ie we do scaling before it as I think this is the correct
way, but if I'm wrong I'll change it of course :-)

--------------------------------------

How to measure white levels:
----------------------------

Dcraw which provides the default values to RawTherapee often provides too high
white levels, and only provides a single value regardless of color channel, ISO
or aperture. If you open an image with a large clipped area and that is
rendered in a pink/magenta color rather than white it usually means that the
white level constant is too high. You can fix this by adjusting the
"Raw White Point" in the raw tab inside RawTherapee, or permanently fix it by
measuring and providing a more exact white level in camconst.json so
RawTherapee gets to know from start where the camera actually clips.

Here's a guide how to do it.

Shoot with your camera into a bright light source, such as a lamp, and make
sure the shutter speed is long enough to get overexposure (we want
clipping!). Some cameras have fuzzy white levels and may look less fuzzy with
strong over-exposure (most samples are then pushed to some hard raw limit), if
you measure such a camera you'd want to over-expose softly (ie one-two stops or
so) so you can more correctly see where the camera stops providing sane
information.

Use f/5.6 or smaller aperture (=larger f-number) to avoid any raw scaling
the camera might have for large apertures. Open the file in a raw analyzer
such as Rawdigger and check the pixel values for the clipped areas (if you
are using Rawdigger, make sure you have disabled "subtract black" in
preferences or else sample values can be wrong). In this stage we always look
at white level before black level subtraction! White levels can be different on
color channel (R, G1, B, G2, note the two greens, most often both green
channels have the same white level though) and vary depending on ISO setting,
so make one shoot for each ISO (even 1/3 steps, so yes it can be quite a lot of
pictures to shoot and check).

In addition, many cameras scale the raw values for large apertures. It's
generally not that important to cover this, but if you want to extract most
out of the camera you should cover this too. Then you need to shoot with a
wide aperture lens (ideally the widest available from the manufacturer) and
test each aperture (1/3 steps) from the widest (say f/1.2) until the camera
stops scaling the raw values (usually f/2.8 or f/4.0). If the camera also
have ISO scaling you need to shoot at these different ISOs to detect any
differences in scaling, there can be a bit of variation. If you don't have
access to the widest lens available for the system (say only an f/1.8 lens
instead of an f/1.2) it can still be valuable to have the values down to
what you can provide.

PROVIDE CONSERVATIVE VALUES. Most cameras have a little noise at the white
level, and some can have a lot. In your raw analyzer, move around and look at
the values in the clipped areas to get a sense of the variation, and/or look
at the histogram. White it's common to have very little variation, say only
+/-2 units, some can have +/-500 or more. There can also be camera-to-camera
variation.

If the white level is set too high RawTherapee will not think the pixels are
clipped and you can get discoloured highlights (usually pink), this is what
we want to avoid. If white level is set too low RawTherapee will clip early, ie
you lose a little highlight detail, but the color is rendered correctly and
highlight reconstruction can work properly, so this is not as bad. This is why
we want conservative values.

By conservative values we mean that if you see a clipping level of most often
15760 and occassionally 15759 (ie very small variation of clipping level which
is a common case), you set the white level 10 - 20 units below, say at 15750 in
this example, this way we get a little margin from noise and camera variation.
Since sensor raw values are linear you lose in this example log2(1-10/15760) =
-0.001 stop of detail, ie irrelevant. Thus it's better to provide RawTherapee
with knowledge where the image clips rather than keeping that last 0.001 stop
of highlight information and risking that clipping will not be detected
properly.

If you have a fuzzy white level look at the linear histogram; you will probably
see a normal/gaussian distribution (bell shape) noise peak at clipping and
probably also a peak at a hard raw data clip level usually at a power of
two - 1, such as 4095 or 16383. Then you pick a value just before the bell
shape rises, ie to the left of the bell meaning that you cut away the whole
fuzzy noise peak. If a little of the starting edge of the noise will be
included it's not harmful, but 99% of it should be above.

If you have used Adobe's DNG Converter and analyzed it's output you may have
noticed that it's very conservative regarding white levels, ie it cuts away
quite a lot from the top. While we also recommend to be conservative, you can
generally be a little bit less conservative than Adobe's DNG Converter.
RawTherapee is meant to max out what you can get from your camera, and the
white levels should (within reason) mirror that.

The aperture scaling feature is meant to raise the white level to not miss out
on highlight detail when the camera has scaled the raw values (and thus
raised white levels). Many cameras do this, but not all, and can only do it
for lenses that report aperture to the camera (ie you see it in the EXIF
data). Providing proper aperture scaling values is a bit more advanced task,
so if you are unsure we recommend to skip that part.

Beware that the raw format may have a ceiling so that it clips scaled values,
for example the Canon 5D mark II maxes out at 16383 which happens at f/1.8
for ISOs with the white level at 15750, but for ISO160 when the white level
is 12800 it does not max out. If there is such a raw limit it must also be
provided ("ranges":"white_max"). Usually you will not need a margin on
white_max as it clipping is a result of an in-camera math operation.

Note that aperture scaling can be quite small, for the 5D mark II it's only
0.1 stop down to f/1.4 and then it can be discussed if it's worthwhile to care.
The "worst" cameras scale about 0.6 stops though, and then it's more
valuable to compensate. If you skip aperture scaling you will clip too early
and miss that highlight detail, but you get no processing problems. Setting
unconservative scale factors can on the other hand cause a too high
whitelevel and break highlight processing, so be careful. Scaling can vary
sligthly depending on ISO (if white levels vary) so make sure to provide
conservative scalings so regardless of ISO you don't get a too high white
level. We recommend to keep a wider margin here than on the white levels,
ie 0.5-1% lower or so. For example if base (conservative!) white level is
15750 and the scaled is 16221 we have a scaling factor of 16221/15750=1.0299
ie +2.9% we set the factor to 1.02 or +2% to keep a margin.

Scaling takes place on the raw values before black level subtraction, and if
a black level constant is provided also that will be scaled.

If RawTherapee doesn't find an entry for the aperture used in the image, it
will pick the closest above. Ie if the apertures 1.0 and 2.0 is in the table
and the image has aperture 1.2, it will pick scaling for 2.0, even if 1.0 is
the closer aperture. The reason for always checking the closest above is that
we rather get a bit low white level than too high, as discussed before.

Some cameras have different white levels on different color channels. Note
that some cameras with different white levels per color have so small
differences that you may just provide a single value instead, then pick
the lowest white level and make a conservative margin as always.

Reported by torger@ludd.ltu.se on 2013-10-21 08:01:03

Beep6581 commented 9 years ago
As you can read I propose to use 1/3 Adobes conservatism and this for Canon raws so
that we can cover with a single per ISO value the gaussian saturation levels when in
camera black frame subtraction is used. This way we can ask the users to provide just
the normal clipping points without experimenting with every possible setting.
The largest deviation that I found is +/- 50/14bit levels at ISO 3200, I just supposed
that it can reach 100+ levels at higher ISOs since the distribution already scales
with ISO (at ISO 100 it is +/- 20 levels. I hope you can investigate for this with
your 5DII, I do not have any Cannon available to help on this.

About scaling.
- For Canon dslrs the correct way is to leave RT calculate the Black Level from the
side optically black region. So if the calculation results is 1024 and the "large apperture"
scale factor is 1.10 what will happen with scaling ?. Did you checked if the rendering
at the darks is correct ? 
- With Rawdigger I see that black level remains the same on files with large apperture.
- When I was trying to reach the correct White level using "raw linear correction"
in RT I found that the correct factor was calculated after black level sutraction and
with out any change at the black levels.    

Reported by iliasgiarimis on 2013-10-21 09:39:14

Beep6581 commented 9 years ago
I noticed a raise (in the file) of the Canon 5Dmk2 black levels when it applies aperture
scaling, but as I expected that to happen I did not go in deeply to analyze. That the
camera would do black level subtraction before scaling seems like very very strange,
as it would break linearity of the data and cause color shift. Problem is that if you
alter the contrast the relativity between R G and B channels will be different on different
light levels. White balancing could for example mandate 0.9*R, 0.7*G and 1.0*B, and
you do this same multiplication regardless if you are 0.1 stop from saturation or 4
stops from it. If you have through scaling altered the contrast of the raw data this
multiplication would also need compensation so you multiply with different values at
0.1 stop than at 4 stops.

I'd like to look at 5Dmk3 though and see what it does. If it's really really messy
we would need different color scaling factors too... note that scaling is generally
so small that color shifts would be hard/impossible to detect so it's a bug that could
pass undetected.

With my Canon 5Dmk2 the clipping variation is very small at all ISOs, only 1-2 units.
*Maybe* there could be a difference for softer over-exposures, I could look into that.

I'd like to keep the possibility to make advanced white level profiles, if we are conservative
enough we can skip aperture scaling and multi-channel whitelevels all-together and
that would be a bit boring. However I could change the docs to show different ways
to make white level profiles, from basic to advanced, and recommend the "advanced"
(with aperture scaling, per ISO etc) only for those that know what they are doing :-).

For Canon DSLRs DCRAW provides the black level value, thus none is in camconst.json.
Note that no raw values are actually scaled - the camera has done the scaling, what
aperture_scaling does is only to change the white level, and black level if that is
provided in camconst.json (ie not for Canon cameras).

I have not looked into how RT's raw linear correction works, but I would guess it is
some scaling of raw values rather than just moving the whitelevel. I would think that
just moving the whitelevel would be a better feature for this purpose, but I don't
know the rationale behind the raw linear correction, maybe there's some other use case.

Reported by torger@ludd.ltu.se on 2013-10-21 10:13:29

Beep6581 commented 9 years ago
I did not find any raw file from Canon 5Dmk3 shot at a larger aperture than f/2.8 to
verify black level scaling.

I looked at one of my own 5Dmk2 files shot at f/1.4 though. Rawdigger reports a black
level of 1024, ie not scaled, but the smallest value available in the file is 1035!
Dcraw/RT does the same thing (rawdigger use dcraw too of course) and report 1024, haven't
looked into why. Maybe the masked black pixels are not scaled by the camera, but the
actual image data is scaled.

Reported by torger@ludd.ltu.se on 2013-10-21 10:37:31

Beep6581 commented 9 years ago
Tested the code, black level is from masked pixels, so they do indeed stay stable.

I dug out some old Canon 7D files, this camera scales really heavily.

f/2.8 ISO800 I have roughly the range 1900 - 15830 in the file
f/9 ISO100 range is 2050 - 13584.

Black level is reported as 2048 for both. May look surprising with lower range in the
ISO800 file but I think it's simply more noise, more smearing around the black level
center which could be higher.

Anyway, for camconst.json scaling before or after black level subtraction is only about
syntax in the file, as we just define levels, we don't scale actual raw samples. And
then I think it's better to have it *without* black level subtraction, because then
you relate to *actual values* that is in the file, ie a white level of 15350 means
that clipping takes place when the raw value is larger than 15350 not 15350 - calculated
black level. I think that's more well-defined. Then you can also change black level
or black level formula without having to recalculate all white levels.

What could be discussed though is if we should scale only white level, or also the
black level if a camconst constant (it's never scaled when provided by dcraw as for
Canon cameras) like is done now. I don't know if cameras with black level constants
(Sony cameras) actually do aperture scaling so maybe it's a non-issue. A Sony example
could be good to look at. On the other hand it's a very minor adjustment with little
effect so we can keep our eyes open and do it later too.

Reported by torger@ludd.ltu.se on 2013-10-21 11:10:02

Beep6581 commented 9 years ago
To summarize my Canon camera understanding so far: masked black pixels are not scaled,
but there is some indication on that in-frame pixels could be scaled all with the same
constant, ie black level is raised a bit too. And my understanding that this is how
it should be done to avoid messy color scaling handling that otherwise would occur.
It's hard to verify for sure though as there is noise around black level.

Reported by torger@ludd.ltu.se on 2013-10-21 11:12:37

Beep6581 commented 9 years ago
I have no time now to upload my samples and I will be off line the next two days.
But to give you a hint, at f/1.4 the histogram has 1 empty level after 9 populated
levels
f/1.4 9+1, f/2.0 23+1, f/2.8 73+1 

Is the rendering after full range scaling correct ?.

7D and all 18Mp aps-c Canon have the same WP for 100, 160, 320, i.e. ISO100 looks scaled
down.

As I understand it Canon always try to normalize BL at a predefined average value (1024
for 5D2, 2048 for 7D and newer models.). 
If you check some of Magic lanterns "Dual ISO" files you can see that the average BL
is 1024 although the low ISO lines are at 988 and high ISO lines at 1060.

Reported by iliasgiarimis on 2013-10-21 13:04:26

Beep6581 commented 9 years ago
Ah, okay seems reasonable, then what they probably do is simply to adjust offset, ie
after scaling add a small negative offset to bring down the black level to their standardized
level. A fixed offset will not alter contrast and give no problems, so that's probably
what they do.

Yes rendering is correct now, as this black level issue has no effect on Canon files
(black level fetched from file).

Maybe the best is to avoid scaling black level then if it happens to be a constant
given in camconst.json, or have a camconst flag for it. I'll see if I can get hold
of some Sony files to see how they do it, if they scale at all.

Reported by torger@ludd.ltu.se on 2013-10-21 14:17:36

Beep6581 commented 9 years ago
I committed the current patch as a work in progress, as I think it's quite safe and
touches just the new camconst code.

I won't close this bug yet though, as there will probably be some minor adjustments,
in the docs for sure. Having a bit of patch buildup in my tree so I just wanted to
get this out of the way.

(Let me know if I'm too aggressive with commits, I try to be careful though)

Reported by torger@ludd.ltu.se on 2013-10-21 17:09:55

Beep6581 commented 9 years ago
Incremental update;

 - removed black level scaling. Haven't been able to verify with a Sony camera, but

   assume that there's no scaling as with Canon. Need a raw shot below f/2.8 to 
   verify.
 - updated docs

Reported by torger@ludd.ltu.se on 2013-10-21 19:37:13


Beep6581 commented 9 years ago
Well, if you commit a patch with half the job done (i.e. the output image will be different
on each release), just say it so in the commit comment so we'll wait before uploading
new official builds.

Reported by natureh.510 on 2013-10-21 20:58:35

Beep6581 commented 9 years ago
Ok! (I did commit fully working code, but with adjustments likely to come)

Someone that has a Sony camera and a wide aperture lens, we need wider than f/2.8 so
we can test and see how it does the scaling? Most interested in knowing if they scale
the black level or not.

Reported by torger@ludd.ltu.se on 2013-10-22 05:44:23

Beep6581 commented 9 years ago
Concerning scale_factor multiplication on white level without dark subtraction: *possibly*
one could make a better formula so the same scale factor would work for several apertures,
rather than providing one scale factor per aperture.

However, as different camera manufacturers can do differently that formula would probably
only work for one manufacturer. So I thought it is simpler and safer to just measure
each white level and provide a scale factor for each one.

If we really find a formula for some specific manufacturer we could add that as a feature
say "canon_scale_factor", "nikon_scale_factor" etc, but for now I think the most generic
way is to just scale the white level without black subtraction or other tricks.

Reported by torger@ludd.ltu.se on 2013-10-22 08:34:48

Beep6581 commented 9 years ago
Re #24:
http://www.focus-numerique.com/test-89/reflex-sony-alpha-330-test-exemples-photos-15.html
http://www.focus-numerique.com/test-1454/compact-sony-rx100-exemples-photos-15.html
http://www.focus-numerique.com/test-1713/compact-sony-rx100-II-exemples-photos-15.html

Reported by natureh.510 on 2013-10-22 09:03:28

Beep6581 commented 9 years ago
Re #26

Thanks, but A-300 uses the older ARW format which has 0 blacklevel, and the RX100 I've
already checked, it doesn't seem to have any aperture-scaling at all.

Reported by torger@ludd.ltu.se on 2013-10-22 10:03:09

Beep6581 commented 9 years ago
So which model are you looking for? :)

Reported by natureh.510 on 2013-10-22 10:09:08

Beep6581 commented 9 years ago
I look for a camera that scales and that has a black level larger than zero, ie ARW2
format. Sony A350 I know scales for sure (mentioned by DxOMark), and it has arw2. I
would guess that any ARW2 DSLR or SLT will scale, possibly also the NEX models.

Shoots need to be at larger aperture than f/2.8 (plus one at f/2.8 or smaller, to have
a reference shot to compare with), and this is usually the difficult part, found lots
of test shots, but no larger than f/2.8...

Reported by torger@ludd.ltu.se on 2013-10-22 10:17:02

Beep6581 commented 9 years ago
sorry was wrong about a350 it's not arw2, ie it has black level 0 and that will be no
problem. What I want to find out is if Sony does like canon, ie apply an offset after
scaling to keep black level the same.

As for the sonys we provide black level as a constant (for canons it's measured) I
need to know if it should be scaled or not.

Reported by torger@ludd.ltu.se on 2013-10-22 10:18:45

Beep6581 commented 9 years ago
committed the update; will look for sony files to verify that it will hold.

Reported by torger@ludd.ltu.se on 2013-10-22 12:06:09

Beep6581 commented 9 years ago
@ torger,

DxO did not measured the raw data scaling but the light quantity detected (this by
measuring the noise). So not all mentioned by DxO models have higher raw White Level
when using wide apertures.

Did you received (by e-mail) my 5DIII measures ?. 

Reported by iliasgiarimis on 2013-10-23 07:42:36

Beep6581 commented 9 years ago
Thanks good info.

I got hold of sony files now, I'm about to test them, I'll see if there's white level
scaling or not.

Yes got the 5D mk 3 data, made an entry for it in camconst.json and have committed
that.

Reported by torger@ludd.ltu.se on 2013-10-23 08:20:24

Beep6581 commented 9 years ago
True, looked at files from SLT-A99V and Sony don't seem to have higher raw white level
for large apertures.

Not strange about Sony though when I actually think about it (should have figured it
out), as they encode their samples with a curve and they use (nearly) the full range
of the curve for small apertures, ie there is no space left to expand.

Maybe it's only Canon that scales white levels? What about Nikon?

Reported by torger@ludd.ltu.se on 2013-10-23 08:49:27

Beep6581 commented 9 years ago
Searching for Nikon files to make check...

Reported by torger@ludd.ltu.se on 2013-10-23 08:56:16

Beep6581 commented 9 years ago
What kind of Nikon files are you looking for? Can make some with aperture 2.0 with an
AF lens and with 1.2 with an MF lens.

Ingo

Reported by heckflosse@i-weyrich.de on 2013-10-23 09:18:13

Beep6581 commented 9 years ago
Have a friend here across the table which have nikon files, I'll try to get some from
him first :-)

Reported by torger@ludd.ltu.se on 2013-10-23 09:38:23

Beep6581 commented 9 years ago
Tried a Nikon D7000, it does white level scaling, so both Canon and Nikon does it.

For the Nikon D7000 it's not very much though, at small apertures base ISO we have
16383, 15778, 16383 on RGB, ie only G is not at raw format maximum, down at f/1.8 all
three channels are up at 16383.

As Nikon has 0 as black level there's nothing to worry about in that end, so I think
we keep "no black level scaling" (currently committed) until we come across some camera
than needs something else.

Reported by torger@ludd.ltu.se on 2013-10-23 10:25:59

Beep6581 commented 9 years ago
Committed a minor doc update based on the Canon/Sony/Nikon findings. I now consider
this as fixed.

Reported by torger@ludd.ltu.se on 2013-10-23 11:36:19

Beep6581 commented 9 years ago
oh added some basic verbose prints when in verbose mode to easier debug when you add
a new entry in camconst, so you actually can see that it's being used.

Reported by torger@ludd.ltu.se on 2013-10-23 16:23:55

Beep6581 commented 9 years ago

Reported by torger@ludd.ltu.se on 2013-11-11 11:02:57