create a 'glare' effect over the brightest 1% of pixels
create a 'glare' effect over the brightest 1% of pixels
Hello!
New to imagemagick so please forgive me if this is a very basic question.
I'm hoping to create a glare effect over the brightest pixels in a photo, as in the photo below.
I could see two potential ways of doing it: creating a threshold mask and using morphology to make a diamond/plus shape & overlay that. Or, find the x/y coordinates of the white pixels in the mask, and overlay a pre-made semi translucent .png of the glare image at those coordinates.
Problem is, I don't really know how to do either of those things.
Any and all suggestions appreciated!
New to imagemagick so please forgive me if this is a very basic question.
I'm hoping to create a glare effect over the brightest pixels in a photo, as in the photo below.
I could see two potential ways of doing it: creating a threshold mask and using morphology to make a diamond/plus shape & overlay that. Or, find the x/y coordinates of the white pixels in the mask, and overlay a pre-made semi translucent .png of the glare image at those coordinates.
Problem is, I don't really know how to do either of those things.
Any and all suggestions appreciated!
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a 'glare' effect over the brightest 1% of pixels
Please always provide your ImageMagick version and platform/OS, as syntax may vary.
Can you post and example input image and corresponding output image. At least post an input image that is appropriate for us to use.
Can you post and example input image and corresponding output image. At least post an input image that is appropriate for us to use.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: create a 'glare' effect over the brightest 1% of pixels
I show a method for making starbursts at Polar distortions: Stars. You could make some at different sizes, and place them according to brightness levels in the input image.
A simpler method might use comet blurs. Simplify your input to just points of light where you want the stars. Comet-blur that, and "-compose Lighten -composite" with your input.
A simpler method might use comet blurs. Simplify your input to just points of light where you want the stars. Comet-blur that, and "-compose Lighten -composite" with your input.
snibgo's IM pages: im.snibgo.com
Re: create a 'glare' effect over the brightest 1% of pixels
@fmw42:
imagemagick version 6.9.3-6 Q16 x86_64. I'm running mac OS 10.12.6.
Here's an example input. I'm hoping to increase the amount of sparkles/flares in the output. I need it to be an automated process as it's going to be part of a photo shoot series.
imagemagick version 6.9.3-6 Q16 x86_64. I'm running mac OS 10.12.6.
Here's an example input. I'm hoping to increase the amount of sparkles/flares in the output. I need it to be an automated process as it's going to be part of a photo shoot series.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a 'glare' effect over the brightest 1% of pixels
Here are a couple of outputs. I started with snibgo's idea of making a diagonal flare image. The code is in Unix syntax.
Input:
Here I threshold the image to get the brightest 1% but remove thicker spots:
Here I draw the diagonal lines and blur them
Here I use snibgo's method of adding the gradients to the lines
Here I have to use HDRI, so I use IM 7 which includes it. You could do it all in IM 7 or with a build of IM 6 with HDRI. The step does a convolution of the star pattern above with the tmp1 top 1% bright image in the Fourier domain. A limitation of ImageMagick here is that both images must be padded with black to the same square and even dimension. The padded out star image must them be rolled so that what was in the center is at the top left corner.
Here I try one method of composing the result onto the original. I use -evaluate log for gain. One could also use -evaluate pow in stead.
Here I try another method of composing.
P.S. If one uses polar -1 and depolar -1, you will get the star pattern to fill out the image, so the stars will match the size of the initial lines.
Input:
Here I threshold the image to get the brightest 1% but remove thicker spots:
Code: Select all
convert sparkle.jpg -negate -threshold 1% -negate -morphology open diamond:2 -type bilevel tmp1.png
Here I draw the diagonal lines and blur them
Code: Select all
convert \
-size 140x140 xc:black \
-fill white \
-draw "line 0,0 139,139 line 0,139 139,0" -alpha off \
-virtual-pixel black \
-blur 0x3 \
tmp2.png
Here I use snibgo's method of adding the gradients to the lines
Code: Select all
convert \
tmp2.png \
-virtual-pixel Edge \
-distort depolar 0 \
-distort SRT 0,-5,1,0,0,0 \
-auto-level \
-level 5%,50% \
\( +clone -sparse-color bilinear "0,0,White 0,%[fx:h-1],Black" \) \
-compose Multiply -composite \
-distort polar 0 \
tmp3.png
Here I have to use HDRI, so I use IM 7 which includes it. You could do it all in IM 7 or with a build of IM 6 with HDRI. The step does a convolution of the star pattern above with the tmp1 top 1% bright image in the Fourier domain. A limitation of ImageMagick here is that both images must be padded with black to the same square and even dimension. The padded out star image must them be rolled so that what was in the center is at the top left corner.
Code: Select all
magick \
\( tmp1.png +fft -background black -gravity center -extent 2736x2736 \) \
\( tmp3.png -background black -gravity center -extent 2736x2736 -roll -1369-1369 +fft \) \
-complex multiply +ift \
-auto-level -gravity northwest -crop 2736x1824+0+0 +repage tmp4.png
Here I try one method of composing the result onto the original. I use -evaluate log for gain. One could also use -evaluate pow in stead.
Code: Select all
convert sparkle.jpg \( tmp4.png -evaluate log 100 \) -compose lighten -composite sparkle_result2.png
Here I try another method of composing.
Code: Select all
convert sparkle.jpg \( +clone -fill white -colorize 100 \) \( tmp4.png -evaluate log 100 \) -compose lighten -composite sparkle_result1.png
P.S. If one uses polar -1 and depolar -1, you will get the star pattern to fill out the image, so the stars will match the size of the initial lines.
Code: Select all
convert \
tmp2.png \
-virtual-pixel Edge \
-distort depolar -1 \
-distort SRT 0,-5,1,0,0,0 \
-auto-level \
-level 5%,50% \
\( +clone -sparse-color bilinear "0,0,White 0,%[fx:h-1],Black" \) \
-compose Multiply -composite \
-distort polar -1 \
tmp3b.png
Re: create a 'glare' effect over the brightest 1% of pixels
This is a huge help! Thank you so much. You guys are real wizards with all this. Bravo!
Re: create a 'glare' effect over the brightest 1% of pixels
Having trouble getting this part to work on mac, using ImageMagick 7.0.7-22 Q16 x86_64. Getting the following error:fmw42 wrote: ↑2018-02-02T19:23:24-07:00
Here I have to use HDRI, so I use IM 7 which includes it. You could do it all in IM 7 or with a build of IM 6 with HDRI. The step does a convolution of the star pattern above with the tmp1 top 1% bright image in the Fourier domain. A limitation of ImageMagick here is that both images must be padded with black to the same square and even dimension. The padded out star image must them be rolled so that what was in the center is at the top left corner.Code: Select all
magick \ \( tmp1.png +fft -background black -gravity center -extent 2736x2736 \) \ \( tmp3.png -background black -gravity center -extent 2736x2736 -roll -1369-1369 +fft \) \ -complex multiply +ift \ -auto-level -gravity northwest -crop 2736x1824+0+0 +repage tmp4.png
magick: delegate library support not built-in `threshold.png' (FFTW) @ warning/fourier.c/ForwardFourierTransformImage/898.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: create a 'glare' effect over the brightest 1% of pixels
Looks like you need to install the FFTW delegate library. See https://www.imagemagick.org/script/comm ... ns.php#fft
What do you get from
On my Mac I have the following delegates installed via MacPorts, but install IM from source.
Version: ImageMagick 7.0.7-22 Q16 x86_64 2018-01-22 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib
Does it list fftw? If not then you need to install that delegate library. How did you install ImageMagick? MacPorts or Homebrew or from ImageMagick directly. If MacPorts or Homebrew, then you will need to install the delegate linked to ImageMagick or reinstall Imagmagick with the delegate? If from ImageMagick source, then see http://www.fftw.org
If you are using IM 7, then change all my convert commands to magick rather than convert.
What do you get from
Code: Select all
magick -version
Version: ImageMagick 7.0.7-22 Q16 x86_64 2018-01-22 http://www.imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP
Delegates (built-in): bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib
Does it list fftw? If not then you need to install that delegate library. How did you install ImageMagick? MacPorts or Homebrew or from ImageMagick directly. If MacPorts or Homebrew, then you will need to install the delegate linked to ImageMagick or reinstall Imagmagick with the delegate? If from ImageMagick source, then see http://www.fftw.org
If you are using IM 7, then change all my convert commands to magick rather than convert.
Re: create a 'glare' effect over the brightest 1% of pixels
Yep, the fftw library was missing. Got it installed, now everything's working perfectly, thanks again for all the help.