Example #1
0
        private static void GetMultiplier1(
            RadiometricSimilarityImage image1,
            RadiometricSimilarityImage image2,
            out int[,] widthHeightDataIntensity)
        {
            widthHeightDataIntensity = new int[image1.Width, image1.Height];
            var data1  = image1.ImageData;
            var data2  = image2.ImageData;
            var width  = image1.Width;
            var height = image1.Height;
            var stride = image1.Stride;

            for (int widthI = 1; widthI < (width - 1); widthI++)
            {
                for (int heightI = 1; heightI < (height - 1); heightI++)
                {
                    var a11 = data1[ToDataPosition(widthI - 1, heightI - 1, stride)];
                    var a12 = data1[ToDataPosition(widthI - 1, heightI, stride)];;
                    var a13 = data1[ToDataPosition(widthI - 1, heightI + 1, stride)];
                    var a21 = data1[ToDataPosition(widthI, heightI - 1, stride)];
                    var a22 = data1[ToDataPosition(widthI, heightI, stride)];
                    var a23 = data1[ToDataPosition(widthI, heightI + 1, stride)];
                    var a31 = data1[ToDataPosition(widthI + 1, heightI - 1, stride)];
                    var a32 = data1[ToDataPosition(widthI + 1, heightI, stride)];
                    var a33 = data1[ToDataPosition(widthI + 1, heightI + 1, stride)];

                    var b11 = data2[ToDataPosition(widthI - 1, heightI - 1, stride)];
                    var b12 = data2[ToDataPosition(widthI - 1, heightI, stride)];
                    var b13 = data2[ToDataPosition(widthI - 1, heightI + 1, stride)];
                    var b21 = data2[ToDataPosition(widthI, heightI - 1, stride)];
                    var b22 = data2[ToDataPosition(widthI, heightI, stride)];
                    var b23 = data2[ToDataPosition(widthI, heightI + 1, stride)];
                    var b31 = data2[ToDataPosition(widthI + 1, heightI - 1, stride)];
                    var b32 = data2[ToDataPosition(widthI + 1, heightI, stride)];
                    var b33 = data2[ToDataPosition(widthI + 1, heightI + 1, stride)];

                    var c11 = a11 * b11 + a12 * b21 + a13 * b31;
                    var c12 = a11 * b12 + a12 * b22 + a13 * b32;
                    var c13 = a11 * b13 + a12 * b23 + a13 * b33;

                    var c21 = a21 * b11 + a22 * b21 + a23 * b31;
                    var c22 = a21 * b12 + a22 * b22 + a23 * b32;
                    var c23 = a21 * b13 + a22 * b23 + a23 * b33;

                    var c31 = a31 * b11 + a32 * b21 + a33 * b31;
                    var c32 = a31 * b12 + a32 * b22 + a33 * b32;
                    var c33 = a31 * b13 + a32 * b23 + a33 * b33;


                    var result = (int)Math.Round(((c11 + c12 + c13 + c21 + c22 + c23 + c31 + c32 + c33) / 9.0) * 2.0 / 3.0);
                    if (result > byte.MaxValue * byte.MaxValue * 2)
                    {
                        throw new InvalidDataException();
                    }

                    widthHeightDataIntensity[widthI, heightI] = result;
                }
            }
        }
Example #2
0
        // this does not work.
        public static void GetRadiometricSimmilarity(
            RadiometricSimilarityImage image1,
            RadiometricSimilarityImage image2,

            int threthhold,

            out byte[,] motionData,
            out Bitmap motionImage,

            out byte[,] stationaryData,
            out Bitmap stationaryImage

            )
        {
            // Radiometric simillarity.
            GCHandle handleMotion;
            GCHandle handleStationary;

            motionImage     = BeginImage(image1.Width, image1.Height, out motionData, out handleMotion);
            stationaryImage = BeginImage(image1.Width, image1.Height, out stationaryData, out handleStationary);
            int[,] firstItemWH;
            GetMultiplier1(image1, image2, out firstItemWH);
            for (int widthI = 1; widthI < (image1.Width - 1); widthI++)
            {
                for (int heightI = 1; heightI < (image1.Height - 1); heightI++)
                {
                    var resultHW = (
                        (firstItemWH[widthI, heightI] - image1.MeanWH[widthI, heightI] * image2.MeanWH[widthI, heightI])
                        /
                        Math.Sqrt(image1.VarianceWH[widthI, heightI] * image2.VarianceWH[widthI, heightI]));
                    //TODO: гистограмма результатов.
                    if (resultHW < 400000)
                    {
                        motionData[heightI, widthI]     = byte.MaxValue;
                        stationaryData[heightI, widthI] = 0;
                    }
                    else
                    {
                        motionData[heightI, widthI]     = 0;
                        stationaryData[heightI, widthI] = byte.MaxValue;
                    }
                }
            }

            EndImage(handleMotion);
            EndImage(handleStationary);
        }