图象恢复是个很麻烦的难题,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
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 );
A pointer to a vImage buffer structure that contains data for the source image.
A pointer to a vImage buffer data structure. You are responsible for filling out the height
, width
, and rowBytes
fields 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.
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.
The horizontal offset, in pixels, to the upper-left pixel of the region of interest within the source image.
The vertical offset, in pixels, to the upper-left pixel of the region of interest within the source image.
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.
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
.
The height of the first kernel in pixels. This value must be odd.
The width of the first kernel in pixels. This value must be odd.
The height of the second kernel in pixels (ignored if kernel2 is NULL
). This value must be odd.
The width of the second kernel in pixels (ignored if kernel2 is NULL
). This value must be odd.
The divisor to be used in convolutions with the first kernel.
The divisor to be used in convolutions with the second kernel.
A background color. If you supply a color, you must also set the kvImageBackgroundColorFill
flag, otherwise the function ignores the color.
The number of times to iterate the deconvolution algorithm.
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
,kvImageTruncateKernel
, kvImageBackgroundColorFill
, or kvImageEdgeExtend
.
Set the kvImageDoNotTile
flag if you plan to perform your own tiling or use multithreading.
kvImageNoError
, otherwise it returns one of the error codes described in vImage Data Types and Constants Reference.
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:
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.
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.