It is quite fast too. With a 2048x1356 main image and 216x216 shape (inset top left), it took 2.3 seconds on my PC (here reduced to 600x400):
Looking forward to see if there’s any tweaks or improvent that can be made to this script.
Notes:
Thanks due to Fred’s ImageMagick Scripts (https://www.fmwconcepts.com/imagemagick/bokeh). I tried to convert the script, but couldn’t do it on my Windows PC without compiling IM with FFTW. Then tried so many blending methods in GIMP using Fourier Transfrom in G’MIC Plugin, but it of course works in a different domain, plus there is no way to multiply layers as complex numbers. Almost went to Python. However, I tried with gmic_cli, and here it is. This does mean the command above could be scripted into a filter.
Other bokeh methods: Bokeh in G’MIC Plugin, but it is at random locations, not centered on the highlights. GIMP’s Lens Blur is quite good, but you can only get circular highlights.
Images from Wikimedia Commons: Christmas_lights_Franklin_Avenue_Millbrook,_NY.JPG and City_Lights_(248468305).jpeg.
Still needs an initial contrast, a resize if the shape is a different dimension, then gamma after fft, normalization (before blending), and blur+blend to get a photographic look.
One tweak: Should you want to do the “Fake depth of field” within gmic, without resorting to an external paint program, then Jerome Boulanger’s mapblur is your friend. It adjusts blurring dynamically in a particular image locale by way of a mask. Its two immediate predecessor images are (1) the image to be blurred, with all other effects already applied, and (2) the blurring mask. The blurring mask is a gray scale, (one channel) image that has the same width and height as the target image. In this mask, black suppresses all blurring, white permits maximum blurring. blurmask sets up a Gaussian blur style mask. This can be replace by any other generator that makes some arbitrary shaped region.