iphone图象处理之--模糊图象恢复

图象恢复是个很麻烦的难题,IOS也提供了部分解决方法,那就是

Accelerator.

Accelerator vImage provides an implementation of the Richardson-Lucy deconvolution algorithm, which can be used to remove lens distortion

https://developer.apple.com/performance/accelerateframework.html

https://developer.apple.com/library/ios/documentation/Performance/Reference/vImage_convolution/Reference/reference.html


vImageRichardsonLucyDeConvolve_ARGB8888

Sharpens an ARGB8888 image by undoing a previous convolution that blurred the image, such as diffraction effects in a camera lens.

vImage_Error vImageRichardsonLucyDeConvolve_ARGB8888 (
   const vImage_Buffer *src,
   const vImage_Buffer *dest,
   void *tempBuffer,
   vImagePixelCount srcOffsetToROI_X,
   vImagePixelCount srcOffsetToROI_Y,
   const int16_t *kernel,
   const int16_t *kernel2,
   uint32_t kernel_height,
   uint32_t kernel_width,
   uint32_t kernel_height2,
   uint32_t kernel_width2,
   int32_t divisor,
   int32_t divisor2,
   Pixel_8888 backgroundColor,
   uint32_t iterationCount,
   vImage_Flags flags
);
Parameters
src

A pointer to a vImage buffer structure that contains data for the source image.

dest

A pointer to a vImage buffer data structure. You are responsible for filling out the heightwidth, and rowBytesfields of this structure, and for allocating a data buffer of the appropriate size. On return, the data buffer pointed to by this structure contains the destination image data. When you no longer need the data buffer, you must deallocate the memory. The size (number of rows and number of columns) of the destination buffer also specifies the size of the region of interest in the source buffer.

tempBuffer

A pointer to a temporary buffer. If you pass NULL, the function allocates the buffer, then deallocates it before returning. Alternatively, you can allocate the buffer yourself, in which case you are responsible for deallocating it when you is no longer need it.

If you want to allocate the buffer yourself, see the Discussion for information on how to determine the minimum size that you must allocate.

srcOffsetToROI_X

The horizontal offset, in pixels, to the upper-left pixel of the region of interest within the source image.

srcOffsetToROI_Y

The vertical offset, in pixels, to the upper-left pixel of the region of interest within the source image.

kernel

A pointer to the deconvolution kernel data, which must be a packed array without any padding. The kernel expresses a blurring convolution or point-spread function.

kernel2

A pointer to the data of a second kernel, which must be a packed array without any padding. Supply this kernel only if the first kernel is asymmetrical; otherwise pass NULL.

kernel_height

The height of the first kernel in pixels. This value must be odd.

kernel_width

The width of the first kernel in pixels. This value must be odd.

kernel_height2

The height of the second kernel in pixels (ignored if kernel2 is NULL). This value must be odd.

kernel_width2

The width of the second kernel in pixels (ignored if kernel2 is NULL). This value must be odd.

divisor

The divisor to be used in convolutions with the first kernel.

divisor2

The divisor to be used in convolutions with the second kernel.

backgroundColor

A background color. If you supply a color, you must also set the kvImageBackgroundColorFill flag, otherwise the function ignores the color.

iterationCount

The number of times to iterate the deconvolution algorithm.

flags

The options to use when performing the deconvolution operation. You must set exactly one of the following flags to specify how vImage handles pixel locations beyond the edge of the source image: kvImageCopyInPlace,kvImageTruncateKernelkvImageBackgroundColorFill, or kvImageEdgeExtend.

Set the kvImageDoNotTile flag if you plan to perform your own tiling or use multithreading.

Return Value

kvImageNoError, otherwise it returns one of the error codes described in vImage Data Types and Constants Reference.

Discussion

This function performs a Richardson-Lucy deconvolution of a region of interest within a source image by an M x N kernel, performing a specified number of iterations and placing the result in a destination buffer.

If you want to allocate the memory for the tempBuffer parameter yourself, call this function twice, as follows:

  1. To determine the minimum size for the temporary buffer, the first time you call this function pass thekvImageGetTempBufferSize flag. Pass the same values for all other parameters that you intend to use in for the second call. The function returns the required minimum size, which should be a positive value. (A negative returned value indicates an error.) The kvImageGetTempBufferSize flag prevents the function from performing any processing other than to determine the minimum buffer size.

  2. After you allocate enough space for a buffer of the returned size, call the function a second time, passing a valid pointer in the tempBuffer parameter. This time, do not pass the kvImageGetTempBufferSize flag.


你可能感兴趣的:(ios,image,accelerato)