Reputation: 1183
I'm trying to create custom cifilter (like adobe's warp filter). How to move only few pixels (that are in ROI) to some other location in kernel language? Maybe someone could suggest me some info about it? I have read all apple docs about creating custom cifilter, but haven't found any similar example of kernel portion of that type of filter. There are some CIFilters that does something similar (like CITwirlDistortion, CIBumpDistortion). Maybe there is some place where I could find their kernels?
Upvotes: 2
Views: 943
Reputation:
You have to do this in reverse. Instead of saying I want to put those input pixels at this position in the output you have to answer the question where are the pixels in the input for this output pixel.
Take a look at this kernel:
kernel vec4 coreImageKernel(sampler image, float minX, float maxX, float shift)
{
vec2 coord = samplerCoord( image );
float x = coord.x;
float inRange = compare( minX - x, compare( x - maxX, 1., 0. ), 0. );
coord.x = coord.x + inRange * shift;
return sample( image, coord );
}
It replaces a vertical stripe between minX and maxX with the contents of the image that is shift pixels to the right. Using this kernel with minX = 100, maxX = 300 and shift = 500 gives the image in the lower left corner. Original is in upper right.
So the effect is that you move the pixels in the range (minX + shift, maxX + shift) to (minX, maxX)
Upvotes: 5