15
Dec
07

More on Core Image Filters (ROI, DOD)

A couple of posts back, I enthused about the new features of Quartz Composer 3.0s Core Image Filter patch.
It turns out they’re a little more tricky to use than I’d realised, so the wonderful space-saving composition I posted a screenshot of didn’t actually work as I’d intended, sadly.

As Kevin Quennesson from the Apple Quartzcomposer-dev list very patiently explained to me, the reason it didn’t work is to do with ROIs and DODs.

The ROI, (Region Of Interest) defines the region of the input image that a filter will act upon, when it’s Kernel code is called from the JavaScript in the bottom pane of the patch’s editing window.

The DOD (Domain Of Definition) defines the dimensions of the image returned by a given Kernel function.

All this isn’t an issue, if you’re creating a simple, single-pass filter, or if the dimensions of the output of the filter are the same as those of the input image. However, I wanted to combine 2 seperate filter functions, and a crop (which resulted in the dimensions of the output image changing, obviously). These are the stages of the multi-pass filter I created:

Original Image
CIFilter Original Image

Filter 1: Pixellation
CIFilter Pixellation

Filter 2: Pixel-Strip
Creates strip at bottom-left, with each vertical stripe representing one ’tile’ of the input image.
Pixels outside this ‘active area’ receive the colour values of the pixel at 0.0, 0.0, but are cropped-out at the next stage, anyway.
CIFilter Pixel-Strip

Final Stage: Crop
(Enlarged for clarity)
CIFilter Cropped

The JavaScript portion of the Core Image Filter code is as follows:
I’ve highlighted the ROI/DOD-related code in purple.

function __image main(__image Image, __number Rows, __number Cols)
{
// CREATE CONTROL VALUES FROM INPUT SPLITTERS

// Input image dimensions
var Width = Image.extent.width;
var Height = Image.extent.height;
// Dimensions of Pixellation cells
var CellWidth = Width / (Math.ceil(Rows));
var CellHeight = Height / (Math.ceil(Cols));
// Total number of cells
var CellNum = Rows * Cols;

// ROI + DOD FUNCTIONS
// Thanks to Kevin Quennesson for his explanation and sample code

// Region Of Interest (ROI) of input image to be processed
function myROIFunction(samplerIndex, dstRect, info)
{
return info;
}
// Output image dimensions (DOD rect)
var dodRect = new Vec(0.0, 0.0, Width, Height);

// IMAGE OPERATIONS

// Pixellate image
xy_pixellate.ROIHandler = myROIFunction;
imagePixellated = xy_pixellate.apply(dodRect, dodRect, Image, CellWidth, CellHeight);
// Create strip

makeStrip.ROIHandler = myROIFunction;
imageStrip = makeStrip.apply(dodRect, dodRect, imagePixellated, CellWidth, CellHeight, CellNum, Cols);
// Crop
imageCropped = Filter.Crop(imageStrip, new Vec(0.0, 0.0, CellNum, 1.0));
// Output
return imageStrip;
}

Advertisements

0 Responses to “More on Core Image Filters (ROI, DOD)”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


December 2007
M T W T F S S
« Nov   Jan »
 12
3456789
10111213141516
17181920212223
24252627282930
31  

Links

Blog Stats

  • 476,450 hits

%d bloggers like this: