Monday, June 25, 2012

DNGMonochrome - an experiment - V


...what's lurking in your DNG files that you haven't seen yet?

Turning M9 color DNGs into monochrome DNGs

A series about the development of an experimental piece of software, called DNGMonochrome, able to convert color DNGs into monochrome DNGs...

The software is available here.


About noise

Did you know you can count noise in photographs?

What noise is exactly I won't explain here. Google is your friend (not necessarily a good friend, but he or she is quite useful sometimes, provided it's not a 'doodle' day...).

To actually 'count' noise requires some math to calculate what's called a peak signal to noise ratio, basically testing the difference between the 'base' photo and the results after interpolating.

It's mainly useful to compare different algorithms on the same photo. It needs to be the same photo by the way, because the numbers of the same algorithm can differ per photo.

And although it's not too difficult to implement it (to compare my own implementations of the different algorithms), running such math on a Lightroom B&W is more complex, seeing that I do not have access to the internals of the B&W Lightroom DNG. I can't test such a DNG against the 'base' DNG, because that B&W version only exists within Lightroom.

It means that photos first have to be exported as TIFF, which complicates this approach. I really didn't feel like going through that much trouble. But I also wondered if by default the Lightroom one wouldn't lose the battle on such testing, because of the color noise in those B&Ws. In that sense I do not know if it would be a fair comparison.


The median filter

One of my attempts to reduce noise involved implementing a median filter. It's a bit of a crude method but it works quite well.

The median filter looks at a 3 pixel by 3 pixel area, assessing the pixel in the middle. If that middle pixel is the highest of all the 9 pixels, it gets replaced by the 'median' value of the other pixels. Median value here stands for 'the middle value' in a sorted list. Then the 3 by 3 block shifts a column and does its trickery again. It does make the end result a tiny bit less sharp - still better than Lightroom - but it does a good job in killing off noise (and dead pixels).

I also implemented a smarter version of this filter, one that only tackles noise in areas that are more equal to begin with. It preserves more detail (and dead pixels).

Both filters will be an optional step in the software, but although useful I have to advise against using them, since there's very good software out there to tackle noise. DNGMonochrome produces a DNG which is fully editable in Lightroom or Photoshop, so any noise can be removed in those programs (or more specific programs designed to remove noise), in a more sophisticated way than through a median filter.


Intermezzo, before you get too bored


Was wondering what he thought of it all, but he didn't want to come out...

St. Peter's Basilica in Rome, with the balcony the pope does his thing on, waving and such...

I was standing at the favorite spot of every tourist out there, constantly being pushed and bumped into, so I had to be quick... focus is aimed a little bit too high...

The shown size here (640 pixels wide) is not the uploaded size. Click on the photo for the full 1280 pixel wide version...

And on the topic of religion: yes, this is also a converted DNG... It renounced its colors to rejoice in the glory of monochrome (well okay, I forced it to, with my software, yes... I can't deny that... but I assure you it's very happy now... no, you can't talk to it yourself, I'm its spokesperson!)


Some harder evidence

Not very happy not knowing how to assess my results, I decided to try to implement at least a Mean Squared Error calculation (or 'MSE', the basis of the peak signal to noise ratio) on the red pixel values, comparing the raw with the interpolated results.

It could just as easily have been the blue pixel values by the way, but not the green values, because those don't change (remember green doesn't borrow from red or blue). The MSE would end up as 0 (zero) for all my results, not telling me anything.

Now, because the raw has much lower red values than the end result, the MSE ends up rather high. I do not start with a full base photo (this is slightly problematic) but with a low red channel that gets altered through values based on green, ending up much higher. I can't help that. I could only use these numbers to compare results between the algorithms I use. In an absolute sense they don't tell anything and there are some additional problems due to the lack of a 'zero' reference - which I won't discuss here in detail, to avoid these posts getting even more nerdy - that make these numbers not rock solid.

They do however confirm my observation of the results, and they form a good starting point for my additional experiments with the algorithms, so I present them anyway (based on the photo I showed you in part III) - the lower the number, the 'better' the performance.

Be aware though that 'better' here is a scientific 'better' and a very limited 'better'. The simple assumption of the mean squared error and the peak signal to noise ratio is that 'lower noise' is 'better'. But 'better' as we usually understand it, can be very personal and subjective.

The one in bold is the winner, the one in italic is the loser. The difference is the difference between winner and loser.

6315708 = Ratio I
6309402 = Ratio II
6305433 = Gradient
difference = 10275

Here the Gradient (the more smooth result - comparable to Lightroom) wins.


Then I compared the same three with the 1 pass median filter:

+ Median filter
6243200 = Ratio I
6267345 = Ratio II
6284818 = Gradient
difference = 41618

And this is rather interesting, because now Ratio I wins, although it's sharper looking than Gradient, even after the median filter. I'm not sure what to conclude, other than: if the noise is cleared, Ratio I wins.


Then I compared all three with the smart median filter, which only tackles noise in more uniform areas.

+ Smart Median filter
6266575 = Ratio I
6274593 = Ratio II
6286318 = Gradient
difference = 19743

Basically the same result but with expected less difference.

At this point I was a bit surprised, seeing that Gradient looks so much like Lightroom. I had expected it to perform better. It's low on noise to begin with, but it seems fairly easy to beat by Ratio I and II if the noise is removed from those.


And then I compared the mix-over, where Gradient is used for high contrast edges and Ratio I or Ratio II for the more uniform areas:

6315389 = Ratio I + Gradient
6309276 = Ratio II + Gradient

+ Median filter
6242971 = Ratio I + Gradient
6267246 = Ratio II + Gradient

+ Smart Median filter
6266258 = Ratio I + Gradient
6274468 = Ratio II + Gradient

So there we have it: strongest combination is the mixed two algorithms in combination with the median filter.

And the difference between the overall best result and worst result is 72737.

In winning order:

6242971 = Ratio I + Gradient + Median filter
6243200 = Ratio I + Median filter
6266258 = Ratio I + Gradient + Smart Median filter
6266575 = Ratio I + Smart Median filter
6267246 = Ratio II + Gradient + Median filter
6267345 = Ratio II + Median filter
6274468 = Ratio II + Gradient + Smart Median filter
6274593 = Ratio II + Smart Median filter
6284818 = Gradient + Median filter
6286318 = Gradient + Smart Median filter
6305433 = Gradient
6309276 = Ratio II + Gradient
6309402 = Ratio II
6315389 = Ratio I + Gradient
6315708 = Ratio I

Ratio I is clearly plagued by noise (but we already established that visually), else the median filter would not have such a strong effect on these numbers. Applying the median filter to Gradient, only makes it jump a few positions. But applying it to Ratio I makes that one jump from position last to almost the winner... rather an improvement...

Frankly, I don't care a lot about these numbers. Visually I like the mix over between Ratio I and Gradient or Ratio II. And noise can be tackled in Lightroom.


And resolution?

But does this tell anything about additional resolution?

I'm afraid not.

Conclusions on resolution I think need to be established visually. I have no idea how to measure those differences. I see sharper output with Ratio I, II and even with Gradient, compared to Lightroom. For me that's enough, even if I don't know if I'm allowed to call that 'resolution'.

The results do have me puzzled a bit where the Gradient algorithm is concerned - here the lack of a base photo might play a role -, so I will be conducting some more experiments on that one. I can not fully explain why it lags behind when the median filter is turned on, seeing that it's the most complicated algorithm and produces Lightroom similar results. It might be that its initial design is better suited for color than for monochrome, which means it can be improved.

My aim is to end up with only one algorithm that does it all, preserving as much of the sharper output of Ratio I and II, but without the artifacts of Ratio I.

Be aware though - as stated before - the numbers need to be taken lightly.

Ratio I - used without the assistance of Gradient - still produces artifacts. In anyone's healthy eye, that would not be considered 'better', even if the numbers state it is.

You be the judge if you decide to try the software.

Note that these conclusions and numbers are only valid for the particular photo I ran the tests on (until proven otherwise). I haven't run extensive tests like these on other photos. The test photo has large areas of out-of-focus background, which might influence the numbers. I might incorporate the MSE in the software so you can compare the different combinations yourself on your own DNGs.


And now for something completely different

Before I end this episode, let me show you two more results, both with the Ratio II algorithm, since this was a lot of text (and almost the pope), but only one photo so far.

Compare the two.

I will talk about this next time.

They're both monochrome DNGs... and no - for the clever reader - I'm still not color interpolating nor are these differences created by changing brightness or contrast...

(If you do guess right, don't tell the color police, because for this they surely gonna lock me up!)

Things are about to get a little bit more Frankenstein in the next part, stay on the road!


Summilux f/1.4 asph, ISO 160... shot with the sun behind the kids and me not professional enough to properly expose for their faces, led to a photo I had to push a bit (raised exposure and blown highlights in the sky)... the photo is slightly cropped... no sharpening and no noise reduction... the shown size (320 pixels here) is not the uploaded size... click on either one for a 1280 pixels version... stick to the 'full' version... the other sizes are automatically down scaled and do not reflect the true output...

M9 color DNG turned into two different monochrome DNGs with DNGMonochrome and the Ratio II algorithm...

... continue with part VI
... back to part IV

No comments:

Post a Comment