---
name: "im_spcor"
section: "3"
platform: "linux"
package: "libvips-dev"
version: "7.20.7-1+b3"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/im_fastcor"
---

# im\_spcor(3)

correlate two images

Part of [im\_fastcor(3)](/im_fastcor/3.md).

## NAME

im\_fastcor, im\_spcor - correlate two images

## SYNOPSIS

**#include \<vips/vips.h\>**

**int im\_fastcor(in, ref, out)**\
 **IMAGE \*in, \*ref, \*out;**

**int im\_spcor(in, ref, out)**\
 **IMAGE \*in, \*ref, \*out;**

## DESCRIPTION

These functions calculate spatial correlation between two  one-band images held by the image descriptors  **in** and  **ref.** The sizes of  **ref** should be smaller than the sizes of  **in.** The correlation is carried out by overlapping  **ref** on the top left corner of  **in** and moving it over  **in.**

The output image is the same size as the input. The edge pixels are calculated by expanding the input image using **[im\_embed(3)](/im_embed/3.md)** in mode 1 (replicating edge pixels) just enough so that the output can match the input.

**[im\_spcor(3)](/im_spcor/3.md)** calculates the spatial correlation between  **in** and  **ref** using the correlation coefficient from Niblack "An Introduction to Digital Image Processing,", Prentice/Hall, pp 138.  The resultant coefficients are written as float numbers in  **out.** The images must be char, short or ushort.

**[im\_fastcor(3)](/im_fastcor/3.md)** simply returns the sum of squares of differences between  **in** and  **ref.** This is much faster, but less useful. The resultant coefficients are written as unsigned int numbers in out which has a size of in.

## BUGS

The functions do not check for integer overflow.

## RETURN VALUE

The function returns 0 on success and -1 on error.

## SEE ALSO

[im\_conv(3)](/im_conv/3.md), [im\_lrmosaic(3)](/im_lrmosaic/3.md).

## COPYRIGHT

The National Gallery and Birkbeck College, 1990-1997.
