Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

VIDEOGLITCH


Applies a video glitch effect to an image.

Download Script

last modified: January 31, 2019



USAGE: videoglitch [-c colors] [-d distance] [-a amplitude ] [-n number] [-t thickness] [-j jaggedness] [-r reseed] infile outfile
USAGE: videoglitch [-h|-help]

-c ... colors ....... colors to use in channel separation; choices are: red-cyan,
..................... green-magenta and blue-yellow; default=red-cyan
-d ... distance ..... separation distance of colors; integer (positive or negative);
..................... default=-5
-a ... amplitude .... amplitude of distortion; integer>=0; default=45
-n ... number ....... number of non-glitch spacer segments; integer>0; default=5
-t ... thickness .... thickness (height) of non-glitch spacer segments; integer>=0;
..................... default=25
-j ... jaggedness ... jaggedness of glitches; integer>0; default=20
-r ... reseed ....... seed value for random number generator used for the glitches;
..................... integer>=0; default=101

PURPOSE: To apply a video glitch effect to an image.

DESCRIPTION: VIDEOGLITCH applies a video glitch effect to an image. The effect is composed of two parts. The first part is to make a horizontal separation between the red and cyan coloring channels. The second part is to add random horizontal offsets. The random offsets are created from a one column random image with height the same as the input image. Then random height constant gray segments are randomly placed over and replacing parts of the random column image. This image is then expanded horizontally to fill the the width of the input image and used as a displacement map applied to the input image.

ARGUMENTS:

-c colors ... COLORS to use in channel separation. The choices are: red-cyan (rc), green-magenta (gm) and blue-yellow (by). The default=red-cyan.

-d distance ... DISTANCE is the separation distance of the red-cyan channels in the output. Values are integers (positive or negative which controls the direction). The default=-5.

-a amplitude ... AMPLITUDE of the horizontal distortion of the glitches. Values are integers>=0. The default=45.

-n number ... NUMBER of non-glitch gray spacer segments in the displacement map. Values are integers>0. The default=5.

-t thickness ... THICKNESS (or height) of the non-glitch spacer segments. Values are integers>=0. The default=25.

-j jaggedness ... JAGGEDNESS of the glitches. Values are integers>0. The default=20.

-r reseed ... RESEED is the initial seed value for the random number generator. Values are integers>=0. Default=101.

NOTE: This script is not designed for images with transparency.

REQUIREMENTS: IM 6.9.9.26 or higher or IM 7.0.7.14 or higher due to the use of -compose stereo.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES


Example 1 -- Variation In Colors

Original Image

Arguments:
-c red-cyan

Arguments:
-c green-magenta

Arguments:
-c blue-yellow



Example 2 -- Variation In Jaggedness

Original Image

Arguments:
-j 2

Arguments:
-j 5

Arguments:
-j 10

Arguments:
-j 20
(default)

Arguments:
-j 30

Arguments:
-j 50

Arguments:
-j 100



What the script does is as follows:

  • Reads the input into MPC format
  • Creates random length lines for constant gray sections to overlay on random column image below
  • Clones the input and applies stereo composition to create the two color offset
  • Create a one column random grayscale noise image
  • Draw the randomly positioned constant gray line section over the one column noise image
  • Scale the one column image down to make less jagged
  • Scale that result back to the size of the input image in both width and height
  • Apply the previous image to the input image as a displacement map
  • Swap color channels as desired for the colors option
  • Save the output

This is equivalent to the following IM commands

  • convert -quiet "$infile" +repage $tmpA1
  • WxH=`convert -ping $tmpA1 -format "%wx%h" info:`
  • wd=`echo $WxH | cut -dx -f1`
  • ht=`echo $WxH | cut -dx -f2`
  • draw_args="line 0,0"
  • for ((i=0; i<number; i++)); do
    y1=`convert xc: -seed $reseed -format "%[fx:round(($i+1)*$ht/$number + (random()>0.5?1:-1)*$ht/(3*$number))]" info:`
    y2=$((y1+$thickness))
    draw_args="$draw_args 0,$y1 line 0,$y2"
    reseed=$((11*reseed+13))
    done
  • draw_args="$draw_args 0,$ht"
  • if [ "$colors" = "red-cyan" ]; then
    cproc=""
    elif [ "$colors" = "green-magenta" ]; then
    cproc="-separate -swap 0,1 -combine"
    elif [ "$colors" = "blue-yellow" ]; then
    cproc="-separate -swap 0,2 -combine"
    fi
  • convert $tmpA1 \( +clone \) -colorspace gray -geometry ${distance}+0 -compose stereo -composite \
    \( -size 1x$ht xc: -seed $reseed +noise random -colorspace gray \
    -fill gray -draw "$draw_args" -alpha off \
    -scale x${jaggedness}% -scale ${wd}X${ht}! \) \
    -define compose:args=${amplitude},0 -compose displace -composite \
    $cproc \
    "$outfile"