RawDigger: detecting posterization in SONY cRAW/ARW2 files

Spring is Here!

All LibRaw Products and Bundles - 25% off

Our Special Prices are valid until May 06, 2024.

Buy now!


Lossy compression of raw data is currently the only option available in Sony cameras of series NEX, SLT, RX, ILCE, ILCA, and the recent DSLR-A. The first part of this article is showing how to detect artifacts caused by this compression. We will be discussing the technical details of this compression in the second part of this article.

In the vast majority of cases, the compression artifacts are imperceptible unless the heavy-handed contrast boost is introduced. There are, however, exceptions. With some unlucky stars in alignment, the artifacts can become plainly visible, even without much image processing.  All that is necessary for the artifacts to threaten the quality of the final image is a combination of high local contrast and a flat featureless background.

Lets have a look at the example provided by Matti Koski, it is the same example that was published by Lloyd Chambers in his blog. Upd.: Many thanks to Mr. Koski who now gave us his permission to link to the original raw file _DSC0035-startrails.ARW

The artifacts in the form of a horizontal color fringe on both sides of one of the star trails are very visible even if all of the sliders are set to zero, except the exposure slider:

Figure 1. Star Trails. Shot opened in Adobe Camera Raw

This problem is even more visible in RawDigger, because for display purposes, RawDigger employs a variant of Auto Levels, when the tones of the image are stretched to occupy the whole tonal range:

Figure 2

What we have here is a clear case of posterization, which is the lack of continuous gradation of tone, or, in other words, color quantization. It is caused by a sort of rounding error specific to the compression scheme Sony are using for there cRAW format. This error occurs when the step between values in the 16-byte block being too crude (a detailed explanation of the mechanism is in the «Inside SONY cRAW format» part of this article, below). As a result of this rounding error, the artifacts are visible even without moving the contrast slider to the right.

To detect the problematic areas in images captured in Sony cRAW format, RawDigger, starting with the version 1.0.5, offers a special unpacking and display mode, which can be switched on with:

Preferences – Data Processing – Sony ARW2 processing mode – Processing mode: Delta step relative to value

Figure 3

In this mode, instead of a regular procedure of data unpacking, we calculate the degree of posterization, that is, the ratio of the minimum variation of data (data step) in the 16-pixel block to the value of the pixel. This ratio is in per mil (1/1000, ‰). Consequently, the ratios of several tens per mil (that is several percent) may be visible if the background is a smooth gradient. Several hundreds per mil (that is several tens of percent) will certainly be visible if the background is smooth and featureless.

Here is the same area of the star trails shot displayed in Delta step relative to value mode:

Figure 4

As you can see, the areas containing artifacts can be easily detected. These areas may exhibit posterization on the final image. 

With a little effort we can make this mode even more usable.

Suppose we want to select the areas where the degree of posterization is 10% (100‰). To do so in RawDiggerer Preferences – Over/Under Exposure we set the Manual level all channels in Overexposure Detection group to 100:

Figure 5

Switching on the indication of Overexposure (check mark in OvExp) we will see a red overlay over the areas where the degree of posterization is higher than 10%:

Figure 6

In this mode, the areas of potential posterization are displayed over the whole image. However, on the final image, posterization will be visible only over smooth and featureless backgrounds like sky, sometimes eye whites, and flat shadows. In all other cases, the only effect of this posterization is an error in local color reproduction. There is very little chance that this error will be discernible.

Let’s take a look at the following shot (from Quesabesde's Sony A7R analysis page):

Figure 7

All of the hard contrast edges exhibit some artifacts where one can suspect posterization:

Figure 8

However, on the final image the posterization is visible only on the edge of the tower where the background is a featureless blue sky.

We will use this shot to demonstrate an additional setting, which helps to exclude the lowest tone values (deep shadows) from the posterization map.

Deep shadows always contain hidden, but substantial posterization because only a few levels are present there. Even if the encoding is lossless, the minimal step in the shadows of a cRAW file is equal to 2. This means that if the level is 64, the degree of posterization is more than 30‰ (2/64 = 3.125%).

In order to keep the display of the image cleaner, you can use the Ignore shadows below level NN setting. This setting is active only together with Sony ARW2 Processing – Delta Step relative to value.

If this setting is turned off (that is, the value in the field is set to zero), the scene will show additional posterization in the shadows on the foreground:

Figure 9

Inside SONY cRAW format

Sony cRAW files are packed and unpacked as following:

  1. Data coming from the sensor is biased by the black level (for example, for Sony A7r camera black level is 512 and this value is added to all the data) and is compressed through the tone curve equivalent to the one below; the compressed result contains 11-bit values.

Figure 10

  1. Each data row (a row has the height of 1 pixel) is split into 32-pixel chunks, each chunk containing interleaved pixels from 2 color channels. For odd rows a chunk contains 16 R-pixels and 16 G-pixels (RGRGRG…), for even rows it contains 16 G-pixels and 16 B-pixels (GBGBGB…)
  1. The structure of each 16-pixel block is:

Figure 11

Here, Max is the maximum pixel value in the block, Min is the minimum value in the block, Offsets are the positions of pixels with Max and Min values relative to the block start

Deltas are calculated as:

DataSpan = Max – Min

Step = 2rounding(log2(DataSpan/128))

Delta = (PixelValue – Min) / Step (see more on this below)

The length of the block is 2*11+2*4+14*7=128 bits, or 16 bytes. Thus the raw data compressed per cRAW scheme effectively uses 1 byte per pixel; but the total ARW2 file size is slightly larger as it contains not only cRAW data, but also metadata and JPEG preview.

The larger the data span in a 16-pixel block is, the larger the step is, which is multiplied by the delta value to restore the pixel value, and consequently the larger the data step is. For a data span of less than or equal to 128, the factor is 1, and no rounding error is introduced while reversing the delta encoding. For a larger span, the scheme does introduce the rounding error, which may lead to posterization. In other words, if the chunk of 32 pixels spans across an area that contains a large variation in brightness, the data in the block is not exact, but is only an approximation.

Data span less than

128

256

512

1024

2048

Step

1

2

4

8

16

  1. During the raw conversion, first, the delta encoding is reversed, next, the linearization tone curve (contained in the metadata of Sony ARW2 files) is applied to decompress the data, and finally the black level (also taken from metadata) is subtracted from the result.

After black level subtraction Sony cRAW linearization tone curve is effectively this:

Figure 12. Sony cRAW tone curve with black level being subtracted

Or, in a form of a table:

Figure 13

Consider the star trails shot once again:

Figure 14

Inspecting the green channel, we can see that the RAW values in the proximity of the track (black level is subtracted) are:

  • The star trail proper has pixel values that reach as high as 4080
  • The sky around the trail is a smooth featureless background, and the pixel values close to the trail range from 80 to 200.

Applying compression tone curve to this data:

  • The maximum value is 1474 (compression applied to 4080)
  • The minimum value is 296 (compression applied to 80)

Data span = (max – min) = (1474 – 296) = 1178.

In order to code values up to 1178 in 7 bits we need to set the step to 16: 2ceiling(log2(1178/128)) = 16.

In other words, for a data span of 1178 the nearest larger number that is an exact power of 2 is 2048 = 211. Dividing 2048 by 128, we have the step of 16.

The delta values during the decompression are multiplied by this step and further decompressed through the curve which you can dump using RawDigger. In our example, after performing decompression through the tone curve the step of 16 becomes 32, that is ≈14-30% of the values characteristic to the background. Naturally with such a crude step posterization becomes plainly visible.

Other Modes under ARW2 Data Processing

Since we have already discussed cRAW/ARW2 format, it is easier to understand the other options under Sony ARW2 Data processing:

  • Standard processing – regular unpacking of RAW data
  • Only base pixels – those pixels where the precise 11-bit values are coded (min and max in the block) are unpacked, while for all other pixels (Delta pixels) are set to zero.
  • Only delta pixels – Delta pixels are unpacked, and adding the minimum value restores their values, after that the base pixels are set to zero.
  • Delta pixels relative to zero – same as previous setting but minimum values are not added to Delta pixels.
  • This mode is also, like the one below, useful for determining the area where the posterization may occur. However now we have added more tale-telling mode, that is the one below.
  • Delta step relative to value – this mode was used throughout the whole article.

This article in PDF format: RawDigger_Detecting_Posterization_in_Sony_Camera.pdf


The Unique Essential Workflow Tool

for Every RAW Shooter

FastRawViewer is a must have; it's all you need for extremely fast and reliable culling, direct presentation, as well as for speeding up of the conversion stage of any amounts of any RAW images of every format.

FastRawViewer 1.3 Program Window

Now with Grid Mode View, Select/Deselect and Multiple Files operations, Screen Sharpening, Highlight Inspection and more.


75 Comments

32 is the minimal non-zero

32 is the minimal non-zero difference between pixel values in this specific pixel block.

but why there is several stamps accross the track

do they have same value?
and
what's the reason of the posterization show up (whether is the background pixels' value lift or the value in each stamp is same and enlarged to 32 by decoding)

No, the pixel in block have

No, the pixels in block have different values, but minimal non-zero difference is limited by minimal step (which, in turn, depends on min/max values in block).

 

I can't explain any better

I can't explain any better than it is already in the article. The necessary examples are given there.

what is non-zero difference

ok but what is non-zero difference ,could you please explain the term?thx in adv

why you use 32 to devide 80 and 200

why you use 32 to devide 80 and 200 (i know 80-200 is the range of background values)

32 is the non-zero difference between values and values of the pixels (i got it with the search of it using bing)
but you use a difference to devide the min value and the max value instead of devide the range (200-80=120) to see how many 32 difference inside and how many patterns of posterization will show up (each 32 will lead to an posterization, so how many 32 means how many patterns of posterization, so i calculated by (200-80)/32=4 patterns)

Question:does delta value and

Question:does delta value and value of 11bit max min and the final result can only contain integer numbers
(after calculate souce number 17203 =2046.9 != 2046)
___________________________________________________________________________________
if so there must be some value missing because of it's not integer ,but how to deal with the number that is not integer?(set value missing or round up to the nearest integer:1.4=1,1.5=2)
(so will 17203 missing during compressing to 11bit or =2047 instead)

and there's more value missing if the step is 16 (for example 1783(11bit value of 2039 and subtracted 11bit min value 256(source number is 0) already)/16=111.4375, it's not integer ,so set value missing or use 111 instead )

if so, the final value will get more missing(because it need to futher decompress using linearization tone curve and the final result should also be integer:

111x16+256=2032,and the decompressed using linearization tone curve is

16212.4211

so we should use 16212) and the reason why the colorful block show up( is because of all value shoud be integer)

so if sum up ,the conclusion is the missing value or the round up (to the nearest integer) lead to the posterization show up

pixel block data is

pixel block data is interpreted in integer domain. This is clearly indicated in delta calculation formula.

set value missing or round up to the nearest integer

if so
there must be some value missing because of it's not integer
but how to deal with the number that is not integer?
(set value missing or round up to the nearest integer:1.4=1,1.5=2)

All calculations are

All calculations are performed in integer domain.

Because step is rounded up to nearest power of two (integer), there is no non-integer numbers in calculations, so no need to rounding/etc, because all intermediate and final results are integer.

 

Q1:what's the input number

Q1:what's the input number mean (in Sony cRAW linearization tone curve) why it not have the value such as 17203 (witch after compress calculate processing the souce number 17203 become 2046.9 != 2046)?

Q2:as said in the article

Data span = (max – min) = (1474 – 296) = 1178.

range of background is 80-200

So:200=356 after compress to 11 bit

(356-296)/16=(max-min)/step=3.75=delta

So: how you say all number ar. all calculated in integer???

All data stored in raw files

All data stored in raw files are integer with low bit count (11/7).

So, when we unpack the process is goes in reverse direction:

11-bit min/max, 7-bit deltas (multiplied by integer step), then expansion curve.

All steps are integer.

There is no way to get 17203 on output.

All data stored in raw files

All data stored in raw files are integer with low bit count (11/7).

Q1:does 11/7 means data stored in 7 or 11 bit values or devide 11 by 7?(get puzzled)

Q2:i am not means to get 17203 after the 11bit or 7 bit count process,i mean if i use 17203 as source input

then after converting to 11 or 7 bit

17203 will become 2046.9 != 2046

So: the sorce data after the compress to 11 or 7 bit we get a number witch is not integer

So how you say all number ar. all calculated in integer???

thx for helping with patience

thx for helping with patience

it maybe the last riddle that puzzles me

Q:why you use 32 to devide 80 and 200(it's all pixel values, you use a step to devide an pixel value,so i wonder whats the sense of it)

Or maybe i am not got the sense of it(''To compare minimum non-zero step in data with average background.''),if can i hope you could explain a little bit further

To compare minimal data step

To compare minimal data step (defined by code/decode process) to average surrounding pixel values.

Just to show, that minimal possible data change is very high (compared to values), making posterization unavoidable

Q1:so do you mean to

Q1:so do you mean to calculate how large the minimal possible data value changed to the value of pixels' raw value(black level is subtracted) it is

and that high change of minimal possible data making ≈14-30% of the values characteristic to the background (making posterization unavoidable)

Q2: So from said previously from Q1 ,does it means the tone of background is not change smoothly because of the reason of 32 steps( after performing decompression through the tone curve) exist between,

so each pixel values is compartment of 32 step biased from the source
so the pixel will be brighten and rough transition(not smoothly enough for tone changing)
so posterization unavoidable

am i right, now?

maybe the steps is too large

maybe the steps is too large so the grayscale is not smooth but if the step can be small enough or precise enough( such as 1) the pattern of posterization will not show up

am i right

Just curious if the same

Just curious if the same analyze could be done on the files from A7III/A7RIII/A9. I am very interested what has chnaged since then.

These cameras uses exactly

These cameras uses exactly same format for 'compressed RAWs', so problem is still here (but not for uncompressed RAW format)

How are Canon And Nikon file

How are Canon And Nikon file in comparsion when compressed. Do they have 1 bit les as well instead of 12 bit? Sorry I am not technical So want to understand simply the difference.

Canon's compression is

Canon's compression is lossless. Nikon has both lossless compression and lossy compression (not in all cameras), but Nikon's lossy compression do not have such kind of artifacts.

Followup: Sony's artifacts

Followup: Sony's artifacts arise because data is compressed in 32-pixel blocks, so if image has high contrast in such block (any contrast border) than minimal data step is high (see detailed format description in this article). Most other lossy RAW formats are 'per pixel', not in blocks (with lower precision in highlights; this is OK because absolute eye sensitivity is less in highlights), so this will not result in boundary-bound artifacts.

Pages

Add new comment