ManagedCuda.NPP.NPPImage_8uC3.ResizeSqrPixel C# (CSharp) Method

ResizeSqrPixel() public static method

planar image resize.
public static ResizeSqrPixel ( NPPImage_8uC1 src0, NPPImage_8uC1 src1, NPPImage_8uC1 src2, NPPImage_8uC1 dest0, NPPImage_8uC1 dest1, NPPImage_8uC1 dest2, double nXFactor, double nYFactor, double nXShift, double nYShift, InterpolationMode eInterpolation ) : void
src0 NPPImage_8uC1 Source image (Channel 0)
src1 NPPImage_8uC1 Source image (Channel 1)
src2 NPPImage_8uC1 Source image (Channel 2)
dest0 NPPImage_8uC1 Destination image (Channel 0)
dest1 NPPImage_8uC1 Destination image (Channel 1)
dest2 NPPImage_8uC1 Destination image (Channel 2)
nXFactor double Factor by which x dimension is changed.
nYFactor double Factor by which y dimension is changed.
nXShift double Source pixel shift in x-direction.
nYShift double Source pixel shift in y-direction.
eInterpolation InterpolationMode The type of eInterpolation to perform resampling.
return void
        public static void ResizeSqrPixel(NPPImage_8uC1 src0, NPPImage_8uC1 src1, NPPImage_8uC1 src2, NPPImage_8uC1 dest0, NPPImage_8uC1 dest1, NPPImage_8uC1 dest2, double nXFactor, double nYFactor, double nXShift, double nYShift, InterpolationMode eInterpolation)
        {
            CUdeviceptr[] src = new CUdeviceptr[] { src0.DevicePointer, src1.DevicePointer, src2.DevicePointer };
            CUdeviceptr[] dst = new CUdeviceptr[] { dest0.DevicePointer, dest1.DevicePointer, dest2.DevicePointer };
            NppiRect srcRect = new NppiRect(src0.PointRoi, src0.SizeRoi);
            NppiRect dstRect = new NppiRect(dest0.PointRoi, dest0.SizeRoi);
            NppStatus status = NPPNativeMethods.NPPi.ResizeSqrPixel.nppiResizeSqrPixel_8u_P3R(src, src0.SizeRoi, src0.Pitch, srcRect, dst, dest0.Pitch, dstRect, nXFactor, nYFactor, nXShift, nYShift, eInterpolation);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiResizeSqrPixel_8u_P3R", status));
            NPPException.CheckNppStatus(status, null);
        }

Same methods

NPPImage_8uC3::ResizeSqrPixel ( NPPImage_8uC3 dst, double nXFactor, double nYFactor, double nXShift, double nYShift, InterpolationMode eInterpolation ) : void

Usage Example

Example #1
0
        private void btn_Resize_Click(object sender, EventArgs e)
        {
            if ((Bitmap)pic_Image.Image == null) return;

            Bitmap bmp = (Bitmap)pic_Image.Image;
            int w = bmp.Width;
            int h = bmp.Height;

            if ((w <= 16 || h <= 16) && trk_Size.Value < 100)
            {
                MessageBox.Show("Image is too small for resizing.");
                return;
            }

            int newW = (int)(trk_Size.Value / 100.0f * w);
            int newH = (int)(trk_Size.Value / 100.0f * h);

            if (newW % 16 != 0)
            {
                newW = newW - (newW % 16);
            }
            if (newW < 16) newW = 16;

            if (newH % 16 != 0)
            {
                newH = newH - (newH % 16);
            }
            if (newH < 16) newH = 16;

            double ratioW = newW / (double)w;
            double ratioH = newH / (double)h;

            if (ratioW == 1 && ratioH == 1)
                return;

            if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)
            {
                MessageBox.Show("Only three channel color images are supported!");
                return;
            }

            NPPImage_8uC3 imgIn = new NPPImage_8uC3(w, h);
            NPPImage_8uC3 imgOut = new NPPImage_8uC3(newW, newH);

            InterpolationMode interpol = InterpolationMode.SuperSampling;
            if (ratioH >= 1 || ratioW >= 1)
                interpol = InterpolationMode.Lanczos;

            imgIn.CopyToDevice(bmp);
            imgIn.ResizeSqrPixel(imgOut, ratioW, ratioH, 0, 0, interpol);
            Bitmap bmpRes = new Bitmap(newW, newH, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            imgOut.CopyToHost(bmpRes);
            pic_Image.Image = bmpRes;

            imgIn.Dispose();
            imgOut.Dispose();
        }
NPPImage_8uC3