/// <summary>
        /// Copy constructor that clones the other WritableLockbitImage. This will clone all
        /// of the internal data from the passed in WritableLockBitImage, with the exception
        /// of whether it was locked.
        /// </summary>
        public WritableLockBitImage(WritableLockBitImage other)
        {
            _bitDepth = Image.GetPixelFormatSize(other.PixelFormat);
            if (_bitDepth != 8 && _bitDepth != 24 && _bitDepth != 32)
            {
                throw new ArgumentException("Only 8, 24, and 32 bit pixels are supported.");
            }
            _width      = other.Width;
            _height     = other.Height;
            _disposed   = _locked = false;
            _bitmap     = new Bitmap(Width, Height);
            _bitmapData = _bitmap.LockBits(new Rectangle(0, 0, Width, Height),
                                           ImageLockMode.ReadWrite,
                                           other.PixelFormat
                                           );

            // Copy over bitmap data manually
            for (int row = 0; row < Height; row++)
            {
                for (int col = 0; col < Width; col++)
                {
                    SetPixel(col, row, other.GetPixel(col, row));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Calculate the SSIM between two IImageFrames
        /// </summary>
        /// <param name="first">The first image</param>
        /// <param name="second">The second image</param>
        /// <returns>The SSIM of two IImageFrames</returns>
        public static double Compute(WritableLockBitImage first, WritableLockBitImage second)
        {
            if (first == null || second == null)
            {
                throw new ArgumentNullException();
            }

            return(ComputeSSIM(
                       ConvertToGrayscale(first),
                       ConvertToGrayscale(second)
                       ));
        }