当前位置: 首页>>代码示例>>C#>>正文


C# UnmanagedImage类代码示例

本文整理汇总了C#中UnmanagedImage的典型用法代码示例。如果您正苦于以下问题:C# UnmanagedImage类的具体用法?C# UnmanagedImage怎么用?C# UnmanagedImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UnmanagedImage类属于命名空间,在下文中一共展示了UnmanagedImage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        /// 
        protected override unsafe void ProcessFilter( UnmanagedImage sourceData, UnmanagedImage destinationData )
        {
            // get source image size
            int width   = sourceData.Width;
            int height  = sourceData.Height;

            int pixelSize = Image.GetPixelFormatSize( sourceData.PixelFormat ) / 8;
            int srcStride = sourceData.Stride;
            int dstStride = destinationData.Stride;
            double xFactor = (double) width / newWidth;
            double yFactor = (double) height / newHeight;

            // do the job
            byte* baseSrc = (byte*) sourceData.ImageData.ToPointer( );
            byte* baseDst = (byte*) destinationData.ImageData.ToPointer( );

            // for each line
            for ( int y = 0; y < newHeight; y++ )
            {
                byte* dst = baseDst + dstStride * y;
                byte* src = baseSrc + srcStride * ( (int) ( y * yFactor ) );
                byte* p;

                // for each pixel
                for ( int x = 0; x < newWidth; x++ )
                {
                    p = src + pixelSize * ( (int) ( x * xFactor ) );

                    for ( int i = 0; i < pixelSize; i++, dst++, p++ )
                    {
                        *dst = *p;
                    }
                }
            }
        }
开发者ID:EnergonV,项目名称:BestCS,代码行数:42,代码来源:ResizeNearestNeighbor.cs

示例2: ProcessFilter

        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// 
        protected unsafe override void ProcessFilter(UnmanagedImage image)
        {
            int width = image.Width;
            int height = image.Height;

            int pixelSize = System.Drawing.Image.GetPixelFormatSize(image.PixelFormat) / 8;
            int stride = image.Stride;
            int offset = stride - image.Width * pixelSize;

            byte* src = (byte*)image.ImageData.ToPointer();

            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++, src += pixelSize)
                {
                    double sum = src[RGB.R] + src[RGB.G] + src[RGB.B];
                    sum = sum == 0 ? 1 : sum;

                    double red = src[RGB.R] / sum;
                    double green = src[RGB.G] / sum;
                    double blue = 1 - red - green;

                    src[RGB.R] = (byte)(red * 255);
                    src[RGB.G] = (byte)(green * 255);
                    src[RGB.B] = (byte)(blue * 255);
                }
                src += offset;
            }
        }
开发者ID:accord-net,项目名称:framework,代码行数:35,代码来源:RGChromacity.cs

示例3: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        /// 
        protected override unsafe void ProcessFilter( UnmanagedImage sourceData, UnmanagedImage destinationData )
        {
            // get width and height
            int width = sourceData.Width;
            int height = sourceData.Height;

            int srcOffset = sourceData.Stride - width;
            int dstOffset = destinationData.Stride - width * 3;

            // do the job
            byte * src = (byte*) sourceData.ImageData.ToPointer( );
            byte * dst = (byte*) destinationData.ImageData.ToPointer( );

            // for each line
            for ( int y = 0; y < height; y++ )
            {
                // for each pixel
                for ( int x = 0; x < width; x++, src++, dst += 3 )
                {
                    dst[RGB.R] = dst[RGB.G] = dst[RGB.B] = *src;
                }
                src += srcOffset;
                dst += dstOffset;
            }
        }
开发者ID:Kenneth-Posey,项目名称:aforge-clone,代码行数:32,代码来源:GrayscaleToRGB.cs

示例4: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            int pixelSize = ( image.PixelFormat == PixelFormat.Format24bppRgb ) ? 3 : 4;

            int startX  = rect.Left;
            int startY  = rect.Top;
            int stopX   = startX + rect.Width;
            int stopY   = startY + rect.Height;
            int offset  = image.Stride - rect.Width * pixelSize;

            // do the job
            byte* ptr = (byte*) image.ImageData.ToPointer( );
            byte t;

            // allign pointer to the first pixel to process
            ptr += ( startY * image.Stride + startX * pixelSize );

            // for each line
            for ( int y = startY; y < stopY; y++ )
            {
                // for each pixel
                for ( int x = startX; x < stopX; x++, ptr += pixelSize )
                {
                    // rotate colors of each pixel
                    t = ptr[RGB.R];
                    ptr[RGB.R] = ptr[RGB.G];
                    ptr[RGB.G] = ptr[RGB.B];
                    ptr[RGB.B] = t;
                }
                ptr += offset;
            }
        }
开发者ID:alexcmd,项目名称:CascadeTrainingTool,代码行数:39,代码来源:RotateChannels.cs

示例5: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            int pixelSize = ( ( image.PixelFormat == PixelFormat.Format8bppIndexed ) ||
                              ( image.PixelFormat == PixelFormat.Format16bppGrayScale ) ) ? 1 : 3;

            int startY  = rect.Top;
            int stopY   = startY + rect.Height;

            int startX  = rect.Left * pixelSize;
            int stopX   = startX + rect.Width * pixelSize;

            byte* basePtr = (byte*) image.ImageData.ToPointer( );

            if (
                ( image.PixelFormat == PixelFormat.Format8bppIndexed ) ||
                ( image.PixelFormat == PixelFormat.Format24bppRgb ) )
            {
                int offset = image.Stride - ( stopX - startX );

                // allign pointer to the first pixel to process
                byte* ptr = basePtr + ( startY * image.Stride + rect.Left * pixelSize );

                // invert
                for ( int y = startY; y < stopY; y++ )
                {
                    for ( int x = startX; x < stopX; x++, ptr++ )
                    {
                        // ivert each pixel
                        *ptr = (byte) ( 255 - *ptr );
                    }
                    ptr += offset;
                }
            }
            else
            {
                int stride = image.Stride;

                // allign pointer to the first pixel to process
                basePtr += ( startY * image.Stride + rect.Left * pixelSize * 2 );

                // invert
                for ( int y = startY; y < stopY; y++ )
                {
                    ushort* ptr = (ushort*) ( basePtr );

                    for ( int x = startX; x < stopX; x++, ptr++ )
                    {
                        // ivert each pixel
                        *ptr = (ushort) ( 65535 - *ptr );
                    }
                    basePtr += stride;
                }
            }
        }
开发者ID:alexcmd,项目名称:CascadeTrainingTool,代码行数:61,代码来源:Invert.cs

示例6: ProcessFilter

        /// <summary>
        ///   Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        ///
        protected override void ProcessFilter(UnmanagedImage sourceData, UnmanagedImage destinationData)
        {
            // Lock the overlay image (left image)
            BitmapData overlayData = overlayImage.LockBits(
                new Rectangle(0, 0, overlayImage.Width, overlayImage.Height),
                ImageLockMode.ReadOnly, overlayImage.PixelFormat);

            int dstHeight = destinationData.Height;
            int src1Height = overlayData.Height;
            int src2Height = sourceData.Height;

            int src1Stride = overlayData.Stride;
            int src2Stride = sourceData.Stride;
            int dstStride = destinationData.Stride;

             int pixelSize = System.Drawing.Image.GetPixelFormatSize(sourceData.PixelFormat) / 8;
             int copySize1 = overlayData.Width * pixelSize;
             int copySize2 = sourceData.Width * pixelSize;

            // do the job
            unsafe
            {
                byte* src1 = (byte*)overlayData.Scan0.ToPointer();
                byte* src2 = (byte*)sourceData.ImageData.ToPointer();
                byte* dst = (byte*)destinationData.ImageData.ToPointer();

                // for each line
                for (int y = 0; y < dstHeight; y++)
                {
                    if (y < src1Height)
                        Accord.SystemTools.CopyUnmanagedMemory(dst, src1, copySize1);
                    if (y < src2Height)
                        Accord.SystemTools.CopyUnmanagedMemory(dst + copySize1, src2, copySize2);
                    
                    src1 += src1Stride;
                    src2 += src2Stride;
                    dst += dstStride;
                }
            }

            // Release
            overlayImage.UnlockBits(overlayData);
        }
开发者ID:accord-net,项目名称:framework,代码行数:50,代码来源:Concatenate.cs

示例7: Apply

 /// <summary>
 /// Apply filter to an image (not implemented).
 /// </summary>
 /// 
 /// <param name="sourceImage">Source image to be processed.</param>
 /// <param name="destinationImage">Destination image to store filter's result.</param>
 /// 
 /// <exception cref="NotImplementedException">The method is not implemented.</exception>
 /// 
 public void Apply( UnmanagedImage sourceImage, UnmanagedImage destinationImage )
 {
     throw new NotImplementedException( "The method is not implemented filter." );
 }
开发者ID:CanerPatir,项目名称:framework,代码行数:13,代码来源:ExtractBiggestBlob.cs

示例8: ApplyBGGR

        private unsafe void ApplyBGGR( UnmanagedImage sourceData, UnmanagedImage destinationData )
        {
            int width  = sourceData.Width;
            int height = sourceData.Height;

            int widthM1  = width - 1;
            int heightM1 = height - 1;

            int srcStride = sourceData.Stride;
            int dstStride = destinationData.Stride;

            int srcStrideP1  = srcStride + 1;
            int srcStrideM1  = srcStride - 1;
            int srcMStride   = -srcStride;
            int srcMStrideP1 = srcMStride + 1;
            int srcMStrideM1 = srcMStride - 1;

            int srcOffset = srcStride - width;
            int dstOffset = dstStride - width * 3;

            // do the job
            byte * src = (byte*) sourceData.ImageData.ToPointer( );
            byte * dst = (byte*) destinationData.ImageData.ToPointer( );

            // --- process the first line

            // . . .
            // . B G 
            // . G R
            dst[RGB.R] = src[srcStrideP1];
            dst[RGB.G] = (byte) ( ( src[1] + src[srcStride] ) >> 1 );
            dst[RGB.B] = *src;

            src++;
            dst += 3;

            for ( int x = 1; x < widthM1; x += 2 )
            {
                // . . .
                // B G B 
                // G R G
                dst[RGB.R] = src[srcStride];
                dst[RGB.G] = (byte) ( ( *src + src[srcStrideM1] + src[srcStrideP1] ) / 3 );
                dst[RGB.B] = (byte) ( ( src[-1] + src[1] ) >> 1 );

                src++;
                dst += 3;

                // . . .
                // G B G
                // R G R
                dst[RGB.R] = (byte) ( ( src[srcStrideM1] + src[srcStrideP1] ) >> 1 );
                dst[RGB.G] = (byte) ( ( src[-1] + src[srcStride] + src[1] ) / 3 );
                dst[RGB.B] = *src;

                src++;
                dst += 3;
            }

            // . . .
            // B G . 
            // G R . 
            dst[RGB.R] = src[srcStride];
            dst[RGB.G] = (byte) ( ( *src + src[srcStrideM1] ) >> 1 );
            dst[RGB.B] = src[-1];


            // allign to the next line
            src += srcOffset + 1;
            dst += dstOffset + 3;

            // --- process all lines except the first one and the last one
            for ( int y = 1; y < heightM1; y += 2 )
            {
                // . B G 
                // . G R
                // . B G
                dst[RGB.R] = src[1];
                dst[RGB.G] = (byte) ( ( src[srcMStrideP1] + src[srcStrideP1] + *src ) / 3 );
                dst[RGB.B] = (byte) ( ( src[srcMStride] + src[srcStride] ) >> 1 );

                dst += dstStride;
                src += srcStride;

                // ( y+1 pixel )
                // . G R
                // . B G
                // . G R
                dst[RGB.R] = (byte) ( ( src[srcMStrideP1] + src[srcStrideP1] ) >> 1 );
                dst[RGB.G] = (byte) ( ( src[1] + src[srcMStride] + src[srcStride] ) / 3 );
                dst[RGB.B] = *src;

                dst -= dstStride;
                src -= srcStride;

                src++;
                dst += 3;

                for ( int x = 1; x < widthM1; x += 2 )
                {
//.........这里部分代码省略.........
开发者ID:centrolutions,项目名称:AForge.NET,代码行数:101,代码来源:BayerFilterOptimized.cs

示例9: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image )
        {
            int width  = image.Width;
            int height = image.Height;

            // 1 - invert the source image
            Invert invertFilter = new Invert( );
            UnmanagedImage invertedImage = invertFilter.Apply( image );

            // 2 - use blob counter to find holes (they are white objects now on the inverted image)
            BlobCounter blobCounter = new BlobCounter( );
            blobCounter.ProcessImage( invertedImage );
            Blob[] blobs = blobCounter.GetObjectsInformation( );

            // 3 - check all blobs and determine which should be filtered
            byte[] newObjectColors = new byte[blobs.Length + 1];
            newObjectColors[0] = 255; // don't touch the objects, which have 0 ID

            for ( int i = 0, n = blobs.Length; i < n; i++ )
            {
                Blob blob = blobs[i];

                if ( ( blob.Rectangle.Left == 0 ) || ( blob.Rectangle.Top == 0 ) ||
                     ( blob.Rectangle.Right == width ) || ( blob.Rectangle.Bottom == height ) )
                {
                    newObjectColors[blob.ID] = 0;
                }
                else
                {
                    if ( ( ( coupledSizeFiltering ) && ( blob.Rectangle.Width <= maxHoleWidth ) && ( blob.Rectangle.Height <= maxHoleHeight ) ) |
                         ( ( !coupledSizeFiltering ) && ( ( blob.Rectangle.Width <= maxHoleWidth ) || ( blob.Rectangle.Height <= maxHoleHeight ) ) ) )
                    {
                        newObjectColors[blob.ID] = 255;
                    }
                    else
                    {
                        newObjectColors[blob.ID] = 0;
                    }
                }
            }

            // 4 - process the source image image and fill holes
            byte* ptr = (byte*) image.ImageData.ToPointer( );
            int offset = image.Stride - width;

            int[] objectLabels = blobCounter.ObjectLabels;

            for ( int y = 0, i = 0; y < height; y++ )
            {
                for ( int x = 0; x < width; x++, i++, ptr++ )
                {
                    *ptr = newObjectColors[objectLabels[i]];
                }
                ptr += offset;
            }
        }
开发者ID:Kenneth-Posey,项目名称:aforge-clone,代码行数:62,代码来源:FillHoles.cs

示例10: Apply

        /// <summary>
        /// Apply filter to an image in unmanaged memory.
        /// </summary>
        /// 
        /// <param name="image">Source image in unmanaged memory to apply filter to.</param>
        /// 
        /// <returns>Returns filter's result obtained by applying the filter to
        /// the source image.</returns>
        /// 
        /// <remarks>The method keeps the source image unchanged and returns
        /// the result of image processing filter as new image.</remarks>
        /// 
        /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image.</exception>
        ///
        public UnmanagedImage Apply( UnmanagedImage image )
        {
            UnmanagedImage destImage = errosion.Apply( image );
            dilatation.ApplyInPlace( destImage );

            return destImage;
        }
开发者ID:CanerPatir,项目名称:framework,代码行数:21,代码来源:Opening.cs

示例11: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        /// 
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            // calculate threshold for the given image
            thresholdFilter.ThresholdValue = CalculateThreshold( image, rect );

            // thresholding
            thresholdFilter.ApplyInPlace( image, rect );
        }
开发者ID:EnergonV,项目名称:BestCS,代码行数:15,代码来源:OtsuThreshold.cs

示例12: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="image">Source image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        ///
        protected override unsafe void ProcessFilter( UnmanagedImage image, Rectangle rect )
        {
            int pixelSize = Image.GetPixelFormatSize( image.PixelFormat ) / 8;

            // processing start and stop X,Y positions
            int startX  = rect.Left;
            int startY  = rect.Top;
            int stopX   = startX + rect.Width;
            int stopY   = startY + rect.Height;
            int offset  = image.Stride - rect.Width * pixelSize;

            // do the job
            byte* ptr = (byte*) image.ImageData.ToPointer( );

            // allign pointer to the first pixel to process
            ptr += ( startY * image.Stride + startX * pixelSize );

            if ( image.PixelFormat == PixelFormat.Format8bppIndexed )
            {
                // grayscale image
                for ( int y = startY; y < stopY; y++ )
                {
                    for ( int x = startX; x < stopX; x++, ptr++ )
                    {
                        // gray
                        *ptr = mapGreen[*ptr];
                    }
                    ptr += offset;
                }
            }
            else
            {
                // RGB image
                for ( int y = startY; y < stopY; y++ )
                {
                    for ( int x = startX; x < stopX; x++, ptr += pixelSize )
                    {
                        // red
                        ptr[RGB.R] = mapRed[ptr[RGB.R]];
                        // green
                        ptr[RGB.G] = mapGreen[ptr[RGB.G]];
                        // blue
                        ptr[RGB.B] = mapBlue[ptr[RGB.B]];
                    }
                    ptr += offset;
                }
            }
        }
开发者ID:RevDevBev,项目名称:aforge.net,代码行数:55,代码来源:LevelsLinear.cs

示例13: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="source">Source image data.</param>
        /// <param name="destination">Destination image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        /// 
        protected override unsafe void ProcessFilter( UnmanagedImage source, UnmanagedImage destination, Rectangle rect )
        {
            int kernelHalf = kernelSize / 2;

            InitFilter( );

            if ( ( rect.Width <= kernelSize ) || ( rect.Height <= kernelSize ) )
            {
                ProcessWithEdgeChecks( source, destination, rect );
            }
            else
            {
                Rectangle safeArea = rect;
                safeArea.Inflate( -kernelHalf, -kernelHalf );

                if ( ( Environment.ProcessorCount > 1 ) && ( enableParallelProcessing ) )
                {
                    ProcessWithoutChecksParallel( source, destination, safeArea );
                }
                else
                {
                    ProcessWithoutChecks( source, destination, safeArea );
                }

                // top
                ProcessWithEdgeChecks( source, destination,
                    new Rectangle( rect.Left, rect.Top, rect.Width, kernelHalf ) );
                // bottom
                ProcessWithEdgeChecks( source, destination,
                    new Rectangle( rect.Left, rect.Bottom - kernelHalf, rect.Width, kernelHalf ) );
                // left
                ProcessWithEdgeChecks( source, destination,
                    new Rectangle( rect.Left, rect.Top + kernelHalf, kernelHalf, rect.Height - kernelHalf * 2 ) );
                // right
                ProcessWithEdgeChecks( source, destination,
                    new Rectangle( rect.Right - kernelHalf, rect.Top + kernelHalf, kernelHalf, rect.Height - kernelHalf  * 2 ) );
            }
        }
开发者ID:centrolutions,项目名称:AForge.NET,代码行数:46,代码来源:BilateralSmoothing.cs

示例14: ProcessWithoutChecksParallel

        // Perform parallel image processing without checking pixels' coordinates to make sure those are in bounds
        private unsafe void ProcessWithoutChecksParallel( UnmanagedImage source, UnmanagedImage destination, Rectangle rect )
        {
            int startX = rect.Left;
            int startY = rect.Top;
            int stopX  = rect.Right;
            int stopY  = rect.Bottom;

            int pixelSize = System.Drawing.Image.GetPixelFormatSize( source.PixelFormat ) / 8;
            int kernelHalf = kernelSize / 2;
            int bytesInKernelRow = kernelSize * pixelSize;

            int srcStride = source.Stride;
            int dstStride = destination.Stride;

            int srcOffset = srcStride - rect.Width * pixelSize;
            int dstOffset = dstStride - rect.Width * pixelSize;

            // offset of the first kernel's pixel
            int srcKernelFistPixelOffset = kernelHalf * ( srcStride + pixelSize );
            // offset to move to the next kernel's pixel after processing one kernel's row
            int srcKernelOffset = srcStride - bytesInKernelRow;

            byte* srcBase = (byte*) source.ImageData.ToPointer( );
            byte* dstBase = (byte*) destination.ImageData.ToPointer( );

            // allign pointers to the left most pixel in the first row
            srcBase += startX * pixelSize;
            dstBase += startX * pixelSize;

            if ( pixelSize > 1 )
            {
                Parallel.For( startY, stopY, delegate( int y )
                {
                    byte* src = srcBase + y * srcStride;
                    byte* dst = dstBase + y * dstStride;

                    byte srcR, srcG, srcB;
                    byte srcR0, srcG0, srcB0;
                    byte* srcPixel;

                    int tx, ty;

                    double sCoefR, sCoefG, sCoefB, sMembR, sMembG, sMembB, coefR, coefG, coefB;

                    for ( int x = startX; x < stopX; x++, src += pixelSize, dst += pixelSize )
                    {
                        // lower right corner - to start processing from that point
                        srcPixel = src + srcKernelFistPixelOffset;

                        sCoefR = 0;
                        sCoefG = 0;
                        sCoefB = 0;
                        sMembR = 0;
                        sMembG = 0;
                        sMembB = 0;

                        srcR0 = src[RGB.R];
                        srcG0 = src[RGB.G];
                        srcB0 = src[RGB.B];

                        // move from lower right to upper left corner
                        ty = kernelSize;
                        while ( ty != 0 )
                        {
                            ty--;

                            tx = kernelSize;
                            while ( tx != 0 )
                            {
                                tx--;

                                srcR = srcPixel[RGB.R];
                                srcG = srcPixel[RGB.G];
                                srcB = srcPixel[RGB.B];

                                coefR = spatialFunc[tx, ty] * colorFunc[srcR, srcR0];
                                coefG = spatialFunc[tx, ty] * colorFunc[srcG, srcG0];
                                coefB = spatialFunc[tx, ty] * colorFunc[srcB, srcB0];

                                sCoefR += coefR;
                                sCoefG += coefG;
                                sCoefB += coefB;

                                sMembR += coefR * srcR;
                                sMembG += coefG * srcG;
                                sMembB += coefB * srcB;

                                srcPixel -= pixelSize;
                            }

                            srcPixel -= srcKernelOffset;
                        }

                        dst[RGB.R] = (byte) ( sMembR / sCoefR );
                        dst[RGB.G] = (byte) ( sMembG / sCoefG );
                        dst[RGB.B] = (byte) ( sMembB / sCoefB );
                    }
                } );
            }
//.........这里部分代码省略.........
开发者ID:centrolutions,项目名称:AForge.NET,代码行数:101,代码来源:BilateralSmoothing.cs

示例15: ProcessFilter

        /// <summary>
        /// Process the filter on the specified image.
        /// </summary>
        /// 
        /// <param name="sourceData">Source image data.</param>
        /// <param name="destinationData">Destination image data.</param>
        /// <param name="rect">Image rectangle for processing by the filter.</param>
        /// 
        /// <exception cref="InvalidImagePropertiesException">Processing rectangle mast be at least 3x3 in size.</exception>
        /// 
        protected override unsafe void ProcessFilter( UnmanagedImage sourceData, UnmanagedImage destinationData, Rectangle rect )
        {
            if ( ( rect.Width < 3 ) || ( rect.Height < 3 ) )
            {
                throw new InvalidImagePropertiesException( "Processing rectangle mast be at least 3x3 in size." );
            }

            // processing start and stop X,Y positions
            int startX  = rect.Left + 1;
            int startY  = rect.Top + 1;
            int stopX   = rect.Right - 1;
            int stopY   = rect.Bottom - 1;

            int dstStride = destinationData.Stride;
            int srcStride = sourceData.Stride;

            int dstOffset = dstStride - rect.Width + 1;
            int srcOffset = srcStride - rect.Width + 1;

            // image pointers
            byte* src = (byte*) sourceData.ImageData.ToPointer( );
            byte* dst = (byte*) destinationData.ImageData.ToPointer( );

            // allign pointers by X and Y
            src += ( startX - 1 ) + ( startY - 1 ) * srcStride;
            dst += ( startX - 1 ) + ( startY - 1 ) * dstStride;

            // --- process the first line setting all to black
            for ( int x = startX - 1; x < stopX; x++, src++, dst++ )
            {
                *dst = 0;
            }
            *dst = 0;

            src += srcOffset;
            dst += dstOffset;

            // --- process all lines except the last one
            for ( int y = startY; y < stopY; y++ )
            {
                // set edge pixel to black
                *dst = 0;

                src++;
                dst++;

                // for each pixel
                for ( int x = startX; x < stopX; x++, src++, dst++ )
                {
                    *dst = (byte) ( *src & src[-1] & src[1] &
                        src[-srcStride] & src[-srcStride - 1] & src[-srcStride + 1] &
                        src[srcStride] & src[srcStride - 1] & src[srcStride + 1] );
                }

                // set edge pixel to black
                *dst = 0;

                src += srcOffset;
                dst += dstOffset;
            }

            // --- process the last line setting all to black

            // for each pixel
            for ( int x = startX - 1; x < stopX; x++, src++, dst++ )
            {
                *dst = 0;
            }
            *dst = 0;
        }
开发者ID:RevDevBev,项目名称:aforge.net,代码行数:80,代码来源:BinaryErosion3x3.cs


注:本文中的UnmanagedImage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。