User's Guide

RANDSAMP

Randomly selects a given percentage of predetermined pixel blocks

Function:

Randomly selects a given percentage of pixel blocks of user-specified size from an input image to form an output image. Sampling may be done with or without replacement.

Parameters:

IN
Input image. May be a multi-band BYTE, INTEGER*2, INTEGER*4 and REAL*4 image. Band and window options may be specified.

OUT
Output image. Data type is the same as the input image. The size is determined by the number of randomly selected blocks and the two KERNDIM values.

KERNDIM(5,5)
Kernel dimensions. The number of lines and samples in each of the randomly selected sample blocks. See User Note 4.

SAMPFACT(5)
Sampling factor. Specifies the percent of sample blocks that will be selected to create the output image. Since only whole blocks are selected, if the value given for SAMPFACT results in a fractional number of samples, this number will be rounded to the nearest whole number.

DUPFLG(NO)
Duplication flag. Controls whether or not any duplicate samples will be replaced by unique ones.


  = NO:  The user has requested that no duplicate 
         samples be used.  In this case the program
         deletes redundant sample blocks and searches
         for unselected samples. Redundant block 
         will be replaced by new one found by further 
         search.

  = YES: The program uses redundant sample blocks. 
         Redundant blocks are therefore not going to
         be replaced. 

Examples:

  1. LAS> randsamp in="test.dat(1,1,512,512)" out=small.dat kerndim=(2,2) dupflg=yes

    Five percent of the 2 x 2 sample blocks are selected, resulting in an output image of size 116 x 114. Some sample blocks may be used more than once.

  2. LAS> randsamp in="test.dat(1,1,512,512)" out=new.dat kerndim=(10,10)

    An image of size 120 x 110 results (see Description/ Algorithm section). The input image is sampled to line 510 and pixel 510 because of truncation. Sample blocks are not used more than once.

  3. LAS> randsamp in="landsat(1,1,100,100)" out=tinyland.dat kerndim=(3,4) sampfact=88

    The user is prompted four times to allow the search for unused sample blocks to continue. If the user responds with YES, the output image size is 96 x 92 (see Description/Algorithm section). If the user decides not to continue the search, the output image size is 96 x 88.

Description/Algorithm:

The input image is divided into a number of sample blocks, each having the size specified by the KERNDIM parameter. If the sample blocks do not divide evenly into the number of lines or pixels in the input image, the input image remainder is discarded. The number of random sample blocks needed for the output image is computed from the SAMPFACT of the number of input sample blocks (in the possibly truncated input image). If the value given for SAMPFACT results in a fractional number of random sample blocks, this number is rounded to the nearest integer. A random number generator is used to select the set of randomly sampled blocks to be taken from the input image; the block numbers are then sorted in ascending order.

If the user has requested that no duplicate samples be used (DUPFLG=NO), the program deletes redundant sample blocks and searches for unselected samples. After 10 iterations the user is prompted to allow continued searching. If the user chooses not to allow further searching, the output image is constructed of the nonredundant output blocks found at that point.

Otherwise, the program continues selecting nonredundant sample blocks, prompting every 10 iterations. The total number of pixels in the output image is the product of the number of randomly sampled blocks times the two KERNDIM values. The square root of this product is truncated, divided by the number of pixels in a sample row (KERNDIM(2)), and truncated to yield the number of sample blocks in an output row. The number of pixels in an output row is the product of the number of sample blocks in a row and the number of pixels in a sample row.

The number of lines in the output image is the product of the number of lines in a sample block (KERNDIM(1)) and the number of rows of sample blocks necessary to use all the selected samples. One or more blocks in the lower right corner of the output image may contain zero-fill pixels in the event the number of sample blocks is insufficient to completely fill the image. The user is informed of number of zero-fill blocks.

The selected samples are output in ascending order until all have been used. Because the randomly selected sample blocks are sorted into ascending order, some order is preserved in the output image; hence, a local area within it does not have the statistical properties of the output image as a whole.

Nonfatal Error Messages:

  1. [randsamp-last] Last xxx sample blocks in output image are zero-filled

    The number of lines in the output image is the product of the number of lines in a sample block (KERNDIM(1)) and the number of rows of sample blocks necessary to use all the selected samples. One or more blocks in the lower right corner of the output image may contain zero-fill pixels in the event the number of sample blocks is insufficient to completely fill the image.

  2. [randsamp-gensamp] Sampling of input image after 10 attempts: xxx percent

    This message informs the user what is the current percentage of nonredundant samples. The user will be prompted to continue. See Description/Algorithm for more details.

  3. [randsamp-outsize] Output image size (NL, NS): xxx, xxx

    This message informs the user what will be the output image size. See Description/Algorithm for more details.

Fatal Error Messages:

  1. [randsamp-kerndim] Sample block size is larger than input image size

    The size of the sample block should not exceed the image size. Respecify appropriate values for KERNDIM.

  2. [randsamp-size] Input images must be of same size

    If multiple input images are used, they must match in size. Respecify input images with same window size.

  3. [randsamp-zero] The number of sample blocks is zero

    The sampling factor specified, was too small and no sample blocks were found. Respecify higher percentage for sampling.

User's Notes:

  1. The entire input image is used for sampling if the sample size is evenly divisible into the number of lines and pixels. Otherwise, the input image is truncated to the largest size that supplies an integer number of sample blocks.

  2. Execution times are heavily dependent on the user's input. CPU usage is increased significantly by a large value of SAMPFACT and sampling without replacement.

  3. If a smaller output image than the one already created is desired, RANDSAMP may be rerun on the output image or on the original input image with a smaller SAMPFACT. However, using a subset of the output image from RANDSAMP may not produce statistical results representative of the original input image. The input and output image statistics may be obtained by using COVAR.

  4. The blocking of the input image is done to ensure the output image includes a good representation of the ecotones contained in the input image. Ecotones are areas which are transitions between different ecological land cover, like a forest and grassland transition zone.