// ========================================================= // Module: OR_GATE // // Description: Apply Boolean OR Gate for 2 images' channel(s) // 1) parameter: threshold // set threshold function to convert data to binary for boolean logic. // Truth table // 1 1 = 1 // 1 0 = 1 // 0 1 = 1 // 0 0 = 0 // 2) parameter: channel // set channel to apply OR gate logic. // 4: RGB mean // 3: Alpha channel // 0: Red channel // 1: Green channel // 2: Blue channel // // Author(s): CT Yeung (cty) // // History: // 26Nov09 1st implementation cty // ========================================================= kernel OR_GATE < namespace : "CT Yeung"; vendor : ""; version : 1; description : "OR Gate for 2 images' channel(s)"; > { // grayscale threshold value parameter float threshold < minValue: 0.0; maxValue: 1.0; defaultValue: .5; >; // channel to use parameter int channel < minValue: 0; maxValue: 4; defaultValue: 0; >; input image4 src1; input image4 src2; output pixel4 dst; void evaluatePixel() { float4 inClr1 = sampleNearest(src1, outCoord()); float4 inClr2 = sampleNearest(src2, outCoord()); if(channel == 4) { // 4: RGB mean float src1Mean = (inClr1.r + inClr1.g + inClr1.b)/3.0; float src2Mean = (inClr2.r + inClr2.g + inClr2.b)/3.0; if((src1Mean >= threshold ) || (src2Mean >= threshold)) { inClr1 = inClr2; } } else { // 3: Alpha channel // 0: Red channel // 1: Green channel // 2: Blue channel if(channel == 0) { if( (inClr1[0] >= threshold)|| (inClr2[0] >= threshold)) { inClr1[0] = inClr2[0]; } } else if(channel == 1) { if( (inClr1[1] >= threshold)|| (inClr2[1] >= threshold)) { inClr1[1] = inClr2[1]; } } else if(channel == 2) { if( (inClr1[2] >= threshold)|| (inClr2[2] >= threshold)) { inClr1[2] = inClr2[2]; } } else if(channel == 3) { if( (inClr1[3] >= threshold)|| (inClr2[3] >= threshold)) { inClr1[3] = inClr2[3]; } } } dst = inClr1; } }