Support my work on Patreon

If you like my work, please consider to help my growing family with a little financial support through my Patreon creator page.


Alternatively, you can leave a one-time donation via PayPal using the Donate button below.

Total Pageviews

Friday, November 28, 2014

Black and white conversion in Photoflow

If you search on the internet, you will find tutorials describing dozens of different methods  for converting a color digital image to grayscale (or "black and white" as many people say). There are lots of web pages that describe the grayscale conversion techniques and the theory behind them, so I decided not to go through all the details here... others have done that much better than I would.

However, if you are new to the subject and you need a good introduction, one of the best places you can visit is Patrick David's blog post at pixls.us. There you will find a very clear explanation of the technical background as well as a detailed description of the methods I'll discuss in this post, so I really encourage you to have a look there before continuing...

Generally speaking, we can say that the goal of grayscale conversion is to create "volume" out of "color", or in other words to translate the colors into reach tonal variations. There are of course lots of artistic exceptions to this rule, but I think that the basic idea is there...
However, there are lots of (infinite?) ways to translate a given "color" into the corresponding shade of gray, and which one is "the best" depends in most cases on the personal taste and on the image itself. You'll have to experiment a lot to find your personal "signature". The software must help you by providing several different options that can be quickly and easily compared on your screen.

One of the main goals I had in mind when I started coding PhotoFlow was to provide a good set of grayscale conversion tools, with all the flexibility that is usually found in high-end software. This means not only different conversions methods, but also the possibility to blend different channels together in separate layers, and access to Lab and CMYK channels in addition to RGB.
Of course it is too early to say "mission accomplished", but things seem to be on good track, and this post will try to show what can be done at the moment of writing.

Photoflow provides three main categories of grayscale conversions:
  1. straight desaturation: there are four methods available, owever each method is not configurable
  2. channel mixer: one of the most classic methods for grayscale conversion, it gives a lot of flexibility
  3. Pat David's black&white film presets from G'MIC: they emulate the spectral response of several widely used B&W films.
All grayscale conversion tools in PhotoFlow generate output images that are in the same colorspace as the colored original. For example, if you start from an image in the AdobeRGB colorspace, the grayscale version will still be an RGB image in AdobeRGB colorspace. Thus, you can for example easily add some toning or duo-toning without having to convert your image back to RGB...

Let's now see each tool in some detail.

Desaturation methods

The desaturation tool in photoflow is a close match of the one you can find in GIMP, and provides the same three grayscale conversion methods: LIGHTNESS, LUMINOSITY and AVERAGE. There is a very detailed explanation of the formulas behind those three methods in Patrick David's tutorial, with many examples of how colors are converted to grayscale in the three cases, so I will not repeat all the arguments here.

To apply the desaturation tool to a color image, you have to add a new layer and choose "Desaturate" in the "Color" group of the tools chooser dialog (see below).



Once the new layer is added, the corresponding configuration dialog will open automatically and will let you choose the desaturation method through a selector widget. You can at any time access this dialog by double-clicking on the name of the corresponding layer.



Photoflow provides a fourth method that has no GIMP counterpart: "L channel (Lab)". As the name of the method indicates, it uses the L channel of the Lab colorspace to convert colors to grayscale. The Lab encoding is the result of long scientific studies of the human perception of colors, and the L channel is designed to provide the closest match of how the human eye translates colors into perceived "lightness". If you want to learn more about the Lab colorspace and the theory behind, the wikipedia page could be a good starting point.
Another nice advantage of the L channel is that it is "perceptually uniform", in the sense that the L values are encoded in a way that reflects the natural response of the human eye. For example, L=50% corresponds to  a well-exposed 18% grey patch, which is usually called "mid-gray".
Technically speaking, in photoflow the L channel is extracted by first doing a colorspace conversion from the input profile to the Lab colorspace, then filling the a and b channels (which encode the color information) with 50% gray, and then converting the resulting greyscale image back to the original colorspace.

The images below show the result of the different desaturation methods compared to the original color image. For this comparison I have used the same portrait image that you will find in Patrick David's tutorial (with the author's permission), so that you can eventually compare with the examples shown there. At least to my taste, the L channel conversion gives the best tonal variations, particularly in skin areas, followed by the luminosity one. The other two (lightness and average) give results that are globally flatter.


Whitney by Patrick David (cc by-sa)
Mouseover type to see: Original - Lightness - Average - Luminosity - Lab L channel


This last conversion method is also the only one that gives always the same result independently of the colorspace in which the input image is encoded. To understand that, we need to introduce a bit of color management theory...

RGB, colors and color spaces...

Many people think that RGB values represent colors... however, this is not entirely true. RGB values are sort of meaningless if you do not specify the colorspace in which they are encoded. For example, a typical caucasian skin tone is represented with quite different RGB values in the sRGB and ProPhotoRGB colorspaces, and this has some consequences on the grayscale conversions discussed above. For example, the picture below lets you compare the result of a "lightness" desaturation applied to the same image encoded in sRGB and ProPhoto. As you can see, the tonality in the skin areas changes quite significantly...

Mouseover type to see: sRGB - ProPhotoRGB



The only exception is the desaturation based on the "L channel", because in this case the whole conversion is performed by taking color management properly into account. Hence, the grayscale version will look the same independently of the input colorspace, making your workflow more "predictable". In all other cases, you should consider to convert all your color images to a reference colorspace before desaturating, to have a uniform starting point for all your edits. In photoflow, it is just a question of adding a "colorspace conversion" layer below the desaturation.
Choose the RGB colorspace that gives you the best results, and stick with it all the time... you have been advised.
As a rule of thumb, sRGB will give you the larges tonal differences between Red and Green on skin tones, while large-gamut colorspaces like ProPhoto will bring the Red and Green channels closer to each other.
Another interesting choice is the LstarRGB colorspace, because its tone curve is encoded the same way as the L channel of Lab.Therefore, a well-exposed 18% gray patch will be represented as R=G=B=50% in LstarRGB, which makes in my opinion the use of curves and other tonal editings more intuitive...

Enough theory for this post, let's go back to practice!

The channel mixer

PhotoFlow includes a simple implementation of the channel mixer. The tool is not as complete as the one found in other programs, but it is sufficient for converting images to grayscale with great flexibility. Again, for a detailed description of how the channel mixer works I encourage you to read this post before continuing.

The channel mixer tool is activated like usual: you have to add a new layer and select the "channel  mixer" in the "Color" tab of the tool selection dialog. Once the layer is added, the configuration dialog of the channel mixer will show up automatically and will let you control how the RGB channels get mixed to produce the grayscale result.



For the moment, the channel mixer only creates grayscale images. Moreover, the multiplicative coefficients of the three channels are automatically scaled so that they sum-up to one, thus avoiding any shift of the overall image brightness. However, the coefficients can be set to values larger than 100% (up to 200%) or negative (down to -200%).


Hue + channel mixer adjustment

The channel mixer is very flexible and powerful, but playing with the individual RGB multipliers is sometimes long and tedious before one reaches the optimal result. There is however a nice technique that allows to dramatically change the result of the channel mixer using just one slider. The idea is to add an HUE adjustment layer below the channel mixer, which is then kept at its default setting of R=100% G=0% B=0%. Once you are in that configuration, you can significantly change the tonality of the red channel by simply shifting the hue of the color image thoward positive or negative values. As you can see below, you can improve a lot the constrast of your image or turn your model into a dangerous alien... you have been warned!



Mouseover type to see: Original - Hue = -90 - Hue = +90



G'MIC B&W Film Presets (from Patrick David)

The last conversion technique that I'm going to discuss is based on the amazing film presets prepared for us by Patrick David and included in the G'MIC processing library.

I've already written a detailed blog post on how to use the film presets in PhotoFlow, so I suggest you to read it here if you are not familiar with them.
In this case, we need to select the "Emulate Film [B&W]" item in the "G'MIC" tab f the layer chooser dialog s shown below.


Once you hit the Ok button, you will be prompted with the preset configuration dialog, where you can choose the actual film brand to emulate. In the example below, I've choosen the "Ilford Delta 400" preset.


Final considerations

That's all for this post. It's now time for you to do your own experimentations... you should also keep in mind that the techniques I've shown here can be further combined in lots of different ways: since they are applied as adjustment layers, you can play with layer opacities, blend modes and masks to further refine your conversions. There is almost no limit to what you can do...

Monday, November 24, 2014

Initial version of pixel cloning tool

Recently I have been working on a feature that I was planning since long time, but I had no idea how to implement... a pixel cloning tool. Finally, it was not that difficult and the preliminary version is now on GitHub for testing.

You might think that this is not such a great step forward, and that many other programs have a similar tool since long time (gimp, krita, etc...). However, the version implemented into photoflow has the nice feature of being non-destructive.
 
Practically, this means that pixels are copied on-the-fly when requested, and that they always reflect the up-to-date status of the input data. For example, if you put the cloning tool above a curves layer, the cloned areas will automatically reflect any changes done to the curves adjustment...

Here is the preliminary tool in action:


It still needs a lot of improvements, like feathering the edges of the strokes or adjusting their opacity, but the basic functionality is there and the code is fast enough to be used in real time.
 
To use the cloning tool, you have to add a new layer and select the "Clone stamp" item in the "misc" tab of the tool selection dialog.

Cloning the pixels works more or less like in GIMP: first you have to ctrl-click on the image to define a source area, and then start drawing to clone the pixels at some other place. With just one minor caveat: in order to avoid drawing accidentally, the tool is "active" only when the corresponding layer is selected and the configuration dialog is opened.

If you feel brave and want to test the new tool, you'll need to update the source code from GitHub and compile it. Any feedback will be really appreciated!

Friday, November 14, 2014

High-iso noise reduction with PhotoFlow and G'MIC (part 1)

Now that several G'MIC noise reduction filters are available in PhotoFlow, I've started experimenting with them to see how they work on typical high-iso RAW images. This post will show a first attempt, using either Iain's noise reduction filter or a custom combination of Iain, Garagecoder's despeckle and guided blur filters.
There will be most likely more posts to come in the future on this subject...

Noise reduction is always a trade-off between preservation of details and removal of luminance and color artifacts. You should not expect noise reduction tools to do miracles: they will not create details that are lost due to noise, and if you ask them to remove noise completely they will also remove a lot of important details... Hence, fine-tuning and personal taste are the keys.
My personal goal is to transform the initial digital noise into a more "grainy" and "good looking" (maybe even "artistic") noise, such that it does not disturb the eye.

For this tutorial I will use a  3200-ISO 6400-ISO image from a Nikon D300 DSLR camera. The original NEF file is available from this link.
If you would like to play with the settings of my custom noise reduction, you can get the corresponding preset from here. The preset can be applied to any image, with the only limitation that the input image should be in RGB colorspace.
As usual, this tutorial requires a very recent version of PhotoFlow. You can either download and compile the sources from GitHub or get the updated windows installer from here.

The result of the recipy described in this post is shown below (mouse over to see the final result), and the rest of the post will describe how I got there...


Choice of demosaicing method

The first important choice comes even before applying noise reduction methods, and involves the demosaicing of the RAW image. PhotoFlow provides two different demosaicing methods:

  • Amaze, which is designed to maximize the level of details that is extracted from the Bayer pattern; it works very well on low-noise images, but we will see how it can introduce artifacts in noisy ones.
  • IGV, which produces softer results than Amaze which are however very "clean" when noise is present.
Below you can see a comparison between the two methods (mouse over to see the Amaze result). I have disabled on purpose the false color suppression inside the RAW developer module, as I want to address the noise reduction problem entirely with G'MIC.



Iain's Noise Reduction


G'MIC provides a powerful noise reduction filter (called "Iain's Noise Reduction"), now included in the set of filters imported into PhotoFlow, which I will use as a term for comparison for my own experimentation.

Let's then see what Iain's noise reduction filter is able to do on this image. The filter parameters that I've used are shown in the screenshot on the right. I've left the chroma NR to the default value of 3, and reduced the luma NR to 1 to avoid loosing too much high-frequency details. I've also disabled the details recovery step, as it makes the filter VERY slow.

The result of applying those settings to the IGV image is shown below (mouse over to see original).


Custom noise reduction

Having Iain's reference in mind, I've tried to see if I was able to get something different (and maybe better) using other noise reduction filters form G'MIC.

As a starting point, I'll use Iain filter for chroma NR (setting the luma NR slider to 0) and use two additional filters for luma NR:
  • Garagecoder's "Despeckle" filter for salt&pepper noise reduction
  • "Guided blur" filter for additional luma NR
In order to efficiently target luma noise only, I've converted the result of Iain's chroma NR to Lab colorspace, and then I've applied the "despeckle" and "guided blur" filters to the "L" channel only.
This time I'll not go through all the steps of the procedure, assuming that you already know how to add layers and layer groups in PhotoFlow (if not, I suggest you to have a look at some of the past tutorials), and I'll concentrate on the results of the intermediate steps. As mentioned at the beginning of the post, you can get the corresponding preset from here to see how layers are configured and grouped.

First of all, let's see how the "despeckle" filter works. Below you can see the result of applying this filter with "tolerance=20" and "max_area=10". I've found that lower tolerance values or larger max_area values tend to introduce artifacts in in small-scale details. Mouse over to see the result of the chroma NR only.

Next, I've applied the "guided blur" filter on top of "despeckle", with "radius=5" and "smoothness=100". Larger values of the radius tend to increase the noise near high-contrast edges, while lower values tend to increase the overall noise. The "smoothness" parameter can be pushed up to obtain a smoother picture that still preserves good detail.
The images below show the final results (mouse over to see image after despeckle) for the IGV (top) and Amaze (bottom) demosaicing. One can clearly see that Amaze introduces more artifacts that are difficult to remove by the NR.




Finally, I show for reference the result one gets with the IGV image when setting "smoothness=200" in the guided blur filter (mouse over to see "smoothness=100" version).

As one can see, fine details are still quite well preserved. Moreover, one can reduce a bit the opacity of the "guided blur" filter in order to restore a bit of noise texture, so that the image looks more "natural".

I hope you will find this first introduction to noise reduction with G'MIC useful. And if you find mistakes or have suggestions to improve the results, just leave a comment and I'll be more than happy to update the post with new material!

Wednesday, November 5, 2014

Patrick David film presets included in PhotoFlow

Now that the G'MIC interface has been integrated into PhotoFlow, adding specific G'MIC filters is quite easy, sometimes even straightforward...

After having added several smooth filters for noise reduction, I decided to give Patrick David's film emulation presets a try... and the results are really nice!

The different presets are now integrated into PhotoFlow as any other non-destructive filter, meaning that you can change presets or tweak parameters and see the result on-the-fly. There are some performance and gui improvements still possible, but the overall usability is I think already quite ok.

In order to use the film presets, you need first of all to download and install the color lookup tables: first you have to get the zip file from here, and then you have to unpack it into the right directory on you disk, which is

    $HOME/.gmic_film_presets/

in the Linux case and

    %APPDATA/

for Windows.


Once the presets are installed and you have downloaded and compiled a fresh version of photoflow, you can apply them as any other tool:

  1. click on the "+" button to add a new layer
  2. activate the "G'MIC" tab and scroll down to the film presets category you want to use
  3. click "OK" to add the layer and open the corresponding configuration dialog
The steps are summarized in this screenshot:


Once the layer configuration dialog is opened, you will be able to switch between presets and change parameters like opacity, contrast, hue, etc... Your changes will be immediately shown in the preview window (see below).



The controls in the configuration dialog are still a bit ugly and would require some clen-up and rearrangement, but the basic functionality is there.

For the moment the film presets are only available from the git develop branch compiled from source. An updated windows executable is in preparation...