Quartz Composer Fundamental : Cropping To Image Dimensions

When using Core Image filters in Quartz Composer, many filters expand pixel width/height, change bounds, or have other aberrations around the edge of the resulting image.

One fundamental way of handling this is to attach an Image Dimensions patch to the Image output of the Image that one wishes to filter. The Image Dimensions patch has Pixel Width and Height outputs. These outputs are connected to the Pixel Width and Height inputs on a Image Crop patch. The image output of the filter goes into the Crop patch, and the output of the Crop patch goes onto whatever Render patch one has selected, such as a Sprite or Billboard.

Some filters, such as Sobel Edge type filters, can be particularly rough, and still leave artifacts around the edges, even when cropping to the same dimensions as the source image. In this case, one can use a math patch between the Image Dimensions Pixel W/H and the W/H inputs of the crop patch, set to multiply at a value like .99.

The Crop To Reference Custom Virtual patch is the same as the basic combo of an Image Dimensions and a Crop patch when properly used, but it doesn't have the ability to add in the Math patches that are sometimes needed to attain a result free of aberrations at the borders of the image output.

This technique is necessary with a great deal of filters, most notably, blurs. In fact, choosing the default Image Filter template reveals a Zoom Blur that has this same connection of patches present, to remove the black fringe that would otherwise be present.