public static I <byte> ToU8(this IImageBuffer source) { if (source == null) { throw new ArgumentNullException("buffer"); } var t0 = source as I <byte>; if (t0 != null) { return(t0); } var t1 = source as I <float>; if (t1 != null) { return(t1.ToU8()); } else { var t2 = source as I <Rgb24>; if (t2 != null) { return(I.FromBytes <byte>(t2.ToByteArray(), t2.Height, t2.Width, PixelFormat.RgbU8)); } } throw new NotSupportedException(string.Format("Conversion routine from buffer image format to 8 bit per channel is missing (buffer pixel format: was {0}).", source.Format)); }
protected override void SetOutputsInternal(params object[] outputs) { var supportedOutput = outputs .OfType <IImageBuffer>() .FirstOrDefault(); if (this.IgnoreEmptyOutputs && supportedOutput == null) { return; } lock (gate) { if (this.previewImage != null) { this.previewImage.Dispose(); this.previewImage = null; } if (supportedOutput != null) { this.previewImage = this.RenderThumbnail(supportedOutput); } } IsDirty = true; }
public I <float> Crop( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] IntRect area ) { return(image.ToF32().Crop(area)); }
public I <float> Filter( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] double weight ) { return(image.ToF32().FastDoGFilter(weight)); }
public void Draw(IImageBuffer imageBuffer, Point? start = null) { Point p = start.HasValue ? start.Value : new Point(0, 0); Size size = imageBuffer.Size.BestFitWithin(p, _size); imageBuffer = new ImageBufferRegion(imageBuffer, p, size); _renderStrategy.Render(this, imageBuffer); }
public IImageBuffer RenderThumbnail(IImageBuffer image) { IImageBuffer resizedImage = null; if (image.Width == 0 || image.Height == 0) { return(I.CreateRgbF32(0, 0)); } Int2 size; IntRect cropRect; base.CalculateNewSize(new Int2(image.Width, image.Height), this.DesiredSize, out size, out cropRect); if (image.Width <= size.X && image.Height <= size.Y) { return(image); } resizedImage = image.ToF32().Resize(size, cropRect, ResizeFilterType.Quadratic); var f32image = resizedImage as I <float>; if (f32image != null) { return(f32image.ToU8()); } return(resizedImage); }
public int[][] CreateHistogramm( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int bins ) { return(image.ToF32().CreateHistogram(bins)); }
public I <float> Equalize( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int bins ) { return(image.ToF32().HistogramEqualization(bins)); }
public static I <float> ToF32(this IImageBuffer source) { if (source == null) { throw new ArgumentNullException("buffer"); } var t0 = source as I <float>; if (t0 != null) { return(t0); } var t1 = source as I <byte>; if (t1 != null) { return(t1.ToF32()); } var t2 = source as I <Rgb24>; if (t2 != null) { return(t2.ToRgbF32()); } throw new NotSupportedException(string.Format("Conversion routine from buffer image format to 32 bit per channel is missing (buffer pixel format: was {0}).", source.Format)); }
public int[] CreateChannelHistogram( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int bins, [InputPin(PropertyMode = PropertyMode.Default)] int channel ) { return(image.ToF32().CreateChannelHistogram(bins, channel)); }
public I <float> Equalize( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int channel, [InputPin(PropertyMode = PropertyMode.Default)] int bins ) { return(image.ToF32().EqualizeSingleChannel(channel, bins)); }
public I <float> Filter( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] double weight, [InputPin(PropertyMode = PropertyMode.Default)] double scaling ) { return(image.ToF32().FastDivisionFilter(weight, scaling)); }
public I <float> ConvertColor( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] ColorSpaceConversionType conversion ) { var converter = GetConverter(conversion); return(converter(image.ToF32())); }
public I <float> Filter( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int width, [InputPin(PropertyMode = PropertyMode.Default)] int height, [InputPin(PropertyMode = PropertyMode.Default)] ResizeFilterType resizeFilterType = ResizeFilterType.Lanczos8 ) { return(image.ToF32().Resize(new Int2(width, height), resizeFilterType)); }
public IEnumerable <I <float> > Split(IImageBuffer image) { var img = image.ToF32(); for (int c = 0; c < img.Channels; ++c) { yield return(img.GetChannel(c)); } }
public I <float> Filter( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int matrixSize, [InputPin(PropertyMode = PropertyMode.Default)] double weight, [InputPin(PropertyMode = PropertyMode.Default)] double scaling ) { return(image.ToF32().DivisionOfGaussianFilter(matrixSize, weight, scaling)); }
public void Resolve(IImageBuffer destination) { for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { destination[x, y] = ResolvePixel(x, y); } } }
public I <float> EqualizeAdaptive( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int bins, [InputPin(PropertyMode = PropertyMode.Default)] int numTilesY, [InputPin(PropertyMode = PropertyMode.Default)] int numTilesX, [InputPin(PropertyMode = PropertyMode.Default)] double normalizedClipLimit ) { return(image.ToF32().AdaptiveHistogramEqualization(bins, numTilesY, numTilesX, normalizedClipLimit)); }
public Mat ImageBufferToMat(IImageBuffer imageBuffer) { var i = imageBuffer.ToU8(); using (var pin = i.Pin()) { var mat = new Mat(i.Height, i.Width, PixelTypeToDepth[i.Format.PixelType], pin.Pointer); return(mat.Clone()); } }
public int[] CreateChannelHistogramOfRect( IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] int startRow, [InputPin(PropertyMode = PropertyMode.Default)] int startCol, [InputPin(PropertyMode = PropertyMode.Default)] int height, [InputPin(PropertyMode = PropertyMode.Default)] int width, [InputPin(PropertyMode = PropertyMode.Default)] int bins, [InputPin(PropertyMode = PropertyMode.Default)] int channel ) { return(image.ToF32().CreateChannelHistogramOfRect(startRow, startCol, height, width, bins, channel)); }
public ImageQuantizerViewModel(GeneralSettings generalSettings, IFileDialog fileDialog, IImageBuffer imageBuffer, IEnumerable <IColorQuantizer> quantizerList, ILogger logger) { _generalSettings = generalSettings; _imageBuffer = imageBuffer; _fileDialog = fileDialog; QuantizerList = quantizerList.ToList(); selectedQuantizer = QuantizerList[0]; selectedColorCount = ColorCountList[4]; OpenCommand = new DelegateCommand(LoadImageAndQuantize); SaveCommand = new DelegateCommand(DialogSaveImage); _logger = logger; }
public IImageBuffer[] SlidingWindow(IImageBuffer image, Int2 winSize, Int2 winStride) { var numCols = (image.Width - (winSize.X - winStride.X)) / winStride.X; var numRows = (image.Height - (winSize.Y - winStride.Y)) / winStride.Y; var windows = new IImageBuffer[numCols * numRows]; var i = 0; for (int row = 0; row <= image.Height - winSize.Y; row += winStride.Y) { for (int col = 0; col <= image.Width - winSize.X; col += winStride.X) { var rect = new IntRect(col, row, col + winSize.X, row + winSize.Y); windows[i] = cropProcessor.Crop(image, rect); i++; } } return(windows); }
public I <byte> ConvertDepth(IImageBuffer image) { return(image.ToU8()); }
public I <float> Filter(IImageBuffer image) { return(image.ToF32().CenteringAroundMean()); }
public void View([InputPin(PropertyMode = PropertyMode.Never)] IImageBuffer image) { this.PreviewGenerator.SetOutputs(image); }
public IImageBuffer Calculate(IImageBuffer image1, IImageBuffer image2) { return(I.Divide(image1.ToF32(), image2.ToF32())); }
public IImageBuffer Calculate(IImageBuffer image1, IImageBuffer image2) { return(I.Multiply(image1.ToF32(), image2.ToF32())); }
private IImageBuffer WrapBuffer(IImageBuffer buffer) { if (buffer == null) return null; return new ImageBufferRegion(buffer, _start, _size); }
public I <float> Saturate(IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] double saturationFactor = 0.01, [InputPin(PropertyMode = PropertyMode.Default)] int bins = 500) { return(image.ToF32().AutoSaturate(saturationFactor, bins)); }
public I <float> Process(IImageBuffer image, [InputPin(PropertyMode = PropertyMode.Default)] double[] stepSize) { return(image.ToF32().Quantization(stepSize)); }
public SKBitmap ImageBufferToSKBitmap(IImageBuffer imageBuffer) { if (imageBuffer == null) { return(null); } imageBuffer = imageBuffer.ToU8(); SKBitmap bitmap = null; SKColorSpace colorSpace = null; if (imageBuffer.Format.ColorSpace == ColorSpace.Srgb) { colorSpace = SKColorSpace.CreateSrgb(); } else if (imageBuffer.Format.ColorSpace == ColorSpace.LinearRgb) { colorSpace = SKColorSpace.CreateSrgbLinear(); } try { // for RGBA-images if (imageBuffer.Format.PixelType == PixelType.U8C3) { // convert to 32bpp var src = imageBuffer is I <byte>?((I <byte>)imageBuffer).Data.Buffer : imageBuffer.ToByteArray(); var dst = new byte[imageBuffer.Height * imageBuffer.Width * 4]; int i = 0, j = 0; while (i < dst.Length) { dst[i + 0] = src[j + 0]; dst[i + 1] = src[j + 1]; dst[i + 2] = src[j + 2]; dst[i + 3] = 0xff; i += 4; j += 3; } SKColorType colorType = SKColorType.Rgba8888; switch (imageBuffer.Format.PixelChannels) { case PixelChannels.Rgb: colorType = SKColorType.Rgba8888; break; case PixelChannels.Bgra: colorType = SKColorType.Bgra8888; break; } using (var pinnedImage = new Utilities.PinnedGCHandle(dst)) { var sourceInfo = new SKImageInfo(imageBuffer.Width, imageBuffer.Height, colorType, SKAlphaType.Opaque); if (colorSpace != null) { sourceInfo.ColorSpace = colorSpace; } bitmap = new SKBitmap(); Debug.Assert(sourceInfo.RowBytes == imageBuffer.Width * 4); if (!bitmap.InstallPixels(sourceInfo, pinnedImage.Pointer)) { throw new Exception("InstallPixels poperation of Skia bitmap failed."); } } } // for RGBA-images else if (imageBuffer.Format.PixelType == PixelType.U8C4) { // try direct copy using (var pinnedImage = imageBuffer.Pin()) { SKAlphaType alphaType = SKAlphaType.Unknown; SKColorType colorType = SKColorType.Rgba8888; switch (imageBuffer.Format.PixelChannels) { case PixelChannels.Rgbx: alphaType = SKAlphaType.Opaque; colorType = SKColorType.Rgba8888; break; case PixelChannels.Rgba: alphaType = SKAlphaType.Unpremul; colorType = SKColorType.Rgba8888; break; case PixelChannels.Bgrx: alphaType = SKAlphaType.Opaque; colorType = SKColorType.Bgra8888; break; case PixelChannels.Bgra: alphaType = SKAlphaType.Unpremul; colorType = SKColorType.Bgra8888; break; } var sourceInfo = new SKImageInfo(imageBuffer.Width, imageBuffer.Height, colorType, alphaType); Debug.Assert(sourceInfo.RowBytes == imageBuffer.Width * 4); if (colorSpace != null) { sourceInfo.ColorSpace = colorSpace; } bitmap = new SKBitmap(); if (!bitmap.InstallPixels(sourceInfo, pinnedImage.Pointer)) { throw new Exception("InstallPixels poperation of Skia bitmap failed."); } } } // for gray-scale else if (imageBuffer.Format.PixelType == PixelType.U8C1) { // try direct copy using (var pinnedImage = imageBuffer.Pin()) { var sourceInfo = new SKImageInfo(imageBuffer.Width, imageBuffer.Height, SKColorType.Gray8); Debug.Assert(sourceInfo.RowBytes == imageBuffer.Width); bitmap = new SKBitmap(); if (!bitmap.InstallPixels(sourceInfo, pinnedImage.Pointer)) { throw new Exception("InstallPixels poperation of Skia bitmap failed."); } } } else { throw new Exception("PixelFormat not yet implemented for preview image."); } SKBitmap result = bitmap; bitmap = null; colorSpace = null; return(result); } finally { if (bitmap != null) { bitmap.Dispose(); if (colorSpace != null) { colorSpace.Dispose(); } } } }
public I <float> ConvertDepth(IImageBuffer image) { return(image.ToF32()); }