示例#1
0
        public (int, int) TestCC(NPPImage_32fC1 img, int shiftX, int shiftY)
        {
            Matrix3x3 mat = Matrix3x3.ShiftAffine(shiftX, shiftY);

            img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.NearestNeighbor);

            forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);
            conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
            fftshiftKernel.RunSafe(imgToTrackCplx, width, height);
            backward.Exec(imgToTrackCplx.DevicePointer, img.DevicePointerRoi);
            img.Div(img.WidthRoi * img.HeightRoi);

            img.MaxIndex(val, x, y);

            float v  = val;
            int   hx = x;
            int   hy = y;

            hx -= imgToTrackRotated.WidthRoi / 2;
            hy -= imgToTrackRotated.HeightRoi / 2;


            CudaDeviceVariable <float> minVal = new CudaDeviceVariable <float>(x.DevicePointer, 4);
            CudaDeviceVariable <float> maxVal = new CudaDeviceVariable <float>(y.DevicePointer, 4);

            img.MinMax(minVal, maxVal, buffer);
            float min = minVal;
            float max = maxVal;

            img.Sub(min);
            img.Div(max - min);


            img.ThresholdLTGT(0, 0, 1, 1);

            return(hx, hy);
        }
示例#2
0
        public double4 ScanAngles(NPPImage_32fC1 img, double incr, double range, double zero)
        {
            NppiRect saveRoi = new NppiRect(img.PointRoi, img.SizeRoi);
            NppiRect roi     = new NppiRect();

            roi.x      = 0;
            roi.y      = 0;
            roi.width  = imgToTrackRotated.WidthRoi;
            roi.height = imgToTrackRotated.HeightRoi;
            img.SetRoi(roi);

            double maxVal = -double.MaxValue;
            double maxAng = 0;
            double maxX   = 0;
            double maxY   = 0;

            //first perform a coarse search
            for (double ang = zero - range; ang <= zero + range; ang += 5 * incr)
            {
                Matrix3x3 mat = Matrix3x3.RotAroundCenter(ang, imgToTrackRotated.Width, imgToTrackRotated.Height);
                imgToTrackRotated.Set(0);
                img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.Cubic);

                forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);

                conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
                backward.Exec(imgToTrackCplx.DevicePointer, imgToTrackRotated.DevicePointerRoi);
                imgToTrackRotated.Div(imgToTrackRotated.WidthRoi * imgToTrackRotated.HeightRoi);

                imgToTrackRotated.MaxIndex(val, x, y);
                float v  = val;
                int   hx = x;
                int   hy = y;
                //Console.WriteLine("Found Max at " + ang.ToString("0.000") + " deg (" + hx + ", " + hy + ") = " + v);
                if (v > maxVal)
                {
                    maxVal = v;
                    maxAng = ang;
                    maxX   = x;
                    maxY   = y;
                    //Console.WriteLine("Max set!");
                }
            }

            zero  = maxAng;
            range = 10 * incr;
            //now perform a fine search but only around the previously found peak
            for (double ang = zero - range; ang <= zero + range; ang += incr)
            {
                Matrix3x3 mat = Matrix3x3.RotAroundCenter(ang, imgToTrackRotated.Width, imgToTrackRotated.Height);
                imgToTrackRotated.Set(0);
                img.WarpAffine(imgToTrackRotated, mat.ToAffine(), InterpolationMode.Cubic);

                int fftWidth = width / 2 + 1;
                forward.Exec(imgToTrackRotated.DevicePointerRoi, imgToTrackCplx.DevicePointer);
                conjKernel.RunSafe(imgRefCplx, imgToTrackCplx);
                backward.Exec(imgToTrackCplx.DevicePointer, imgToTrackRotated.DevicePointerRoi);
                imgToTrackRotated.Div(imgToTrackRotated.WidthRoi * imgToTrackRotated.HeightRoi);

                imgToTrackRotated.MaxIndex(val, x, y);

                float v  = val;
                int   hx = x;
                int   hy = y;
                if (v > maxVal)
                {
                    maxVal = v;
                    maxAng = ang;
                    maxX   = x;
                    maxY   = y;
                    //Console.WriteLine("Found Max at " + ang.ToString("0.000") + " deg (" + hx + ", " + hy + ") = " + v);
                    //Console.WriteLine("Max set!");
                }
            }

            if (maxX > imgToTrackRotated.WidthRoi / 2)
            {
                maxX -= imgToTrackRotated.WidthRoi;
            }
            if (maxY > imgToTrackRotated.HeightRoi / 2)
            {
                maxY -= imgToTrackRotated.HeightRoi;
            }

            img.SetRoi(saveRoi);
            return(new double4(-maxX, -maxY, maxAng, maxVal));
        }
示例#3
0
        public TestRawFile(string dummyFile, int size, float preShiftX, float preShiftY, float preRotDeg, float shiftX, float shiftY)
            : base(dummyFile)
        {
            //close the file
            Close();
            Random rand = new Random(0);

            mRawImage = new ushort[size, size];

            float[]        temp   = new float[size * size];
            NPPImage_32fC1 img1   = new NPPImage_32fC1(size, size);
            NPPImage_32fC1 img2   = new NPPImage_32fC1(size, size);
            NPPImage_16uC1 img16u = new NPPImage_16uC1(size, size);

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] = (float)rand.NextDouble();
            }

            img1.CopyToDevice(temp);
            img1.FilterGaussBorder(img2, MaskSize.Size_5_X_5, NppiBorderType.Replicate);
            img1.Set(0);
            img2.WarpAffine(img1, Matrix3x3.ShiftAffine(-preShiftX, -preShiftY).ToAffine(), InterpolationMode.Cubic);
            img2.Set(0);
            img1.WarpAffine(img2, Matrix3x3.RotAroundCenter(-preRotDeg, size, size).ToAffine(), InterpolationMode.Cubic);
            img1.Set(0);
            img2.WarpAffine(img1, Matrix3x3.ShiftAffine(-shiftX, -shiftY).ToAffine(), InterpolationMode.Cubic);
            img1.Mul(65535);
            img1.Convert(img16u, NppRoundMode.Near);

            img16u.CopyToHost(mRawImage, size * sizeof(ushort));

            double[] colorMatrix = new double[] { 1, 0, 0, 0, 1, 0, 0, 0, 1 };
            mColorSpec = new PentaxPefFile.DNGColorSpec(colorMatrix, colorMatrix, PentaxPefFile.IFDDNGCalibrationIlluminant.Illuminant.D50,
                                                        PentaxPefFile.IFDDNGCalibrationIlluminant.Illuminant.D65, new float[] { 1f, 1, 1f });
            mOrientation = new PentaxPefFile.DNGOrientation(PentaxPefFile.DNGOrientation.Orientation.Normal);

            mWidth            = size;
            mHeight           = size;
            mCropLeft         = 0;
            mCropTop          = 0;
            mCroppedWidth     = size;
            mCroppedHeight    = size;
            mBitDepth         = 16;
            mISO              = 100;
            mBayerPattern     = new BayerColor[] { BayerColor.Red, BayerColor.Cyan, BayerColor.Blue };
            mWhiteLevel       = new float[] { 65535, 65535, 65535 };
            mBlackLevel       = new float[] { 0, 0, 0 };
            mWhiteBalance     = new float[] { 1, 1, 1 };;
            mRollAngle        = 0;
            mRollAnglePresent = false;
            mNoiseModelAlpha  = float.Epsilon;
            mNoiseModelBeta   = 0;
            mExposureTime     = new PentaxPefFile.Rational(1, 1);
            mRecordingDate    = DateTime.Now;
            mMake             = "None";
            mUniqueModelName  = "Test file";

            img1.Dispose();
            img2.Dispose();
            img16u.Dispose();
        }