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.

SCATTER


Generates a channel-by-channel scatter diagram between two images

Download Script

last modified: December 15, 2018



USAGE: scatter [-s scale] [-m] infile1 infile2 outfile
USAGE: scatter [-h or -help]

-s ..... scale .... subsampling scale size for input images in both dimensions;
................... default=50 (pixels)
-m................. mirror the resulting scatter diagram vertically
...................
The two input images must be the same size.

PURPOSE: To generate a channel-by-channel scatter diagram between two images.

DESCRIPTION: SCATTER generates a channel-by-channel scatter diagram between two images. The 8-bit channel graylevel values at each corresponding pixel in the two images are used as the x and y coordinates to plot white points on a 256x256 black background image. The process is slow and is proportional to the size of the input images. Therefore the two images 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:

-s scale ... SCALE is the resulting subsampled scale size of the two input images. The two images will be scaled to the desired size in pixels maximum on each side, if the images are 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.

-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.

The two input images must be the same size. If both images are grayscale, only the one channel will be processed.

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


Image vs Low Saturation Version Of Same Image

Image 1

Image 2

Scatter Diagram
Arguments:
-s 50

Scatter Diagram
Arguments:
-s 50 -m



Image vs Same Image
(should produce white diagonal line if all graylevels available in all channels)

Image 1

Image 2

Scatter Diagram
Arguments:
-s 50



Image vs Same Image Shifted By 1 Pixel

Image 1

Image 2
-roll +1+0

Scatter Diagram
Arguments:
-s 50



Image vs Same Image Shifted By 2 Pixels

Image 1

Image 2
-roll +2+0

Scatter Diagram
Arguments:
-s 50



What the script does is as follows:

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

This is equivalent to the following IM commands.

  • colorlist="Red Green Blue"
  • for color in $colorlist; do
  • xArray=(`convert $infile1 -scale '50x50>' -depth 8 -colorspace RGB -channel $color \
    -separate txt:- | tail -n +2 | tr -cs '0-9\n' ' ' | cut -d' ' -f3`)
  • yArray=(`convert $infile2 -scale '50x50>' -depth 8 -colorspace RGB -channel $color \
    -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"
  • 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