// Standard public CWatchImage(string name, int index, IMagickImage magickImage, double metricUpperBound) { Name = name; Index = index; MagickImage = magickImage; HasAlpha = MagickImage != null && MagickImage.HasAlpha; TransparencyRate = MagickImage != null?MagickImage.GetTransparencyRate() : 0; AlphaChannel = null; MetricUpperBound = metricUpperBound; _PauseTicks = DateTime.MinValue.Ticks; if (HasAlpha) { // Does Separate() clone the channels? If so, does it dispose of them during this? var tmpMi = MagickImage.Separate().Last().Clone(); tmpMi.Negate(); AlphaChannel = new MagickImage(_AlphaReplacement, MagickImage.Width, MagickImage.Height); AlphaChannel.Composite(tmpMi, CompositeOperator.CopyAlpha); AlphaChannel.RePage(); tmpMi.Dispose(); MagickImage.ColorAlpha(_AlphaReplacement); MagickImage.RePage(); } }
private static double GetRatio(IMagickImage image, Channels channel, IMagickImage mask, double maskMean) { using (IMagickImage channelImage = image.Separate(channel).First()) { channelImage.Composite(mask, CompositeOperator.Multiply); var channelMean = GetMean(channelImage); var average = 100 * channelMean / maskMean; return(100 / average); } }
// May need to update to support multiple channels. private static IMagickImage GetComposedImage(IMagickImage input, int channelIndex) { IMagickImage mi = input.Clone(); if (channelIndex > -1) { mi = mi.Separate().ToArray()[channelIndex]; } return(mi); }