Movatterモバイル変換


[0]ホーム

URL:


libvips

A fast image processing library with low memory needs.

DownloadInstallDocumentationIssuesWikilibvips projectslibvips on GitHub
Top  | Description  | Object HierarchyHomeUpPrevNext

convolution

convolution — convolve and correlate images

Stability Level

Stable, unless otherwise indicated

Functions

intvips_conv ()
intvips_convf ()
intvips_convi ()
intvips_conva ()
intvips_convsep ()
intvips_convasep ()
intvips_compass ()
intvips_gaussblur ()
intvips_sharpen ()
intvips_spcor ()
intvips_fastcor ()
intvips_sobel ()
intvips_scharr ()
intvips_prewitt ()
intvips_canny ()

Types and Values

enumVipsCombine

Object Hierarchy

GEnum╰── VipsCombine

Includes

#include <vips/vips.h>

Description

These operations convolve an image in some way, or are operations based onsimple convolution, or are useful with convolution.

Functions

vips_conv ()

intvips_conv (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Optional arguments:

  • precision:VipsPrecision, calculation accuracy

  • layers:gint, number of layers for approximation

  • cluster:gint, cluster lines closer than this distance

Convolution.

Perform a convolution ofin withmask.Each output pixel is calculated as:

1
sigma[i]{pixel[i]*mask[i]}/scale+offset

where scale and offset are part ofmask.

By default,precision isVIPS_PRECISION_FLOAT. The output imageis alwaysVIPS_FORMAT_FLOAT unlessin isVIPS_FORMAT_DOUBLE, in which caseout is alsoVIPS_FORMAT_DOUBLE.

Ifprecision isVIPS_PRECISION_INTEGER, thenelements ofmask are converted tointegers before convolution, usingrint(),and the output imagealways has the sameVipsBandFormat as the input image.

ForVIPS_FORMAT_UCHAR images andVIPS_PRECISION_INTEGERprecision,vips_conv() uses a fast vector path based onhalf-float arithmetic. This can produce slightly different results.Disable the vector path with--vips-novector orVIPS_NOVECTOR orvips_vector_set_enabled().

Ifprecision isVIPS_PRECISION_APPROXIMATE then, likeVIPS_PRECISION_INTEGER,mask is converted to int before convolution, andthe output imagealways has the sameVipsBandFormat as the input image.

Larger values forlayers give more accurateresults, but are slower. Aslayers approaches the mask radius, theaccuracy will become close to exact convolution and the speed will drop tomatch. For many large masks, such as Gaussian,n_layers need be only 10% ofthis value and accuracy will still be good.

Smaller values ofcluster will give more accurate results, but be slowerand use more memory. 10% of the mask radius is a good rule of thumb.

See also:vips_convsep().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolve with this mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_convf ()

intvips_convf (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Convolution. This is a low-level operation, seevips_conv() for somethingmore convenient.

Perform a convolution ofin withmask.Each output pixel iscalculated as sigma[i]{pixel[i] * mask[i]} / scale + offset, where scaleand offset are part ofmask.

The convolution is performed with floating-point arithmetic. The output imageis alwaysVIPS_FORMAT_FLOAT unlessin isVIPS_FORMAT_DOUBLE, in which caseout is alsoVIPS_FORMAT_DOUBLE.

See also:vips_conv().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolve with this mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_convi ()

intvips_convi (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Integer convolution. This is a low-level operation, seevips_conv() forsomething more convenient.

mask is converted to an integer mask withrint() of each element, rint ofscale and rint of offset. Each output pixel is then calculated as

1
sigma[i]{pixel[i]*mask[i]}/scale+offset

The output image always has the sameVipsBandFormat as the input image.

ForVIPS_FORMAT_UCHAR images,vips_convi() uses a fast vector path based onhalf-float arithmetic. This can produce slightly different results.Disable the vector path with--vips-novector orVIPS_NOVECTOR orvips_vector_set_enabled().

See also:vips_conv().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolve with this mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_conva ()

intvips_conva (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Optional arguments:

  • layers:gint, number of layers for approximation

  • cluster:gint, cluster lines closer than this distance

Perform an approximate integer convolution ofin withmask.This is a low-level operation, seevips_conv() for something more convenient.

The output imagealways has the sameVipsBandFormat as the input image.Elements ofmask are converted tointegers before convolution.

Larger values forlayers give more accurateresults, but are slower. Aslayers approaches the mask radius, theaccuracy will become close to exact convolution and the speed will drop tomatch. For many large masks, such as Gaussian,layers need be only 10% ofthis value and accuracy will still be good.

Smaller values ofcluster will give more accurate results, but be slowerand use more memory. 10% of the mask radius is a good rule of thumb.

See also:vips_conv().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolution mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_convsep ()

intvips_convsep (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Optional arguments:

  • precision: calculation accuracy

  • layers: number of layers for approximation

  • cluster: cluster lines closer than this distance

Perform a separable convolution ofin withmask.Seevips_conv() for a detailed description.

The mask must be 1xn or nx1 elements.

The image is convolved twice: once withmask and then again withmaskrotated by 90 degrees. This is much faster for certain types of mask(gaussian blur, for example) than doing a full 2D convolution.

See also:vips_conv(),vips_gaussmat().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolution mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_convasep ()

intvips_convasep (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Optional arguments:

  • layers:gint, number of layers for approximation

Approximate separable integer convolution. This is a low-level operation, seevips_convsep() for something more convenient.

The image is convolved twice: once withmask and then again withmaskrotated by 90 degrees.mask must be 1xn or nx1 elements.Elements ofmask are converted tointegers before convolution.

Larger values forlayers give more accurateresults, but are slower. Aslayers approaches the mask radius, theaccuracy will become close to exact convolution and the speed will drop tomatch. For many large masks, such as Gaussian,layers need be only 10% ofthis value and accuracy will still be good.

The output imagealways has the sameVipsBandFormat as the input image.

See also:vips_convsep().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolve with this mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_compass ()

intvips_compass (VipsImage *in,VipsImage **out,VipsImage *mask,...);

Optional arguments:

  • times:gint, how many times to rotate and convolve

  • angle:VipsAngle45, rotate mask by this much between colvolutions

  • combine:VipsCombine, combine results like this

  • precision:VipsPrecision, precision for blur, default float

  • layers:gint, number of layers for approximation

  • cluster:gint, cluster lines closer than this distance

This convolvesin withmasktimes times, rotatingmask byangleeach time. By default, it comvolves twice, rotating by 90 degrees, takingthe maximum result.

See also:vips_conv().

[method]

Parameters

in

input image

 

out

output image.

[out]

mask

convolve with this mask

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_gaussblur ()

intvips_gaussblur (VipsImage *in,VipsImage **out,double sigma,...);

Optional arguments:

  • precision:VipsPrecision, precision for blur, default int

  • min_ampl: minimum amplitude, default 0.2

This operator runsvips_gaussmat() andvips_convsep() for you on an image.Setmin_ampl smaller to generate a larger, more accurate mask. Setsigmalarger to make the blur more blurry.

See also:vips_gaussmat(),vips_convsep().

[method]

Parameters

in

input image

 

out

output image.

[out]

sigma

how large a mask to use

 

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_sharpen ()

intvips_sharpen (VipsImage *in,VipsImage **out,...);

Optional arguments:

  • sigma: sigma of gaussian

  • x1: flat/jaggy threshold

  • y2: maximum amount of brightening

  • y3: maximum amount of darkening

  • m1: slope for flat areas

  • m2: slope for jaggy areas

Selectively sharpen the L channel of a LAB image. The input image istransformed toVIPS_INTERPRETATION_LABS.

The operation performs a gaussian blur and subtracts fromin to generate ahigh-frequency signal. This signal is passed through a lookup table formedfrom the five parameters and added back toin.

The lookup table is formed like this:

1234567891011121314151617
.^.y2|----------------.|/.|/slopem2.|.../.-x1|...|.-------------------...---------------------->.|...|x1.|...slopem1./|./m2|./|./|./|./|.______/______|-y3.|

For screen output, we suggest the following settings (the defaults):

123456
sigma==0.5x1==2y2==10(don'tbrightenbymorethan10L*)y3==20(candarkenbyupto20L*)m1==0(nosharpeninginflatareas)m2==3(somesharpeninginjaggyareas)

If you want more or less sharpening, we suggest you just change them2 parameter.

Thesigma parameter changes the width of the fringe and can beadjusted according to the output printing resolution. As an approximateguideline, use 0.5 for 4 pixels/mm (display resolution),1.0 for 12 pixels/mm and 1.5 for 16 pixels/mm (300 dpi == 12pixels/mm). These figures refer to the image raster, not the half-toneresolution.

See also:vips_conv().

[method]

Parameters

in

input image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_spcor ()

intvips_spcor (VipsImage *in,VipsImage *ref,VipsImage **out,...);

Calculate a correlation surface.

ref is placed at every position inin and the correlation coefficientcalculated. The outputimage is always float.

The outputimage is the same size as the input. Extra input edge pixels are made bycopying the existing edges outwards.

The correlation coefficient is calculated as:

1234
sumij(ref(i,j)-mean(ref))(inkl(i,j)-mean(inkl))c(k,l)=------------------------------------------------sqrt(sumij(ref(i,j)-mean(ref))^2)*sqrt(sumij(inkl(i,j)-mean(inkl))^2)

where inkl is the area ofin centred at position (k,l).

from Niblack "An Introduction to Digital Image Processing",Prentice/Hall, pp 138.

If the number of bands differs, one of the imagesmust have one band. In this case, an n-band image is formed from theone-band image by joining n copies of the one-band image together, and thenthe two n-band images are operated upon.

The output image is always float, unless either of the two inputs isdouble, in which case the output is also double.

See also:vips_fastcor().

[method]

Parameters

in

input image

 

ref

reference image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_fastcor ()

intvips_fastcor (VipsImage *in,VipsImage *ref,VipsImage **out,...);

Calculate a fast correlation surface.

ref is placed at every position inin and the sum of squares ofdifferences calculated.

The outputimage is the same size as the input. Extra input edge pixels are made bycopying the existing edges outwards.

If the number of bands differs, one of the imagesmust have one band. In this case, an n-band image is formed from theone-band image by joining n copies of the one-band image together, and thenthe two n-band images are operated upon.

The output type is uint if both inputs are integer, float if both are floator complex, and double if either is double or double complex.In other words, the output type is just large enough to hold the wholerange of possible values.

See also:vips_spcor().

[method]

Parameters

in

input image

 

ref

reference image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error


vips_sobel ()

intvips_sobel (VipsImage *in,VipsImage **out,...);

Sobel edge detector.

uchar images are computed using a fast, low-precision path. Cast to floatfor a high-precision implementation.

See also:vips_canny(),vips_sobel(),vips_prewitt(),vips_scharr().

[method]

Parameters

in

input image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_scharr ()

intvips_scharr (VipsImage *in,VipsImage **out,...);

Scharr edge detector.

uchar images are computed using a fast, low-precision path. Cast to floatfor a high-precision implementation.

See also:vips_canny(),vips_sobel(),vips_prewitt(),vips_scharr().

[method]

Parameters

in

input image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_prewitt ()

intvips_prewitt (VipsImage *in,VipsImage **out,...);

Prewitt edge detector.

uchar images are computed using a fast, low-precision path. Cast to floatfor a high-precision implementation.

See also:vips_canny(),vips_sobel(),vips_prewitt(),vips_scharr().

[method]

Parameters

in

input image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.


vips_canny ()

intvips_canny (VipsImage *in,VipsImage **out,...);

Optional arguments:

  • sigma:gdouble, sigma for gaussian blur

  • precision:VipsPrecision, calculation accuracy

Find edges by Canny's method: The maximum of the derivative of the gradientin the direction of the gradient. Output is float, except for uchar input,where output is uchar, and double input, where output is double. Non-compleximages only.

Usesigma to control the scale over which gradient is measured. 1.4 isusually a good value.

Useprecision to set the precision of edge detection. For uchar images,setting this toVIPS_PRECISION_INTEGER will make edge detection muchfaster, but sacrifice some sensitivity.

You will probably need to process the output further to eliminate weakedges.

See also:vips_sobel().

[method]

Parameters

in

input image

 

out

output image.

[out]

...

NULL-terminated list of optional named arguments

 

Returns

0 on success, -1 on error.

Types and Values

enum VipsCombine

How to combine values. Seevips_compass(), for example.

Members

VIPS_COMBINE_MAX

take the maximum of the possible values

 

VIPS_COMBINE_SUM

sum all the values

 

VIPS_COMBINE_MIN

take the minimum value

 

VIPS_COMBINE_LAST

  

Generated by GTK-Doc V1.34.0

[8]ページ先頭

©2009-2025 Movatter.jp