Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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

SCATTERCHANNELS


Generates a scatter diagram between channels of an image

Download Script

last modified: April 25, 2015



USAGE: scatterchannels [-c channels] [-f format] [-s scale] [-l] [-t] [-m] infile
USAGE: scatterchannels [-h or -help]

-c .... channels ..... channel pair to process; RG, GB, BR; default=all 3 pairs
-f .... format ....... output format when channels=default (all); format=1 or 3 images;
...................... default=1; output name(s) will be created from the infile
...................... and the channels. The output image will be GIF format
-s .... scale ........ subsampling scale size for input images in both dimensions;
...................... default=50 (pixels)
-l ................... label each axis with a color stripe of the relevant color
...................... when channels is not default (all) or format=3
-t ................... transpose the resulting scatter diagram
-m ................... mirror the resulting scatter diagram vertically

PURPOSE: To generate a scatter diagram between channels of an image.

DESCRIPTION: SCATTERCHANNELS generates a scatter diagram between channels of an images. The 8-bit graylevel values at each corresponding pixel in the two channels are used as the x and y coordinates to plot white points on a 256x256 black background image. By default all 3 pairs of channels will be processed: red vs green, green vs blue and blue vs red. The process is slow and is proportional to the size of the input image. Therefore the image will be scaled down to the desired size in order to keep the processing to a reasonable time, but have an adequate uniform sampling of the data. The resulting graph image may be mirrored vertically so that the x,y origin is at the bottom left, if desired, rather than the default top left.

ARGUMENTS:

-c channels ... CHANNELS are the pair(s) of channels to be made into a a scatter diagram. The choices are: red-green or RG, green-blue or GB, blue-red or BR. The default is all 3 pairs in one image. If the image is CMYK, then RG is equivalent to CM, GB is equivalent to MY and BR is equivalent to YC. By default the first color will be along the x axis and the second color along the y axis.

-f format ... OUTPUT FORMAT when channels=default (all). The format can be either 1 or 3 images. The default is 1. Output name(s) will be created from the infile and the channels. The output image will be GIF format.

-s scale ... SCALE is the resulting subsampled scale size of the input image. The image will be scaled to the desired size in pixels maximum on each side, if the image is larger than this size. The default is 50. Thus for a square image equal to or larger than 50, 50x50=2500 points will be plotted.

-l ... Indicates to label each axis with a color stripe of the relevant color when channels is not default (all) or when format=3. In other words, when separate channel-to-channel scatter images are created.

-t ... Indicates to transpose the resulting scatter diagram, interchanging the x and y axes (colors/channels).

-m ... Indicates to mirror the resulting scatter diagram vertically, so that the x,y origin is at the bottom left rather than the top left.

NOTE: This process is slow and takes about 2 minutes to generate with the default sample size of 50 on my Mac Mini 1.4 GHz G4.

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


One Color Scatter Image

Image

Scatter Diagram
Arguments:
-c all -s 50 -f 1

Image

Scatter Diagram
Arguments:
-c all -s 50 -f 1

Image

Scatter Diagram
Arguments:
-c all -s 50 -f 1

Image

Scatter Diagram
Arguments:
-c all -s 50 -f 1

Image

Scatter Diagram
Arguments:
-c all -s 50 -f 1



Three Grayscale Channel To Channel Scatter Images -- Variation In Orientation

Image

Red-Green Scatter Diagram
Arguments:
-c all -f 3 -s 50 -m -l

Green-Blue Scatter Diagram
Arguments:
-c all -f 3 -s 50 -m -l

Blue-Red Scatter Diagram
Arguments:
-c all -f 3 -s 50 -m -l

Image

Red-Green Scatter Diagram
Arguments:
-c all -f 3 -s 50 -t -m -l

Green-Blue Scatter Diagram
Arguments:
-c all -f 3 -s 50 -t -m -l

Blue-Red Scatter Diagram
Arguments:
-c all -f 3 -s 50 -t -m -l



What the script does is as follows:

  • Scales the image to 8-bit depth and size 50x50 (nominally)
  • For each channel pair, finds the graylevel in range 0-255
    and plots a white point at x=graylevel for channel1 and y=graylevel for channel2

This is equivalent to the following IM commands.

  • colorlist="Red Green Blue"
  • for color in $colorlist; do
  • if [ "$color" = "Red" ]; then
  • color1="Red"
  • color1a="Red"
  • color2="Green"
  • color2a="Green1"
  • elif [ "$color" = "Green" ]; then
  • color1="Green"
  • color1a="Green1"
  • color2="Blue"
  • color2a="Blue"
  • elif [ "$color" = "Blue" ]; then
  • color1="Blue"
  • color1a="Blue"
  • color2="Red"
  • color2a="Red"
  • fi
  • xArray=(`convert $infile -scale '50x50>' -depth 8 -channel $color1 \
    -separate txt:- | tail -n +2 | tr -cs '0-9\n' ' ' | cut -d' ' -f3`)
  • yArray=(`convert $infile -scale '50x50>' -depth 8 -channel $color2 \
    -separate txt:- | tail -n +2 | tr -cs '0-9\n' ' ' | cut -d' ' -f3`)
  • # Generate a MVG file for IM to draw all components
  • ( echo "viewbox 0 0 256 256 fill black rectangle 0,0 256 256"
  • echo "fill white"
  • if [ "$label" = "yes" -a "$channels" != "all" -o $format -eq 3 ]; then
  • echo "stroke $color1a stroke-width 3 line 0,0 255,0"
  • echo "stroke $color2a stroke-width 3 line 0,0 0,255"
  • fi
  • i=0
  • while [ $i -lt $hh ]; do
  • j=0
  • while [ $j -lt $ww ]; do
  • k=`expr $ww \* $i + $j`
  • echo " point ${xArray[$k]},${yArray[$k]}"
  • j=`expr $j + 1`
  • done
  • i=`expr $i + 1`
  • done
  • ) | eval convert mvg:- \$tmp$color
  • done
  • convert $tmpRed $tmpGreen $tmpBlue -combine $outfile