Difficulty with Blurs and Masks

Hi,

I’m having some issues applying a small “natural” looking blur to the background of this image, using the Blurs module.

I’ve used a drawn mask. Other people in the picture (not shown in attached example) have colours that are similar to the background, which has ruled me out from using a parametric mask. It might be possible, but not yet for me.

I’ve read in other posts different limitations with the Blurs module, so if there’s a better module for me to be using, please let me know. For me, it is giving the nicest blur effect. Remember, I want to keep it natural, so I’m only looking for a slight blur to add some separation between the subjects and the background.

Sorry, I’m not able to attach the RAW image to the post, because I would like to keep my family and friends off the internet, at least in family shots anyway. (We’re all out there somewhere!)
I have looked through the PlayRAW section in an attempt to find a similar situation and there’s not too many images that I could find with people or subjects in front of busy backgrounds. The best I could find was: Two Taiwanese uncles playing chess

In the attached jpg, I’ve pointed to 2 areas where I am having the opposite problem.

On the ears, I have pulled the mask back away from the edge and have let the feathering go up to the edge. This blurs the edge of the ears, along with the background, which isn’t what I want.
(There is also a small gap I missed at the base of the left ear, where the background isn’t blurred. See my next try for more on that.)

On the arm and shoulder, the edge of the mask is almost to the edge of the subject. This shows a noticeable halo to me, which again, isn’t what I want.

I have been able to succeed using drawn masks with colour and exposure adjustments to nicely separate the subject and background, but using a mask and a blur seems to leave obvious artefacts, to me at least.

Feel free to point me to any tutorials or previous posts that would help me out.

Thank you in advance for your help,
GJ

try using the Feathering radius on your mask.

Try tweaking these

rather than trying to use the drawn mask object “feather” ie the dotted graduated boundry.

Contrast and feather can often really clean up the mask

You could refine the mask based on detail levels. The subject is generally sharp, the background blurred. See details threshold: darktable user manual - mask refinement & additional controls

I’ve had good luck using the bloom preset of diffuse or sharpen, for example see here:

In my view and experience what you are wanting to do is incredibly difficult because it is nearly impossible to avoid halos. However, the bloom option preset of diffuse or sharpen module would be my go to in Darktable. However, this sort of work I am more likely to use a layers and masking techniques in GIMP

  1. Open up the image of the people in GIMP and create a duplicate layer

    1. Go to Filters > Blur > Lens Blur and adjust the radius to get the desired amount of blur for the background. I often use Gaussian Blur but some pictures may benefit using motion blur to imply motion instead of Gaussian blur. Others may benefit from Circular, Linear or Zoom motion blur instead of the lens blur filter.
    2. Activate the second layer, move it to the top of the stack and add a white layer mask and ensure the invert mask box is not selected.
    3. You then need to use a paint brush with a 50% hardness and black paint to paint in the areas you want blurred. If you make a mistake then switch the paint to white and erase that area of the mask.

With lots of patience this can be achieved in GIMP and would suspect a lot easier than in DT. This would also be one of those cases that AI might have the edge, but that option is not available in DT or GIMP.

Thank you for the replies.

I’ll start at the top of the replies and work down through the suggestions until I can get a result that I’m happy with. Hopefully I can start this later this afternoon.

Some questions when I create the drawn mask:

  • When I draw the mask, should I try and get as close to the edge of the subject as possible, or should I go outside of the subject, or should I draw inside of the subject?
  • Before working on the “Mask Refinement” as suggested, should I pull back the dotted line feathering to the drawn mask (solid line), or leave it as is?

I’m sure there is going to be a depends in some of the answers. :slight_smile:

Thanks,
GJ

It’s a dance…I think inside a bit is better….

Contrast with tighten or relax the mask a bit wrt the edges if you raise/lower it…

The feather will adjust the edge awareness and the opacity can push or pull back the mask at the edges depending on the slider setting as well so you just need to experiment a little and see which combination gives you the best result…if you make the edge too harsh it will show so don’t try to make it absolutely hard edged….

Then in some cases you can combine a parametric one to help but likely not here in your case with that sample photo…

I would suggest visualising the mask after drawing it to understand what you have created. For instance I usually have keep the dot line very narrow and use the feather slider to soften the gradient. The feather created by the dotted line and the feather created by the slider are very different.


The feather created by the dotted line is like a gradient from the solid line to the dotted line.


In comparison the feather created by the slider works equally on both sides of the solid line.

I’ve made some progress with your suggestions.

I had to reduce the mask opacity from -100% to -85% before I saw any effects though.

The higher contrast areas need a bit more physical refinement of the mask, than the lower contrast areas. eg. white shirt on dark background VS dark hair on dark background. The mask needs to be more “accurate” in these areas to avoid artefacts.

Thanks, I’ll keep working on it and will ask if I have any more questions.

GJ

The blur module is very useful to render a realistic focus blur, the problem comes when using large blur radii and because of how the masking works in darktable.

In this picture, I’ve drawn a mask which is a perfect circle which does not touch the light green moss on the right, and applied a 64px wide blur. It shows a light green halo corresponding to the moss.

This is because the masking is not a constraint on the input pixels but on the output pixels. I don’t know if it would be feasible to design a blur module which would generate the blur from only the input pixels.

An alternative could be the retouch module using the blur mode

I see what you mean, however when I first tried it on one of my own images, I put the circle on a light area and I could not see a halo from a nearby dark area. I then moved the circle to a dark area and just as you pointed out, the halo from a nearby light area became apparent.

Fortunately, in the image that I originally posted about, I am only using a small Blur Radius of 8px, which seems to be avoiding most of the demonstrated issue.
I originally selected this small blur radius, because I wanted to keep the blur more natural, to my eye at least.

(For reference, I took the picture at 20mm f5.6, with an m43 camera, which would be equivalent to 40mm f11 full frame. If I was thinking, I probably could have used f4.0, which could have made things a little easier at this point. Oh well.)

GJ

Could these be used to tweak that result in a positive way…

I don’t think so, because the “feathering guide” setting changes whether the guide is done on the input or output, but not on which pixels the module computations happens. But maybe it still can help mitigate the halo effect.

Unfortunately darktable design seems not suitable for reliable blur masking. The github feature request was closed as too difficult.

This kind of makes sense to me: to place a blur on a pixel, darktable must need to know what the surrounding pixels are first. In the case where there is a pixel that is next door to a masked pixel, it would have less data to blur with and I could see that this could cause artefacts in some cases.

I continued on with my drawn mask and ended up getting a reasonable result. Not great overall, particularly at 100% zoom, but on a phone screen it looks pretty good.

This is the final image (reduced to 33%)

In comparison, this is what the camera gave me:

Lower contrast areas come out better than high contrast areas (shoulder on left vs shoulder on right):

I did find the mask feathering was particularly useful around areas with hair. When there is a hard cut off between the blurred and non-blurred areas, hair looks a bit strange, where as if there is a gradient into the blur, you can see some “fly-aways” which makes the result look more natural.
After I got the basic mask close to what I wanted using the Mask Refinement settings, I then went around and fixed areas that were showing halos and other unwanted artefacts. Generally the (solid) mask line was just inside the edge of the subject. I adjusted the feathering line (dotted) to clean up the final result. In lower contrast areas the dotted line was further away from the solid line, but in high contrast, hard edge areas, the 2 lines are quite close. It was tedious, but this softens the edges a little and the kids don’t look like a cardboard cutout on the background: 2D foreground stuck onto a blurred background.

I think I will try editing/processing the image again, using the suggestion of layers in Gimp. I want to see if I can get a result that I am happy with quicker than adjusting every point along the drawn mask.

Thanks,
GJ

I would suggest find a suitable image and offer it as a playraw requesting a blurring of the background.

Not necessarily, as they should be blurred anyway. Even “fake” pixels from the background would be better than pixels from the subject. But darktable applies masking on already blurred image (contaminated) , so the masking module already doesn’t have option to restrict or affect blur based on the source image. E.g. in other editors i saw, probably with different architecture, it doesn’t seems to suffer by this issue.

1 Like

I think darktable blurs the whole image, and then applies a mask to mix the source and the result. It’s just like creating a new layer in Gimp, blurring its contents, and applying a mask.

Yeah, it would be like in bitmap editor. However in bitmap editor you can workaround, do inpaint and blur afterwards, it not an big issue since you can already export the mask from darktable.