... | ... | @@ -519,4 +519,46 @@ The "embossimage" script is more a demonstration script than a general purpose s |
|
|
|
|
|
As well as the built in Core Image filters I have added another filter for use with Moving Images. It is called YVSChromaKey and allows you to make parts of an image based on a selected color transparent. The filter has three inputs, a chroma key color "inputColor" which is defined as a CIVector, a distance number "inputDistance" which is distance in a color space within which the image is made fully transparent and a slope number "inputSlopeWidth" which is also a distance in a color space and this is the width of the slope. The smaller the width the steeper the slope.
|
|
|
|
|
|
cr = chroma color red component.
|
|
|
cg = chroma color green component.
|
|
|
cb = chroma color blue component.
|
|
|
|
|
|
pr = pixel color red component.
|
|
|
pg = pixel color green component.
|
|
|
pb = pixel color blue component.
|
|
|
|
|
|
redDiffSquared = (cr - pr) * (cr - pr)
|
|
|
greenDiffSquared = (cg - pg) * (cg - pg)
|
|
|
blueDiffSquared = (cb - pb) * (cb - pb)
|
|
|
colorDistance = sqrt(redDiffSquared + greenDiffSquared + blueDiffSquared)
|
|
|
|
|
|
In the following diagram the colorDistance is on the horizontal axis. Pixels with colors similar to the chroma color become transparent, whilst colors further away are either semi transparent or fully opaque.
|
|
|
|
|
|
![YVS Chroma Key diagram](../raw/master/wiki-images/yvschromakeyplot.png "A diagram showing how transparency changes with color distance from the chroma key color.")
|
|
|
|
|
|
The following shows a json object representation of the properties needed to
|
|
|
{
|
|
|
"cifiltername": "YVSChromaKey",
|
|
|
"mifiltername" : "com.yvs.documentation.renderingfilterchain.chromakey",
|
|
|
"cifilterproperties": [
|
|
|
{
|
|
|
"cifilterkey": "inputDistance",
|
|
|
"cifiltervalue": 0.08
|
|
|
},
|
|
|
{
|
|
|
"cifilterkey": "inputSlopeWidth",
|
|
|
"cifiltervalue": 0.06
|
|
|
},
|
|
|
{
|
|
|
"cifilterkey": "inputImage",
|
|
|
"cifiltervalueclass": "CIImage",
|
|
|
"cifiltervalue": {
|
|
|
"objectreference": 0
|
|
|
}
|
|
|
}
|
|
|
]
|
|
|
}
|
|
|
|
|
|
Like many core image filters, the YVSChromaKeyFilter can be part of a larger filter chain, including a filter chain of multiple YVSChromaKeyFilters. This allows transparency based on multiple chroma key colors to be achieved providing flexibility for creating transparency.
|
|
|
|
|
|
[Home](Home) | [Contents](Contents) | [Previous - Drawing in a Bitmap Context](DrawingInABitmapContext) | [Next - Image Metadata](ImageMetadata) |