/// <summary> /// Initializes a new instance of the <see cref="Image"/> class. /// </summary> /// <param name="configuration"> /// The configuration which allows altering default behaviour or extending the library. /// </param> /// <param name="pixelType">The <see cref="PixelTypeInfo"/>.</param> /// <param name="metadata">The <see cref="ImageMetadata"/>.</param> /// <param name="size">The <see cref="size"/>.</param> protected Image(Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, Size size) { this.configuration = configuration ?? Configuration.Default; this.PixelType = pixelType; this.size = size; this.Metadata = metadata ?? new ImageMetadata(); }
/// <summary> /// Initializes a new instance of the <see cref="ImageInfo"/> class. /// </summary> /// <param name="pixelType">The image pixel type information.</param> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="metadata">The images metadata.</param> public ImageInfo(PixelTypeInfo pixelType, int width, int height, ImageMetadata metadata) { this.PixelType = pixelType; this.Width = width; this.Height = height; this.Metadata = metadata; }
public IImageInfo Identify(Configuration configuration, Stream stream) { using (var sourceBitmap = new System.Drawing.Bitmap(stream)) { var pixelType = new PixelTypeInfo(System.Drawing.Image.GetPixelFormatSize(sourceBitmap.PixelFormat)); return(new ImageInfo(pixelType, sourceBitmap.Width, sourceBitmap.Height, new ImageMetaData())); } }
/// <summary> /// Initializes a new instance of the <see cref="Image"/> class. /// </summary> internal Image( Configuration configuration, PixelTypeInfo pixelType, ImageMetadata metadata, int width, int height) : this(configuration, pixelType, metadata, new Size(width, height)) { }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}" /> class /// with the height and the width of the image. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="metadata">The images metadata.</param> /// <param name="frames">The frames that will be owned by this image instance.</param> internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable <ImageFrame <TPixel> > frames) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, ValidateFramesAndGetSize(frames)) { ArrayPoolMemoryAllocator memoryAllocator = (ArrayPoolMemoryAllocator)this.GetConfiguration().MemoryAllocator; memoryAllocator.LockingOnThread(); this.Frames = new ImageFrameCollection <TPixel>(this, frames); memoryAllocator.Unlock(); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// with the height and the width of the image. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="metadata">The images metadata.</param> internal Image(Configuration configuration, int width, int height, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, width, height) { ArrayPoolMemoryAllocator memoryAllocator = (ArrayPoolMemoryAllocator)this.GetConfiguration().MemoryAllocator; memoryAllocator.LockingOnThread(); this.Frames = new ImageFrameCollection <TPixel>(this, width, height, default(TPixel)); memoryAllocator.Unlock(); }
public Bitmap BitmapFromClusterMap() { PixelTypeInfo pixelInfo = PixelInfo.GetPixelTypeInfo(clusterImage); Rectangle imageSize = new Rectangle(0, 0, clusterImage.Width, clusterImage.Height); BitmapData originalBitmapData = clusterImage.LockBits(imageSize, ImageLockMode.WriteOnly, clusterImage.PixelFormat); unsafe { byte *rowPtr = (byte *)originalBitmapData.Scan0; int pixelIndex = 0; for (int y = 0; y < originalBitmapData.Height; y++) { byte *pixelPtr = rowPtr; for (int x = 0; x < originalBitmapData.Width; x++) { int clusterNumber = ClusterMap[pixelIndex]; if (ViewType == ClusterViewTypes.Clusters) { int colorIndex = (clusterNumber % (colors.Length / 3)) * 3; pixelPtr[0] = colors[colorIndex + 0]; pixelPtr[1] = colors[colorIndex + 1]; pixelPtr[2] = colors[colorIndex + 2]; } else if (ViewType == ClusterViewTypes.PixelDistances) { byte d1 = LabDistances[pixelIndex * 4 + 0]; byte d2 = LabDistances[pixelIndex * 4 + 1]; byte d3 = LabDistances[pixelIndex * 4 + 2]; byte d4 = LabDistances[pixelIndex * 4 + 3]; byte sum = (byte)((d1 + d2 + d3 + d4) * 50); byte value = Math.Min(sum, byte.MaxValue); pixelPtr[0] = value; pixelPtr[1] = value; pixelPtr[2] = value; } else if (ViewType == ClusterViewTypes.Image) { pixelPtr[(int)RGBAColor.Red] = RGBPixels[pixelIndex * 3 + 0]; pixelPtr[(int)RGBAColor.Green] = RGBPixels[pixelIndex * 3 + 1]; pixelPtr[(int)RGBAColor.Blue] = RGBPixels[pixelIndex * 3 + 2]; } pixelIndex++; pixelPtr += 3; } rowPtr += originalBitmapData.Stride; } } clusterImage.UnlockBits(originalBitmapData); return(clusterImage); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// with the height and the width of the image. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="backgroundColor">The color to initialize the pixels with.</param> /// <param name="metadata">The images metadata.</param> internal Image( Configuration configuration, int width, int height, TPixel backgroundColor, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, width, height) { this.frames = new ImageFrameCollection <TPixel>(this, width, height, backgroundColor); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// wrapping an external <see cref="MemoryGroup{T}"/>. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="memoryGroup">The memory source.</param> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="metadata">The images metadata.</param> internal Image( Configuration configuration, MemoryGroup <TPixel> memoryGroup, int width, int height, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, width, height) { this.frames = new ImageFrameCollection <TPixel>(this, width, height, memoryGroup); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// with the height, the width and raw byte data of the image. /// </summary> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="RawData">The pixels byte data in Raw.</param> public Image(int width, int height, byte[] RawData) : base(Configuration.Default, PixelTypeInfo.Create <TPixel>(), new ImageMetadata(), width, height) { ArrayPoolMemoryAllocator memoryAllocator = (ArrayPoolMemoryAllocator)this.GetConfiguration().MemoryAllocator; memoryAllocator.LockingOnThread(); if (memoryAllocator != null) { memoryAllocator.RawData = RawData; } this.Frames = new ImageFrameCollection <TPixel>(this, width, height, default(TPixel)); memoryAllocator.RawData = null; memoryAllocator.Unlock(); }
private void ToLabPixels(Bitmap image) { PixelTypeInfo pixelInfo = PixelInfo.GetPixelTypeInfo(image); if (pixelInfo.GetBytesForColor(RGBAColor.RGB) != 1) { throw new Exception("Pixeltype is not supported."); } Rectangle imageSize = new Rectangle(0, 0, image.Width, image.Height); BitmapData originalBitmapData = image.LockBits(imageSize, ImageLockMode.ReadOnly, image.PixelFormat); unsafe { byte *rowPtr = (byte *)originalBitmapData.Scan0; int index = 0; for (int y = 0; y < originalBitmapData.Height; y++) { byte *pixelPtr = rowPtr; for (int x = 0; x < originalBitmapData.Width; x++) { RGBPixels[index + 0] = pixelPtr[(int)RGBAColor.Red]; RGBPixels[index + 1] = pixelPtr[(int)RGBAColor.Green]; RGBPixels[index + 2] = pixelPtr[(int)RGBAColor.Blue]; index += 3; pixelPtr += 3; } rowPtr += originalBitmapData.Stride; } } image.UnlockBits(originalBitmapData); if (UseGaussBlur) { gpuAccel.Invoke("GaussianBlur", 0, ImageWidth * ImageHeight, RGBPixels, GaussedRGBPixels, ImageWidth, ImageHeight); var t = RGBPixels; RGBPixels = GaussedRGBPixels; GaussedRGBPixels = t; } gpuAccel.Invoke("RGBToLab", 0, LabPixels.Length / 3, RGBPixels, LabPixels, 255f); gpuAccel.Invoke("LabDistances", 0, ImageWidth * ImageHeight, LabPixels, LabDistances, ImageWidth, ImageHeight, MaxColorDistanceForMatch); if (UseNoiseRemoval) { gpuAccel.Invoke("RemoveNoise", 0, ImageWidth * ImageHeight, LabDistances, ImageWidth, ImageHeight); } }
public void ImageInfoInitializesCorrectly() { const int Width = 50; const int Height = 60; var size = new Size(Width, Height); var rectangle = new Rectangle(0, 0, Width, Height); var pixelType = new PixelTypeInfo(8); var meta = new ImageMetadata(); var info = new ImageInfo(pixelType, Width, Height, meta); Assert.Equal(pixelType, info.PixelType); Assert.Equal(Width, info.Width); Assert.Equal(Height, info.Height); Assert.Equal(size, info.Size()); Assert.Equal(rectangle, info.Bounds()); Assert.Equal(meta, info.Metadata); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// with the height and the width of the image. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="width">The width of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param> /// <param name="metadata">The images metadata.</param> internal Image(Configuration configuration, int width, int height, ImageMetadata metadata) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, width, height) { this.frames = new ImageFrameCollection <TPixel>(this, width, height, default(TPixel)); }
/// <summary> /// Initializes a new instance of the <see cref="Image{TPixel}" /> class /// with the height and the width of the image. /// </summary> /// <param name="configuration">The configuration providing initialization code which allows extending the library.</param> /// <param name="metadata">The images metadata.</param> /// <param name="frames">The frames that will be owned by this image instance.</param> internal Image(Configuration configuration, ImageMetadata metadata, IEnumerable <ImageFrame <TPixel> > frames) : base(configuration, PixelTypeInfo.Create <TPixel>(), metadata, ValidateFramesAndGetSize(frames)) { this.frames = new ImageFrameCollection <TPixel>(this, frames); }
public Image(IBitmap bitmap, int width, int height, int bitsPerPixel) { this.Bitmap = bitmap; this.PixelTypeInfo = new PixelTypeInfo(bitsPerPixel); }