public void CreateHistogram(Image<Bgr, Byte> img) { Image<Gray, Byte>[] channels = img.Split(); Image<Gray, Byte> blueChannel = channels[0]; Image<Gray, Byte> greenChannel = channels[1]; Image<Gray, Byte> redChannel = channels[2]; //Red colour channel DenseHistogram dhRed = new DenseHistogram(BIN_SIZE, new RangeF(0.0f, BIN_DEPTH)); dhRed.Calculate<Byte>(new Image<Gray, Byte>[1] { redChannel }, false, null); redChart.ClearHistogram(); redChart.AddHistogram("Red Channel", System.Drawing.Color.Red, dhRed); redChart.Refresh(); //Green colour Channel DenseHistogram dhGreen = new DenseHistogram(BIN_SIZE, new RangeF(0.0f, BIN_DEPTH)); dhGreen.Calculate<Byte>(new Image<Gray, Byte>[1] { greenChannel }, false, null); greenChart.ClearHistogram(); greenChart.AddHistogram("Green Channel", System.Drawing.Color.Green, dhGreen); greenChart.Refresh(); //Blue colour Channel DenseHistogram dhBlue = new DenseHistogram(BIN_SIZE, new RangeF(0.0f, BIN_DEPTH)); dhBlue.Calculate<Byte>(new Image<Gray, Byte>[1] { blueChannel }, false, null); blueChart.ClearHistogram(); blueChart.Show(); blueChart.AddHistogram("Blue Channel", System.Drawing.Color.Blue, dhBlue); blueChart.Refresh(); }
public static Image<Bgra, Byte> addAlphaToBgrImage(Image<Bgr, Byte> bgrImage, Image<Gray, Byte> alphaImage) { Image<Gray, Byte>[] channels = bgrImage.Split(); Image<Bgra, Byte> imageWithAlpha = new Image<Bgra,byte>(bgrImage.Width, bgrImage.Height); CvInvoke.cvMerge(channels[0], channels[1], channels[2], alphaImage, imageWithAlpha); for (int i = 0; i < 3; ++i) channels[i].Dispose(); return imageWithAlpha; }