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

Tuesday, February 17, 2015

Edge sharpening with G'MIC "Gradient norm" and "Richardson-Lucy de-convolution" filters

Recently I've added two more G'MIC filters into PhotoFlow:

  1. The "Gradient norm" filter, which allows to identify the edges in an image and to create a convenient grayscale edge mask
  2. The "Richardson-Lucy de-convolution" filter for image sharpening, which generally yields better results than the standard Unsharp Mask technique
Combining both of them, it is possible to create a filter that selectively sharpens the image portions that are already "quite sharp", and leave untouched other smooth regions (like an out-of-focus background). The main interest of doing that is to avoid sharpening the noise in smooth areas. One can usually also increase the sharpening strength, because the effect is restricted by the edges mask. Moreover, the technique is not limited to the RL de-convolution filter, since the edge mask can be applied to any kind of sharpening tool. In PhotoFlow, you can currently choose between UnSharp Mask (USM) and RL de-convolution.

Below you can see the result of the edge masking filter, compared with the original image and a classic sharpening. For comparison, I've also added the output of edge-masked USM from PhotoFlow and RawTherapee, so that you can better compare the quality of the result with other existing open-source alternatives (it seems that there is no edge-masked sharpening available in Darktable for the moment).


Click type to see: Original - RL deconvolution sharpening - RL deconvolution edges sharpening - USM edges sharpening - USM edges sharpening (RawTherapee) - Edges mask

In this post I will not go into all details of how to create an edge-masked sharpening filter in PhotoFlow. Instead, I am providing a preset that automates the whole procedure, and I will only describe the few adjustment layers that have an impact on the output result (most of the layers in the preset are just buffers and copy operations). The screenshot below shows the preset in action, with some annotations that point to the relevant layers. The preset can be directly downloaded from here.


As you can see, the preset allows to directly visualize the edge mask being applied: for that, one has to select the "gradient norm" layer and activate the "show active layer" radio button below the preview area. Two parameters in the "Gradient norm" tool mainly control the generated mask: the "Threshold" value determines how much sharpening is applied in smooth areas, while the "Multiplier" value controls the amount of mask pixels that are purely white.

The "sharpening" layer lets you define the sharpening method (currently the standard Unsharp Maks and G'MIC "Richardson-Lucy de-convolution" are implemented) and its strength.

Finally, The "Halo control" group allows to optionally adjust the strength of the dark and light sharpening halos separately. I personally find that reducing the opacity of the light halos to 50% gives slightly better results.

The advantage of this approach is that the edge mask can be directly applied to any additional sharpening method that might be added in the future, and vice-versa new edge detection methods could be used to mask any of the existing sharpening filters.

Saturday, February 14, 2015

"Autumn at the National Rhododendron Gardens" edit - Part 2: more sky editing

In this second part of the step-by-step description of my final edit of the image in this google+ post of the "Open Source Edit my RAW" discussion group, I want to introduce another simple yet powerful technique for enhancing the sky in landscape pictures.

The technique consists in blending the "b" Lab channel with the original image in "Overlay" mode. Below you can see a comparison between the original image, the result of the previous step, the result of the "b" channel blend and the "b" channel itself.



Click type to see: Original - Step 1 result - "b" channel Overlay result - "b" channel

In the "b" channel, anything that contains some blue is below 50% and gets darkened in the overlay blend, while "yellowish" areas (including leaves and grass) are above 50% and result in lighter tones after blending. In order to keep the lightness of the tree and grass close to the original, I've added a slightly darkening tone curve to the Overlay blending input. The tone curve, as well as the settings for the "b" channel blend, can be seen in the screenshot below.



The nice thing with this technique and the one described in the previous post, is that the result is achieved using only the image data itself, without any masking. The effect is therefore very "natural", without any presence of disturbing halos in the transition areas.

In order to simplify the application of this steps, I've prepared a preset that automatically adds a group layer containing both the red channel blend and the "b" channel overlay. The preset can be downloaded from here. 
The technique turns out to be also quite powerful for haze removal. Below I have applied the preset to the RAW image shared in this google+ post (mouse over to see original image):


Saturday, February 7, 2015

"Autumn at the National Rhododendron Gardens" edit - Part 1: the sky

This post describes step-by-step how I've obtained the final edit of the image in this google+ post of the "Open Source Edit my RAW" discussion group. You can see the final result here.

When editing this picture I had few guiding ideas in mind:

  • the sky was too bright, and I wanted to obtain a more saturated blu tint as well as more contrast and "texture" in the clouds
  • the tree in the foreground is the main element of the composition, so I wanted to give it some "pop"
  • the scene gave me a "late afternoon" feeling, so I wanted to add some overall warm tone

The starting point is the original RAW image, processed using the in-camera settings and the standard Adobe color matrices (for a detailed tutorial on how to open and process a RAW image, see here).

Let's see my editing step-by-step, starting from the sky and clouds. Actually, the techniques described in this and the next posts are not really peculiar to PhotoFlow, and most likely can be applied with minor modifications in other image editors.

Part 1: sky editing

In oder to darken the sky and clouds, I will use a rather common but very powerfull technique, which consists in replacing the luminosity channel of the original image with its own RED channel, and then blend the result back with the original image in "Darken" mode.

The screenshots below shows how this can be achieved in PhotoFlow.





Here are the detailed steps that I've followed:
  1. Add a group layer (I've called it "Sky edit") above the developed RAW image (new groups can be created by clicking on the "G+" button).
  2. Add a "clone" layer inside the group: for that, you have to select the empty row below the group name, than click on the "+" button to open the tool chooser dialog, and then select the "Clone layer" row in the "Misc" tab before clicking the "OK" button to close the dialog.
  3. In the "clone layer" configuration dialog that will pop up, you have to choose the layer corresponding to the initial image (in my vcase "RAW developer") for the layer name, and the "R" channel for the source. The image is graysacle at this point, since we only cloned one channel. To "restore" the colors, set the  blend mode to "Luminosity".
  4. You will notice at this point that the sky got quite darker, but the reddish leaves in the trees became very bright. What we would like is to keep what is darker in this R channel blend, and preserve everything else from the original image... to achieve this, you have to change the blend mode of the "Sky edit" group from "Normal" to "Darken"


There it is! The sky has now a deeper blue and more contrast in the clouds, all that without any masking and unwanted halos around the transition regions. Click on the caption elements to see the original image, the red channel, and the luminosity blend before the final "Darken" blend.



Click type to see: Original - Red channel - R channel Luminosity blend - Final result
  
The next part will show how the contrast in the foreground tree has been improved through a mid-tones liminosity mask associated to a curves adjustment.

Tuesday, January 27, 2015

Basic batch processing with PhotoFlow

The development branch of PhotoFlow now provides a new command that allows some basic batch processing. The batch processor is called pfbatch and gets installed in the same directory as the interactive photoflow command.

The general syntax of the pfbatch command is the following:

    pfbatch input_file [preset_1]...[preset_n] output_file

and can be used to perform different kind of tasks:
  • export an existing PFI file to TIFF or JPeg, optionally applying additional presets (I'll come back to that later in this post)
  • load a TIFF or JPeg file and save it as PFI file
  • load a TIFF or JPeg file, apply some presets and export again as  TIFF or JPeg
  • load a PFI file,  append some presets and save again as PFI

To make a concrete example, let's assume you have a certain number of edited images (saved as PFI files), and you want to create down-scaled versions to be posted on the web. You probably also want the web images to be converted to sRGB, just to make sure that they will display at least decently even on browsers that ignore ICC profiles.

The downscaling and sRGB conversions are additional operations that are not contained in the input PFI files, and that have to be applied to each image we are converting. All we need to do is to create a couple of presets for that, and then append them to the input file when calling pfbatch.

In order to create the presets, you first need to open an existing image with photoflow, and then add any layer that you want to save as a preset.

The example below shows how to add a "Scale & rotate" layer to an existing image: we will use this tool to create a preset that scales the image to a size of 800x600 pixels at most (the "Scale & rotate" tool is found under the "geom" tab of the "new layer" dialog).



Now we have to adjust the parameters of the scale tool so that the final image will fit into 800x600 pixels. The scale tool in PhotoFlow works similar to the "-resize" command in ImageMagick: when scaling the image, the tool will preserve its aspect ratio and will make sure that the resulting image fits into the given size. Therefore, we simply need to specify the desired size (in pixels) in the correspoding tool dialog:



At this point, with the "resize" layer still selected, click on the "Save" button below the layers list to save it as a preset (with extension ".pfp"):



In the following I will assume that you have saved this preset as "$HOME/presets/web_resize.pfp".

Now you have to do the same for the sRGB conversion: add one more layer of type "Color profile conversion" (you will find it in the "conv" tab of the "new layer" dialog) and leave the parameters to their defaults. In my case, the layer is simply named "sRGB":



Make sure that only the "sRGB" layer is selected, then click on the "Save" button below the layers list to save it as an additional preset (I'll assume you have called it "$HOME/presets/sRGB.pfp").

You can also save several layers in one single preset, either by selecting them before clicking on the "Save" button, or by inserting them into a group layer and saving the group itself as a preset.

At this point, everything is ready to batch-convert your first image for the web (of course you need to replace the input and output file names with your actual files):

    pfbatch input.pfi $HOME/presets/web_resize.pfp $HOME/presets/sRGB.pfp output_4web.jpg

This command can also be used inside a Makefile. Here is how a generic rule could look like:

    Web/%.jpg: %.pfi
        pfbatch $< $HOME/presets/web_resize.pfp $HOME/presets/sRGB.pfp $@

 This will run through all the *.pfi files in the current directory and save the resulting resized JPeg files in the "Web" subdirectory.

For the future I am planning to make the batch processing tool more intuitive and user-friendly, and add some GUI interface to it. However, the pfbatch commmand will most likely remain there as the basic building block for everything else...

Monday, January 12, 2015

Experimental LensFun support added into PhotoFlow

An initial implementation of LensFun support has been added into PhotoFlow.

The tool is still experimental, and limited in functionality:
  • the camera and lens information can only be extracted from the EXIF metadata, and not specified by hand
  • only distorsion and TCA corrections are implemented for the moment, the vignetting is still missing
  • there is no possibility yet to select the corrections to be applied
  • the interpolation is performed using a simple nearest neighbour method, to be replaced with a better interpolator in future


Nevertheless, if you are interested in this feature and you want to help me in the testing and debugging process, the tool can be accessed from the "Geometry" tab of the tool selector. The tool is called "Optical corrections":


Here is how the tool dialog looks like:


The LensFun tool is for the moment only available from the GitHub sources.
Two additional dependencies are needed to compile PhotoFlow: exiv2 and LensFun.

As any other experimental code, it still contains bugs and is likely to produce frequent crashes, therefore I recommend to frequently save your work while testing it.

Monday, January 5, 2015

Photoflow update: crop tool, foreground extraction and layer shifting

Interactive crop tool

PhotoFlow has finally some decent crop tool. It is now possible to define the crop area interactively with the mouse, or directly by the numbers. The cropped area can be resized by dragging the right or bottom edges, or the bottom-right corner. It can also be moved by dragging anywhere inside the area itself.

An example of the crop tool in action is shown below.



Foreground extraction tool (G'MIC)

The foreground extraction tool now works as a "mask generator": the output of the tool is a black & white image that represents the foreground mask, and that can be used as a layer mask for better flexibility.
The foreground points (green ones) are added with the left mouse click, while the background points (red ones) are added with the right click. To remove some point, one has to click on it with the middle mouse button.

I'm preparing a detailed step-by-step tutorial on the subject, to show how the foreground mask can be used and further edited.

Below one can see the tool in action (top screenshot is the original image with the control points, bottom screenshot is the generated mask).




Blending images of different size and layer shifting

It is now possible to blend images with different sizes, as well as shift one image with respect to another one. Two additional controls have appeared in the layer configuration dialogs, allowing to define the horizontal and vertical layer shifts. Any opacity mask associated with the shifted layer also gets shifted automatically.

Below one can see the rose blended on top of another image, using the foreground extraction mask in the blending process.



Monday, December 22, 2014

The alien grasshopper - Complex layer masking using channel data

In this tutorial I will show how to create a layer mask based on the image data itself, and how to select given portions of an image seamlessly and with little effort.

To illustrate this technique, I will take as example the grasshopper image that I posted around some time ago, and show how I isolated this nice insect from the flower and the rest of the background. To show the technique more clearly, in this post I will turn the grasshopper into an alien insect by applying a selective hue shift, like you see below:



Isolating the insect manually, either by drawing with a brush or by using a freehand selection tool, would be very time consuming and boring, and probably not as precise as the technique shown here.
Instead, I will show you here how you can use the image data itself to create a convenient grasshopper mask, all that in few mouse clicks. The idea is to find image channels in which the grasshopper is well separated from the flower, and then add a curves adjustment to the channel data so that the grasshopper appears completely white and the flower completely black in the final mask (with some smooth variation in the transition regions). The first step is to identify which channels are more promising. You can choose between the individual Red, Green and Blue channels of the RGB colorspace and the L, a and b channels of the Lab colorspace.

The grasshopper differs a lot from the flower in terms of color, but not too much in terms of luminosity, therefore we can already guess that the "L" channel will not be very useful... the other channels are all potentially promising, and we need to look at them directly to see which are best.

To visualize the individual channels, do the following: create a "Clone" layer (which I called "channel selector", select the layer you want to inspect, and choose the channel from the corresponding drop-down list. The individual channels of the grasshopper image are shown below (move the mouse over the caption items to see the corresponding image). The contrast of the "a" and "b" channels has been increased to better see the tonal variations.


Click type to see: Red - Green - Blue - Lab "a" - Lab "b"


As expected, the "a" and "b" channels look the most promising ones... Not surprising, since the grasshopper is searated from the flower mostly in terms of color. The "a" and "b" channels might be difficult to interpret if you are not familiar with the Lab colorspace, so I'll spend a few words to explain why they look like that.
The "a" and "b" channels encode the color information of the image, independently of the luminosity, in a quite peculiar way: a neutral grey corresponds to "a=50%, b=50%", while values above and below 50% encode complementary colors. For example, "a<50%" corresponds to green and "a>50%" to magenta, while "b<50%" corresponds to blue and "b>50%" to yellow. The higher the distance from 50%, the higher is the saturation of the corresponding color component.

With that in mind, we can already expect that the flower and the grasshopper will have quite different values in the "a" channel (the grasshopper is greenish and therefore "a<50%", while the flower is pinkish and so we can expect that "a>50%"). The "b" channel is less obvious (the grasshopper is certainly yellowish with "b>50%", but the b values in the flower are not so evident...) but a direct look to it shows that there is a quite strong separation between grasshopper and flower in this channel as well.

For this image I ended up using a combination of the "a"and "b" channels to isolate the grasshopper, and the Red channel to mask the out-of-focus background.

Now that the masking strategy is ready, I made the "channel selector" layer invisible (but kept it there in case I wanted to inspect again the individual channels later on). Invisible layers do not consume any memory and are simply skipped by the processing pipeline, so you can have as many as you like without any negative impact on the processing performance...
I added a "Hue/Saturation" adjustment layer on top of the invisible channel selector. I will change the Hue of the layer until the green color of the insect will turn into electric blue, but first I will work on the layer mask to isolate the grasshopper from the rest. For that, I double-clicked on the icon corresponding to the "opacity mask" (the one at the extreme right right of the layer row) to open the layer stack of the mask itself (initially empty).
First, I added a new layer group (I've called it "a channel mask") and then added a "Clone" layer inside this group. I selected the "a" channel of the background layer as source, and clicked on the "show active layer" button below the preview window to activate the visualization of the mask itself. The preview window now looks like this:


Next, I've added a "Curves" layer on top of the "a" clone and applied a "threshold-like" curve that turns the mask into pure white above the grasshopper, and pure black above the flower (with some smooth transitions).
Here is how I did it:


I repeated then the above steps for the "b" channel (created a group, inserted a clone layer into the group and then a "Curves" adjustment on top of the cloned channel), obtaining this result:


The two masks look similar, but not identical... actually, the best would be a combination of the two. Combining the two masks is quite easy: I simply changed the blending mode of the top group (with the "b" channel mask) to "Lighten" mode, to obtain this:


At this point, the masking of the grasshopper looks quite ok (we could remove a bit of remaining red areas by hand), but I still need to isolate the out-of-focus background. For that, the "Red" channel looked like the most appropriate. The technique is always the same: I added a layer group, inserted a clone layer inside the group and a curves adjustment on top of it. I ended up with this red channel edit:


The red channel mask needs now to be combined with the "a+b" one: for that, I have applied a slight blur (5 pixels of radius) and then changed the blending mode the the red channel group to "Darken", to obtain an almost final result:


There are still a couple of unmasked spots in the background, but those are easily corrected by drawing directly on the mask with a large black pencil. Therefore, my last masking step is to add a "Draw" layer on top of the "red channel mask" group, set the background color to white and the pen color to black, and change the blending mode of the "Draw" layer to "Darken". Now I could draw with a large pencil (I've set the size to 100 pixels) to completely remove the unmasked regions. The final result looks like this:


As you can see, I've ended up with a quite complex mask edit. However, I can guarantee that the procedure is much longer to describe than to realize. With a little practice, it is easy to identify the channels that are likely to be good for masking, and the technique is rather simple: create a group, clone a channel inside the group, and add a threshold-like curve adjustment to create the mask.

The nice thing is that all steps in the mask creation are non-destructive, and you can go back and tweak any setting whenever you like, even after saving and reopening the file later on.
Moreover, despite the relatively large number of layers and blendings, the mask is computed quite fast and does not slow down significantly the preview of the edited result.

Finally, it's time to turn the color of the grasshopper into electric blue. First I switched back to the main "Layers" panel to edited the "Hue/Saturation" adjustment. I double-clicked on the corresponding layer name to open the configuration dialog, and shifted the hue by 150 degrees in the positive direction... and there it is, a weird alien has taken the place of the nice insect!



Of course, the same technique can be applied to more "traditional" edits... I've used the same mask to increase a bit the contrast and give some more "pop" to the grasshopper. That's the final result (mouse over to see original):