Sunday, September 29, 2013

Blurry vision III

And a small victory today...

On a side track I've been testing color DNGs, to figure out if it is actually possible to deblur a RAW file in stead of an exported JPG. I couldn't find a theoretical reason why not, but seeing that a DNG still needs to be interpolated, I did wonder if filtering the RAW values like the deblurring does, would lead to any problems.

Basically I'm using the engine of DNGMonochrome: interpolate the three color planes (green, red and blue), deblur all the color planes with the same kernel, then write back the DNG as a RAW file, with the replaced pixel values for green, red and blue. Producing what I was looking for: a deblurred - non interpolated - RAW file.

Deblur first, develop later.

First attempts were rather horrendous, but today I had some success.

It's the same umbrella - from my previous post - but now in color. The 'deblur' is slightly less spectacular, but that's because I'm currently deblurring on a preview of the grayscale version of the photo. I haven't implemented a color preview yet.


Small crop from a blurred Canon 40D photo... Move over the image with your mouse to see the blur corrected version... JPG produced from a deblurred DNG...

Saturday, September 28, 2013

Blurry vision II

Making some progress with the deblurring. I haven't shown you any shots of the user interface yet, because that's still unfinished, although it is getting closer to a presentable version. In general I'd say that if you'd like to use this in a next version of DNGMonochrome, be aware it's not a one-click solution. Some photos really require some effort to get to an acceptable result, and the method itself will never lead to 'perfection'. It's simply not possible (I think) to filter photos like this without some downsides (as in additional artifacts thrown in for free). Personally I think this method is only useful if the blur isn't too extensive.

Here's another quick example...

Blurry original... (no mouseover on this one, see the crops below...)



Small crop from a blurred Canon 40D photo, converted with DNGMonochrome... note that this is a real life shot, not some fake blurred image... the monochrome DNG was then developed in Lightroom, with no sharpening and no noise reduction. Move over the image with your mouse to see the blur corrected version produced by DNGMonochrome, which got exactly the same treatment in Lightroom (no sharpening nor noise reduction)...



Same as above, but an even smaller piece of the photo... move over the image with your mouse to see the blur corrected version produced by DNGMonochrome...



Same as above, but now the blurred original was sharpened 70% in Lightroom... as you can see - for the more doubtful - the deblurring isn't comparable to sharpening... Move over the image with your mouse to see the blur corrected version produced by DNGMonochrome (which was not sharpened)...

Thursday, September 26, 2013

Blurry vision I

Ok, well, this is not really about blurry vision, more about blurry photographs, and the methods to get rid of that blur.

I've been experimenting a bit with it in DNGMonochrome.

There's several solutions available (in software) out there, to deblur photos. Be it motion blur (camera shake) or blur due to focus errors. But the problem with those solutions (some are actually quite good) is that they only work on the finished end product. You have to export your RAW or DNG first to JPG or PNG, then deblur that photo.

I find that rather tedious, because once you've done all that and you decide you still need to make some adjustments to the RAW photo in e.g. Lightroom, you have to go through the whole process of deblurring the final export again. I regularly go back to older DNGs or CR2s and redo them. Software progresses, your own vision of how a photo should look might change, and then you still have to have the deblurring software around and remember the settings for that particular photo. It's just not very convenient.

I think this deblurring should take place on the DNG or the RAW file, before you start working on it in your RAW developer. Problem is: so far I haven't found software that actually tackles the RAW file.

So, introducing the blur/deblur filter in DNGMonochrome, with plans to extend it to color DNGs. Deblur first, then develop, in stead of develop, deblur afterwards.

Yes, ok, but wait...

How does this work?

Well, it works.

Let me show you...

Move over the image with your mouse to see the difference...


Small crop from a slightly blurred Canon 40D, most likely a focus error, converted with DNGMonochrome... note that this is a real life shot, not some fake blurred image... the monochrome DNG was then developed in Lightroom, with no sharpening and no noise reduction. Move over the image with your mouse to see the blur corrected version produced by DNGMonochrome, which got exactly the same treatment in Lightroom (no sharpening nor noise reduction)...

As you can see - although this example is quite subtle, I don't have many blurry real life shots, because I usually throw them - it really works.

The deblurring filter uses a Fourier transform of the photo (essentially this means the photo is split up in two separate collection of numbers, both belonging to the frequency domain: one collection is called the spectrum and the other is called the phase). After the Fourier transform the transformation is filtered using a second Fourier transform of a so called 'kernel'. That actually causes the blur / deblur to take place (I'm still working on the user interface of that one, because currently it's simply a free block you can click in to create the kernel). Then the Fourier representation is transformed back to the original photo.

One of the biggest issues I had to solve was the memory demand of this transform. The Fourier transform requires a huge amount of memory for the bigger photos. For your average M9 DNG we're talking 16 bytes per number (a real number and an imaginary number, 8 bytes per piece), times the size of the closest power of 2 of the longest edge of the photo. In case of the M and M9 that's 8192 by 8192. Now multiply that (8192 times 8192 times 16) and you get a whopping 1073741824 bytes (roughly 1 gigabyte).

Then for the kernel we need the same amount. And then for some nice laplacian filtering or some other additional goodies, we need a third transform.

So in total we're talking at least 3 gigabytes for an average deblurring action.

Now, I was able to cut that down to 1.5GB by changing the doubles to floats (going from 16 bytes per number to 8 bytes per number), but that still wasn't enough.

My 64-bit Windows system with 4GB of memory simply couldn't handle it. Small photos (as shown in the example) were fine. The bigger ones crashed the software.

Well, to cut a long and boring story short, I solved it with memory mapped files. Essentially cache writing memory to disk. It does slow down a bit, but it works. All the huge DNGs now deblur without memory problems, at least on my system :-)

This whole thing isn't finished yet, there's more experimenting, but I will try to keep you posted and show you some more examples when things progress...

Wednesday, September 11, 2013

DNGMonochrome 0.9.72 beta released

No spectacular changes in this release, but it does come with some new stuff.

New in version 0.9.72
  • Fixes some very minor bugs in the user interface, which didn't affect the conversion.
  • Makes some small adjustments to the GreenSplit implementation of previous version, improving fine detail in darker areas.
  • Improves the red and blue conversions. Especially the red conversion could suffer from a zipper like artifact, visible mostly on highlighted edges with bright red background. This started showing in some photos around 200 to 300% magnification.
  • Improves the algorithm by applying a localised minimum and maximum during interpolation, which helps especially the very noisy photos and improves the outcome of the algorithm when used together with the 'sharper' setting.
  • Adds code to enable this version to function with the new Lightroom plugin. The plugin installs through the regular installer, together with DNGMonochrome 0.9.72 (only for Windows Vista / Windows 7 and Lightroom 4/5).
  • Brings back the strength setting for RAW red and RAW blue filtering, which was dropped too hastily in an earlier version... strength has the same range (steps of 5%) as the RGB filters... if you want to get to the RAW red or RAW blue results version 0.9.71 produced, push the strength slider to 100%.
  • Adds a manual 'Update check' through a new button in the main screen... it will tell you if there's a new version available, provided you're online.


Lightroom plugin

If your work flow is based on Lightroom, the new plugin can be quite a help. It can be installed by choice (it's in the 0.9.72 installer, you don't have to download anything else... turn it off during installation if you don't use Lightroom, although installing it anyway won't harm).

A few notes:
  • The plugin is more or less beta. This is my first Lightroom plugin, so be gentle if it doesn't work on your system as intended. Please try it out on some backup DNGs first and make sure it works properly! DNGMonochrome contains safeguards to avoid ever overwriting an original, but nevertheless, convince yourself first it works as intended.
  • The plugin will not work with older versions of DNGMonochrome: you need to install it together with at least version 0.9.72 - the plugin is embedded in the installer of DNGMonochrome.
  • The plugin will not work with older versions of Lightroom (earlier than version 4).
  • Lightroom 4 doesn't work on Windows XP, so if you're on Windows XP, this plugin won't be very useful. Also, since DNGMonochrome itself was adapted to work with Lightroom, the XP version now has a separate installer. Pick the right one on the download page since the Vista/Windows 7 version of DNGMonochrome will not work on XP.
  • Do not change the folder of DNGMonochrome (usually under Program Files) or move it to another location after installation: the plugin will get lost. If you need or want to install DNGMonochrome in a different folder, do it during installation, when the installer asks you for the installation path, or - if you want to change it after installation - uninstall DNGMonochrome, then reinstall and change the installation folder during installation (and be sure to include the plugin in the re-installation).
After installation, start up Lightroom, select a color DNG and look under the Help menu in Lightroom. There should be an entry called 'Plugin extras -> DNGMonochrome -> Convert with DNGMonochrome'. If you select it, DNGMonochrome should start with the selected photo from Lightroom, and after conversion (you still have to press that button in DNGMonochrome!), the monochrome DNG is automatically imported into Lightroom, after being saved to the same folder as the original color DNG.

Note that if you're working from a 'last imported' folder within Lightroom, you might not see the imported monochrome photo. If that happens, go to the Library module and select the folder the original is actually in. Then you should see the monochrome version.

You can keep converting the original in DNGMonochrome (changing filters or noise reduction and reprocess) and every converted copy will be imported automatically. Close DNGMonochrome after you're finished, or select a different DNG in Lightroom and go to the Help menu again to select 'Convert with DNGMonochrome' once more. The already running version of DNGMonochrome will close automatically and a new one will open with your selected DNG.

Read more about this plugin here (about installing, using, turning it off or deleting it if you want to get rid of it).


Why the strength setting for RAW filtering?

Well, the reasons are a bit fuzzy, but in hindsight, the RAW filtering with strength is a very simple procedure compared to the more complex RGB filtering. I haven't extensively compared both results side by side, but I did notice that the RAW filtering with strength (after compensating for the loss of exposure in Lightroom) seemed slightly cleaner and less noisy than similar results with RGB filtering.

There are some distinct differences:
  • With RGB filtering you get the right exposure setting at every strength setting. Strength at 5% will give the same exposure as strength at 100%. With the RAW filtering, the stronger you filter, the more you have to compensate in your RAW converter for lost luminance.
  • RAW filtering doesn't care about white balance.
  • RAW filtering can not do a green filter.
  • Due to the loss of exposure it's not possible to use gradient filtering with the RAW filters. So if you only want to filter part of the photo, you'll have to use the RGB filters.


Download

You can download the new version of DNGMonochrome here.

Wednesday, September 4, 2013

Quick update

Yes yes, I know I have been a bit silent on the subject of DNGMonochrome, but not to worry, I haven't abandoned it. There will be a 0.9.72 soon (with Lightroom plugin, making it possible to convert from within Lightroom, and some other small improvements), and I still have some ideas to extend it. It's just that I have been quite busy the last few months doing other stuff, hence the silence...

Tuesday, September 3, 2013

Exhausted

Don't worry, he was still breathing... in a warm double decker tram, shot from a tram in front of it...

Hong Kong Island, Hong Kong, 21 August 2013

Click on photo for the full version...

Monday, September 2, 2013

Apartments

Apartments on Hong Kong Island near the east, Hong Kong, 23 August 2013

Click on photo for the full version...

Sunday, September 1, 2013

The Peak I

Shot from The Peak on Hong Kong Island, Hong Kong, 25 August 2013

Click on photo for the full version...