Rotate image using nearest neighbor algorithm.

The class implements image rotation filter using nearest neighbor algorithm, which does not assume any interpolation.

Rotation is performed in counterclockwise direction.

The filter accepts 8/16 bpp grayscale images and 24/48 bpp color image for processing.

Sample usage:

// create filter - rotate for 30 degrees keeping original image size RotateNearestNeighbor filter = new RotateNearestNeighbor( 30, true ); // apply the filter Bitmap newImage = filter.Apply( image );

Initial image:

Result image:

Inheritance: BaseRotateFilter
Exemple #1
0
        private void SetFilter()
        {
            ImageType = ImageTypes.Rgb24bpp;

            switch (mode)
            {
            case Modes.Bicubic:
                Af.RotateBicubic newFilterA = new Af.RotateBicubic(angle);
                newFilterA.FillColor = color;
                newFilterA.KeepSize  = keepSize;
                imageFilter          = newFilterA;
                break;

            case Modes.Bilinear:
                Af.RotateBilinear newFilterB = new Af.RotateBilinear(angle);
                newFilterB.FillColor = color;
                newFilterB.KeepSize  = keepSize;
                imageFilter          = newFilterB;
                break;

            case Modes.Nearest:
                Af.RotateNearestNeighbor newFilterC = new Af.RotateNearestNeighbor(angle);
                newFilterC.FillColor = color;
                newFilterC.KeepSize  = keepSize;
                imageFilter          = newFilterC;
                break;
            }
        }
        public static bool RotateTest32bpp(IFilter filter, Bitmap input, Bitmap output)
        {
            var itm = new ImageToMatrix();

            // Test directly
            Color[,] actual;
            itm.Convert(filter.Apply(input), out actual);

            Color[,] expected;
            itm.Convert(output, out expected);

            if (!actual.IsEqual(expected))
            {
                return(false);
            }

            // Rotate and re-test
            var rotate = new RotateNearestNeighbor(90, false);

            input  = rotate.Apply(input);
            output = rotate.Apply(output);

            itm.Convert(filter.Apply(input), out actual);
            itm.Convert(output, out expected);

            return(actual.IsEqual(expected));
        }
Exemple #3
0
        public static bool RotateTest32bpp(IFilter filter, Bitmap input, Bitmap output)
        {
            var itm = new ImageToMatrix();

            // Test directly
            Color[,] actual;
            itm.Convert(filter.Apply(input), out actual);

            Color[,] expected;
            itm.Convert(output, out expected);

            if (!actual.IsEqual(expected))
                return false;

            // Rotate and re-test
            var rotate = new RotateNearestNeighbor(90, false);
            input = rotate.Apply(input);
            output = rotate.Apply(output);

            itm.Convert(filter.Apply(input), out actual);
            itm.Convert(output, out expected);

            return actual.IsEqual(expected);
        }