public IObservable <Mat> Process(IObservable <Mat> source) { return(source.Select(input => { if (input.Rows > 1) { throw new InvalidOperationException("The input buffer must have a single channel."); } var bitbuffer = new Mat(input.ElementSize * 8, input.Cols, input.Depth, 1); for (int i = 0; i < bitbuffer.Rows; i++) { using (var row = bitbuffer.GetRow(i)) { CV.AndS(input, Scalar.Real(1 << i), row); } } var output = input.Depth != Depth.U8 ? new Mat(bitbuffer.Size, Depth.U8, 1) : bitbuffer; if (output != bitbuffer) { CV.CmpS(bitbuffer, 0, output, ComparisonOperation.NotEqual); } CV.Threshold(output, output, 1, 1, ThresholdTypes.Truncate); return output; })); }