| Environments | PYTHON :: EASI |
| Quick links | Description :: Parameters :: Parameter descriptions :: Details :: Example :: Related |
| Back to top |
| Back to top |
mosprep(mfile, silfile, nodatval, sortmthd, normaliz, balspec, loclmask, globfile, globmask, cutmthd, mapunits)
| Name | Type | Caption | Length | Value range |
|---|---|---|---|---|
| MFILE * | str | Input file name, folder, text file, or existing mosaic project | 1 - | |
| SILFILE * | str | Mosaic project to create | 1 - | |
| NODATVAL | List[float] | NoData value of input images | 0 - | |
| SORTMTHD | str | Sorting method | 0 - | NONE | NEARESTCENTER | MAXINTERSECT Default: NEARESTCENTER |
| NORMALIZ | str | Normalization method | 0 - | NONE | HOTSPOT | ADAPTIVE Default: NONE |
| BALSPEC | str | Color-balancing method | 0 - | BUNDLE | OVERLAP | LUT | HISTOGRAM | REFERENCE | NEIGHBORHOOD | NONE Default: BUNDLE |
| LOCLMASK | str | Local exclusion mask | 0 - 10 | Default: NONE |
| GLOBFILE | str | File containing global exclusion mask | 0 - | |
| GLOBMASK | List[int] | Global exclusion-mask segment | 0 - 4 | |
| CUTMTHD | str | Method for generating cutlines | 0 - | MINSQDIFF | MINDIFF | MINRELDIFF | EDGE | MAXDATA | IMPORT | FILEEXT Default: MINSQDIFF |
| MAPUNITS | str | Map units | 0 - | UTM, LONG/LAT, METER, and others |
| Back to top |
MFILE
The data to mosaic.
Input images can vary in projection, spatial resolution, or both. When the projection varies, the default output projection will be that which occurs most commonly in the input imagery.
You can specify the value of the parameter by using any of the following options:
<FILE>; [<NODATVAL>]
For example, C:\Data\image.pix; 0 indicates that a zero will be used as the background for the image.pix file.
"c:\data\image1.pix"; -9999 ! all channels use -9999 as their NoData
"c:\data\image2.pix"; 0, -9999 ! channel 1 uses 0 for its NoData and the remaining channels use -9999
"c:\data\image3.pix"; ,0,-9999 ! channel 1 does not have a NoData (notice the comma before the zero), channel 2 uses 0 for its NoData and the remaining channels use -9999
SILFILE
The name of the mosaic project file (.mos) to create.
An accompanying folder, with the same base name, is also created. The folder contains auxiliary information that makes up the mosaic project created by the mosaic-preparation process. Unique image IDs are created automatically based on the names of the source files and listed in the project file.
You can open the output mosaic project in CATALYST Professional Mosaic Tool to enhance the mosaic and perform quality-control procedures.
NODATVAL
The background value of the input images.
A pixel you designate as NoData is excluded from normalization, color balancing, and cutline generation. Images often have NoData defined in their metadata so this parameter can be defaulted.
When you specify a text file as input, you can specify the NoData value of an image in the file. The NoData value specified in the input text file takes precedence over all other sources. When a value is not specified in the text file, precedence is applied to the NO_DATA_VALUE metadata tag of the input image. If NO_DATA_VALUE metadata exists for an input channel, its value is used; otherwise, the NO_DATA_VALUE at the file level is used. Finally, if a NoData value is available in neither the text file nor the metadata, you can specify the value for this parameter.
If necessary, you can enter more than one NoData value for your input images. For example, to specify that channel 1 has a NoData value of -9999, channel 2 is 0, and channel 3 is 255, enter -9999,0,255.
SORTMTHD
The order in which to mosaic the images.
This parameter is optional.
NORMALIZ
The normalization to apply to each source image before color balancing, cutline generation, or mosaicking.
Occasionally, images can contain patterns in visual brightness that affect the seamless integration of the images into a mosaic. By applying normalization, bright and dark effects in images are evened out to create a mosaic that is more pleasing visually.
Each normalization method applied (except NONE) results in some coefficients that define a transformation of pixel values in the source image. These are written to the source-image description file.
A hot spot is a common distortion in aerial photographs and optical-satellite images. With aerial photographs, distortion is caused typically by solar reflections that appear circular (also known as lens flare). With optical-satellite images, distortion appears typically as a striped pattern.
HOTSPOT normalizes the brightness over the image by fitting a Gaussian surface to the brightness values. Smaller spot reflections, such as from lakes, cars, or buildings are not removed.
ADAPTIVE adjusts the brightness and contrast over local areas, improving image detail, while reducing the bright-and-dark pattern over the entire image. The method applies an adaptive enhancement by using a moving window to calculate the adjustment for each pixel value.
The size of the window affects the results of the filter. You specify the window size by entering the percentage value of the filter size; for example, to represent a 35-percent window, enter 35. If you do not specify a value for image_percent, a default value of 20, or 20 percent, is applied.
ADAPTIVE calculates the mean and standard deviation of the gray levels in the window and adjusts the values to match the overall mean and standard deviation of the image. Mean adjusts the brightness and standard deviation adjusts the contrast.
This parameter is optional.
BALSPEC
The color-balancing method to apply.
Color balancing evens out the color contrasts between images to reduce the visibility of seams and produce a mosaic that is appealing visually. Each method (except NONE) results in some parameters that define an adjustment of pixel values in the source image. The adjustments are applied when the image is added to the mosaic and stored as part of the mosaic project.
First, a global adjustment of the mean and sigma of each image is computed by using a "block-bundle" method between it and each of its overlapping images. The method makes large adjustments between images to make them more balanced.
Second, a series of dodging points is determined automatically to make smaller local adjustments between pairs of images. The order of the input images is ignored, because all of the overlapping images are used to adjust one image.
You can also specify the keyword AUTOSCALE to have all input images stretched linearly and have a common scale. This can improve the results when the dynamic ranges of various input images vary significantly. You can also specify the keyword DODGE=MANY to allow the creation of multiple dodging points for each edges across the whole project, rather than just one dodging point per edge. When DODGE=MANY is specified, you can also use the SAMPLE=<size> and DIST=<distance> keywords to further control the dodging points. To adjust the number of full-resolution pixels that are used to compute each dodging point specify a value for the sample <size>. To adjust the spacing between the dodging points specify a <distance> in the units of the project. When unspecified, a default <size> of 64x64 is used, while a <distance> is computed automatically. For example, BALSPEC="BUNDLE, DODGE=MANY, SAMPLE=128, DIST=1000" would result in dodging points being created every 1000 meters, with each point using the surrounding 128x128 pixels.The rasters must have a sufficient overlap (greater than 10 percent) between each pair of adjacent input rasters and have good-quality georeferencing. You can also specify a local (LOCLMASK) or global mask (GLOBMASK). The mask must have some pixels within the overlap area to affect the output.
When you specify a LUT value, MOSPREP looks for one LUT segment for each image channel; for example, an RGB-color image being added to the mosaic must have three LUT segments per input file.
LUT-segment numbers must be provided explicitly using LUT_segment_numbers. The first LUT is used for the first image channel, the second LUT for the second channel, and so on. All input images must have the specified LUT segments; otherwise, the process will stop and an error message is displayed.
HISTOGRAM, [<match_area_multiple>], [<trim_percentage>]: Color balancing is based on matching the histogram of the input image to that of the target mosaic image, sequentially.
The reference-image file is specified by fili_ref. The reference image need not be the same resolution or projection as the input images, provided it can be reprojected into the projection of the input image. That is, neither precise georeferencing nor overlap are required.
When you specify NEIGHBORHOOD, MOSPREP uses the default values of meanb_adjustment, outlier_correction, and outlier_threshold.
This parameter is optional.
LOCLMASK
Whether to apply a local mask to exclude specific pixels from color balancing or from cutline generation.
You use a mask when the same feature or features differ radically from one image to another.
LOCLMASK = (NONE | BIT | VEC | <n>), (NONE | BIT | VEC | <n>)
The first parameter value refers to color balancing and the second refers to cutline generation. Regions specified with the second parameter are used as local constraints during cutline generation.
This parameter is optional.
GLOBFILE
The file that, in conjunction with the value of GLOBMASK, you can use to define a global exclusion mask.
A global exclusion mask identifies regions in the source images to exclude from color balancing or cutline generation. GLOBFILE provides the file name referenced by GLOBMASK.
GLOBFILE = (<cb_file> | NONE), (<cut_file>)
This parameter is optional.
GLOBMASK
In conjunction with the value of GLOBFILE, the global exclusion mask that identifies regions in the source images to exclude from color balancing or cutline generation.
Typically, you use the global exclusion mask to identify large areas to exclude from color balancing, such as a large body of water. The mask can also include building footprints to influence the cutlines that MOSPREP generates. However, because the specified mask assigns a high cost to masked regions, cutlines will generally avoid such regions unless there is no better alternative.
You can specify a bitmap or a vector as an exclusion mask, both of which refer to the file specified for GLOBFILE. If you do not specify a value for this parameter, no mask is applied.
GLOBMASK = (-1 | <n>), (m)
This parameter is optional.
CUTMTHD
The method to use to generate cutlines (polygons that enclose all of the data) from an image to include in the output mosaic.
You can specify the value as follows:
CUTMTHD = <method>, [(<vector_file>, [<field_name>], [<segment_number>]) | (AUTOCONSTRAIN[=CLASSIC[,<thiessen_factor>]] | [=STRIPS[,<overlap_factor>]]), [VECTHIN=<thin_tolerance>], [DOWNRES=<x_resolution>[;<y_resolution>]], [ERODEEXT[=<erosion_distance>]], [FORCE_DATAEXT]]
The keyword identifying the method is mandatory, but you can, optionally, specify other settings to further influence the cutlines. In particular, you can specify options related to constraining polygons, which define regions in which cutlines are allowed for each image, such that the generated cutlines do not cross the specified boundaries or thinning the cutlines, which reduces the number of vertices.
Specify a cutline constraint file
If the field_name is not specified, MOSPREP searches the vector-segment attributes for a field named ImageSource. If the specified field name or ImageSource does not exist, an error occurs.
If the segment number is not specified, the algorithm uses the last segment from the vector file you specified. If the constraining polygon is larger than the image being processed, cutline generation is not constrained. If the constraining polygon does not overlap the image, an error occurs.
Automatically generate a cutline-constraint file
You can use the AUTOCONSTRAIN option to automatically generate a constraining polygon layer. By doing so, MOSPREP will generate one constraint polygon for each input image. If the input images are approximately square and contain a lot of overlap, the classic constraint polygons limit the data to consider for cutline generation to only the central parts of each image. Alternatively, if the images have one side much longer than the other than the strips method is likely better for constraining the cutline generation.
The AUTOCONSTRAIN=CLASSIC option is ideal for use with airphoto projects, because, such projects have typically a large amount of image overlap. You can adjust the option by specifying a Thiessen factor (thiessen_factor). The value you specify can range from 1 through 100. A larger value causes more overlap between the generated constraint polygons; that is, the cutlines will be less constrained. If you do not specify a value, the default value of 50 is applied. If AUTOCONSTRAIN is specified without a further keyword, it is interpreted as if CLASSIC were provided so AUTOCONSTRAIN=40 is treated as AUTOCONSTRAIN=CLASSIC,40.
The AUTOCONSTRAIN=STRIPS option is best suited for projects that have a clear pattern of strips, such as often seen with ADS data. Images must be of similar size and align in at least one direction from, for instance, aerial flight lines or satellite swaths. Cutline-constraining polygons will be generated for each image based on where it and its neighbors have actual data. This method first tries to group the images in rows or columns, and will choose the strips with the most consistent distance between images. It will then remove the overlap between images in each strip using, at most, two neighboring images. Finally overlap will be remove between the different strips leaving a constraining polygon. The extents of the polygons can be manipulated by specifying a value between 1 through 100 for the overlap factor (overlap_factor). A larger value causes more overlap between the generated constraint polygons; that is, the cutlines will be less constrained. If you do not specify a value, the default value of 30 is applied.
The VECTHIN option controls the thinning, or weeding, of the computed cutlines. When you want the cutlines, with all of the vertices computed initially, included in the output, enter a thin-tolerance value of 0. Any number greater than zero increases the thinning of the vector, so the cutlines will have fewer vertices. Approximately, a value of n results in 1/n of the vertices being written to the output. When you do not specify a value, a default value of 1.75 is applied (VECTHIN=1.75).
The DOWNRES option controls the resolution of the mosaic preview. It can be used to override the default reduced-resolution used by the algorithm. The applicable units are those of the projection of your project. For example, to use a 8 meters resolution of an UTM project, enter CUTMTHD="MINSQDIFF, DOWNRES=8".
Eroding the data-extents polygons
By default, if an image does not overlap the current mosaic preview, it will be assigned a cutline equal to that file's extents. Consider using the keyword FORCE_DATAEXT if you prefer such an image to have its cutline be the image's data-extents. By doing so, you ensure MOSPREP creates data-extents polygons for each input image and that the cutline will be set to the image's data-extents if it does not overlap with the current mosaic preview. For example, the first image is, by default, assigned a file extents cutline because the mosaic preview is empty at the start.
When one image completely overlaps another in the same mosaic project, the computation of the cutlines differs slightly. Perpendicular profiles are drawn at intervals around the image boundary. For each profile, the location that gives the best result for your cutline criterion (for example, MINDIFF, MINRELDIFF, and so on) is selected as a "seed point". A dynamic programming algorithm is then used to find the minimum-cost path. This produces a cutline that can be merged to form a closed loop. This may appear as a "patch", because there is no starting and ending point but, rather, a looped cutline.
This parameter is optional.
MAPUNITS
The projection string or units of the mosaic preview and other MOSPREP output data.
If you do not specify a value for this parameter, the projection that occurs most commonly in the input imagery is applied. If you specify a projection that differs from that of the input data, the data is reprojected. A projection string must fully identify the projection and Earth model you want, such as UTM 17 D000.
The standard definitions are as follows:
For a complete list of supported projections and Earth models, see Map projections. For information on the format of the map-units string, see Output units.
| Back to top |
MOSPREP combines a set of images into an image mosaic project.
The first step of a mosaic process is to identify and prepare the data. MOSPREP generates a series of files that describe how to mosaic the imagery. This includes creating cutlines for each image, generating color balancing and normalization coefficients to apply, and applying exclusion masks to remove specific areas from the output mosaic.
The first image serves as a "template" for mosaicking; specifically, the first channel. Each subsequent image that has a first channel that matches the bit depth of the first channel of the template is included in the mosaic. Images with a first-channel bit depth that does not match the template are excluded. The number of channels in the mosaic will equal that of each valid input image of the same bit depth.
With MOSPREP, you can define local or global masks to control color-balancing calculations and cutline generation. These masks can, for instance, define cloudy areas to exclude from color balancing, or areas in which to avoid placing cutlines. When a cutline passes through a building, for example, it produces a displeasing effect in the resulting mosaic. By providing a mask file that identifies buildings by outlining their base footprints, you can define areas in which to avoid placing cutlines, when possible.
Output results
The following is an example of the output created for a mosaic project with Halifax specified as the name of the output mosaic project:
If MOSPREP computes neither normalization, color balancing, nor cutlines, the mosaic preview is not created. To generate the preview, run the MOSPREVIEW algorithm.
When input files result in the same photo ID, for example: ottawa, then the photo ID for the second file must be made unique. The method used to make it unique is to append a number to the photo ID. All subsequent photo IDs that produce the same base name must also be made unique. In such a case the number is just incremented, for example: ottawa, ottawa_1, ottawa_2, etc.
| Back to top |
The following example generates a mosaic project of all images in C:\Halifax\orthos, by using the bundle color-balancing method and a global exclusion mask. The input image-background value (as defined by NODATAVAL) is 0.
from pci.mosprep import mosprep mfile = "Halifax/orthos" # location of orthorectified images silfile = "Halifax/Halifax.mos" # source-image list file to hold information nodatval = [0] # define 0 as input image background value sortmthd = "" # use NEARESTCENTER as sorting method normaliz = "ADAPTIVE" # normalization method balspec = "BUNDLE" # color-balancing method loclmask = "" # do not use any local masks globfile = "data/lake.pix" # source file to define the exclusion mask globmask = [2] # use segment 2 from lake.pix as exclusion mask cutmthd = "MINSQDIFF" # cutline-generation method mosprep(mfile, silfile, nodatval, sortmthd, normaliz, balspec, loclmask, globfile, globmask, cutmthd)
© PCI Geomatics Enterprises, Inc.®, 2026. All rights reserved.