Пример #1
0
        public GrayImage Filter1DSymmetric(GrayImage data, float[] filter, bool transpose)
        {
            GrayImage image = transpose ? new GrayImage(data.Height, data.Width) : new GrayImage(data.Width, data.Height);
            int       num   = 0;
            int       num2  = transpose ? num : (num * image.Width);
            FilterJob job2  = new FilterJob();

            job2.filter  = filter;
            job2.data    = data;
            job2.destPtr = num2;
            job2.result  = image;
            job2.start   = num;
            job2.end     = data.Height / 2;
            FilterJob parameter            = job2;
            ParameterizedThreadStart start = transpose ? new ParameterizedThreadStart(this.FilterPartSymmetricT) : new ParameterizedThreadStart(this.FilterPartSymmetric);
            Thread thread = new Thread(start);

            thread.Start(parameter);
            num               = data.Height / 2;
            num2              = transpose ? num : (num * image.Width);
            parameter.start   = num;
            parameter.destPtr = num2;
            parameter.end     = data.Height;
            start(parameter);
            thread.Join();
            return(image);
        }
Пример #2
0
    void Start()
    {
        NativeArray <TestData> nData = new NativeArray <TestData>(2, Allocator.TempJob);

        // Won't filter to use...or won't be filtered away? Not sure how to interpret
        nData[0] = new TestData(0, 0);

        // Opposite, I expect one of these to end up having a value of 1
        nData[1] = new TestData(0, 1);

        NativeList <int> indexes = new NativeList <int>(Allocator.TempJob);

        FilterJob filterJob = new FilterJob();

        filterJob.nData = nData;

        JobHandle handle = filterJob.ScheduleAppend(indexes, nData.Length, 1); //filterJob.ScheduleFilter(indexes, 32);

        // Even forcing a complete here doesn't seem to matter. As best as I can tell the filter doesn't run
        // handle.Complete();

        IncrementIndices incJob = new IncrementIndices();

        incJob.indexes = indexes;
        incJob.nData   = nData;
        handle         = incJob.Schedule(handle);

        handle.Complete();

        Debug.Log(nData[0].num + " " + nData[1].num);

        nData.Dispose();
        indexes.Dispose();
    }
Пример #3
0
        public void FilterPartSymmetric(object filterJob)
        {
            FilterJob filterJob2 = (FilterJob)filterJob;
            GrayImage data       = filterJob2.data;

            float[] scan    = data.Scan0;
            float[] filter  = filterJob2.filter;
            float[] scan2   = filterJob2.result.Scan0;
            int     num     = filter.Length - 1;
            int     destPtr = filterJob2.destPtr;

            for (int i = filterJob2.start; i < filterJob2.end; i++)
            {
                int num2 = i * data.Width;
                for (int j = 0; j < num; j++)
                {
                    float num3 = scan[num2] * filter[0];
                    for (int k = 1; k < j + 1; k++)
                    {
                        num3 += (scan[num2 + k] + scan[num2 - k]) * filter[k];
                    }
                    for (int l = j + 1; l < filter.Length; l++)
                    {
                        num3 += (scan[num2 + l] + scan[num2 + l]) * filter[l];
                    }
                    scan2[destPtr++] = num3;
                    num2++;
                }
                for (int m = num; m < data.Width - num; m++)
                {
                    float num4 = scan[num2] * filter[0];
                    for (int n = 1; n < filter.Length; n++)
                    {
                        num4 += (scan[num2 + n] + scan[num2 - n]) * filter[n];
                    }
                    scan2[destPtr++] = num4;
                    num2++;
                }
                for (int num5 = data.Width - num; num5 < data.Width; num5++)
                {
                    float num6 = scan[num2] * filter[0];
                    for (int num7 = 0; num7 < data.Width - num5; num7++)
                    {
                        num6 += (scan[num2 + num7] + scan[num2 - num7]) * filter[num7];
                    }
                    for (int num8 = data.Width - num5; num8 < filter.Length; num8++)
                    {
                        num6 += (scan[num2 + num8] + scan[num2 - num8]) * filter[num8];
                    }
                    scan2[destPtr++] = num6;
                    num2++;
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Filters an GrayImage with a 1D symmetric filter along the X-axis.
        /// (This operation is multithreaded)
        /// </summary>
        /// <param name="data">GrayImage to be operated on</param>
        /// <param name="filter">Filter to use (center tap plus right-hand-side)</param>
        /// <param name="transpose">Transpose the result?</param>
        /// <returns>Transposed, filtered GrayImage.</returns>
        public GrayImage Filter1DSymmetric(GrayImage data, float[] filter, bool transpose)
        {
            GrayImage result = transpose ?
                               new GrayImage(data.Height, data.Width) :
                               new GrayImage(data.Width, data.Height);

            int startY = 0;

            int destPtr = transpose ?  startY : (startY * result.Width);

            FilterJob job
                = new FilterJob
                {
                filter  = filter,
                data    = data,
                destPtr = destPtr,
                result  = result,
                start   = startY,
                end     = data.Height / 2
                };

            ParameterizedThreadStart del = transpose ?
                                           new ParameterizedThreadStart(FilterPartSymmetricT) :
                                           new ParameterizedThreadStart(FilterPartSymmetric);

            Thread worker = new Thread(del);

            worker.Start(job);

            startY  = data.Height / 2;
            destPtr = transpose ?  startY : (startY * result.Width);


            job.start   = startY;
            job.destPtr = destPtr;
            job.end     = data.Height;

            del((object)job); // Run the appropriate filter in this thread, too

            worker.Join();


            return(result);
        }
Пример #5
0
        public GrayImage Filter1DSymmetric(GrayImage data, float[] filter, bool transpose)
        {
            GrayImage result    = transpose ? new GrayImage(data.Height, data.Width) : new GrayImage(data.Width, data.Height);
            FilterJob filterJob = default(FilterJob);

            filterJob.filter  = filter;
            filterJob.data    = data;
            filterJob.destPtr = 0;
            filterJob.result  = result;
            filterJob.start   = 0;
            filterJob.end     = data.Height;
            FilterJob filterJob2 = filterJob;

            if (transpose)
            {
                FilterPartSymmetricT(filterJob2);
            }
            else
            {
                FilterPartSymmetric(filterJob2);
            }
            return(result);
        }
Пример #6
0
        private void FilterPartSymmetricT(object filterJob)
        {
            FilterJob job  = (FilterJob)filterJob;
            GrayImage data = job.data;

            float[]   numArray = data.Scan0;
            float[]   filter   = job.filter;
            GrayImage result   = job.result;
            int       num      = filter.Length - 1;

            for (int i = job.start; i < job.end; i++)
            {
                float num6;
                int   num7;
                int   num3  = i * data.Width;
                int   index = num3;
                int   num5  = 0;
                while (num5 < num)
                {
                    num6 = numArray[index] * filter[0];
                    num7 = 1;
                    while (num7 < (num5 + 1))
                    {
                        num6 += (numArray[index + num7] + numArray[index - num7]) * filter[num7];
                        num7++;
                    }
                    num7 = num5 + 1;
                    while (num7 < filter.Length)
                    {
                        num6 += (numArray[index + num7] + numArray[index + num7]) * filter[num7];
                        num7++;
                    }
                    result[i, num5] = num6;
                    index++;
                    num5++;
                }
                num5 = num;
                while (num5 < (data.Width - num))
                {
                    num6 = numArray[index] * filter[0];
                    num7 = 1;
                    while (num7 < filter.Length)
                    {
                        num6 += (numArray[index + num7] + numArray[index - num7]) * filter[num7];
                        num7++;
                    }
                    result[i, num5] = num6;
                    index++;
                    num5++;
                }
                for (num5 = data.Width - num; num5 < data.Width; num5++)
                {
                    num6 = numArray[index] * filter[0];
                    num7 = 1;
                    while (num7 < (data.Width - num5))
                    {
                        num6 += (numArray[index + num7] + numArray[index - num7]) * filter[num7];
                        num7++;
                    }
                    for (num7 = data.Width - num5; num7 < filter.Length; num7++)
                    {
                        num6 += (numArray[index - num7] + numArray[index - num7]) * filter[num7];
                    }
                    result[i, num5] = num6;
                    index++;
                }
            }
        }
Пример #7
0
        private void FilterPartSymmetric(object filterJob)
        {
            FilterJob job  = (FilterJob)filterJob;
            GrayImage data = job.data;

            float[] numArray  = data.Scan0;
            float[] filter    = job.filter;
            float[] numArray3 = job.result.Scan0;
            int     num       = filter.Length - 1;
            int     destPtr   = job.destPtr;

            for (int i = job.start; i < job.end; i++)
            {
                float num7;
                int   num8;
                int   num4  = i * data.Width;
                int   index = job.dataPtr + num4;
                int   num6  = 0;
                while (num6 < num)
                {
                    num7 = numArray[index] * filter[0];
                    num8 = 1;
                    while (num8 < (num6 + 1))
                    {
                        num7 += (numArray[index + num8] + numArray[index - num8]) * filter[num8];
                        num8++;
                    }
                    num8 = num6 + 1;
                    while (num8 < filter.Length)
                    {
                        num7 += (numArray[index + num8] + numArray[index + num8]) * filter[num8];
                        num8++;
                    }
                    numArray3[destPtr++] = num7;
                    index++;
                    num6++;
                }
                num6 = num;
                while (num6 < (data.Width - num))
                {
                    num7 = numArray[index] * filter[0];
                    num8 = 1;
                    while (num8 < filter.Length)
                    {
                        num7 += (numArray[index + num8] + numArray[index - num8]) * filter[num8];
                        num8++;
                    }
                    numArray3[destPtr++] = num7;
                    index++;
                    num6++;
                }
                for (num6 = data.Width - num; num6 < data.Width; num6++)
                {
                    num7 = numArray[index] * filter[0];
                    num8 = 0;
                    while (num8 < (data.Width - num6))
                    {
                        num7 += (numArray[index + num8] + numArray[index - num8]) * filter[num8];
                        num8++;
                    }
                    for (num8 = data.Width - num6; num8 < filter.Length; num8++)
                    {
                        num7 += (numArray[index + num8] + numArray[index - num8]) * filter[num8];
                    }
                    numArray3[destPtr++] = num7;
                    index++;
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Filters an GrayImage with a 1D symmetric filter along the X-axis.
        /// (This operation is multithreaded)
        /// </summary>
        /// <param name="data">GrayImage to be operated on</param>
        /// <param name="filter">Filter to use (center tap plus right-hand-side)</param>
        /// <param name="transpose">Transpose the result?</param>
        /// <returns>Transposed, filtered GrayImage.</returns>
        public GrayImage Filter1DSymmetric(GrayImage data, float[] filter, bool transpose)
        {
            GrayImage result = transpose ?
                new GrayImage(data.Height, data.Width) :
                new GrayImage(data.Width, data.Height);

#if SILVERLIGHT || WIN
            int startY = 0;

            int destPtr = transpose ?  startY : (startY * result.Width);

            FilterJob job
                = new FilterJob
                {
                    filter = filter,
                    data = data,
                    destPtr = destPtr,
                    result = result,
                    start = startY,
                    end = data.Height / 2
                };

            ParameterizedThreadStart del = transpose ?
                new ParameterizedThreadStart(FilterPartSymmetricT) :
                new ParameterizedThreadStart(FilterPartSymmetric);

            Thread worker = new Thread(del);
            worker.Start(job);

            startY = data.Height / 2;
            destPtr = transpose ?  startY : (startY * result.Width);


            job.start = startY;
            job.destPtr = destPtr;
            job.end = data.Height;

            del((object)job); // Run the appropriate filter in this thread, too

            worker.Join();
#else
            FilterJob job
                = new FilterJob
                {
                    filter = filter,
                    data = data,
                    destPtr = 0,
                    result = result,
                    start = 0,
                    end = data.Height
                };

            if (transpose)
                FilterPartSymmetricT(job);
            else
                FilterPartSymmetric(job);
#endif

            return result;
        }
Пример #9
0
        /// <summary>
        /// Convolves an GrayImage with a 1D filter along the X-axis.
        /// </summary>
        /// <param name="filterJob">Filter operation details</param>
        private void FilterPartSymmetric(object filterJob)
        {
            FilterJob fj = (FilterJob)filterJob;

            GrayImage data = fj.data;

            float[]   srcData = data.Scan0;
            float[]   filter  = fj.filter;
            GrayImage result  = fj.result;

            float[] resData = result.Scan0;

            int pad = filter.Length - 1;

            int destPtr = fj.destPtr;

            #region Filter (no transpose)
            for (int y = fj.start; y < fj.end; y++)
            {
                int rowStart = y * data.Width;

                int ptr = fj.dataPtr + rowStart;

                // Left checked region
                for (int x = 0; x < pad; x++)
                {
                    float pixel = srcData[ptr] * filter[0];

                    // Part of the filter that fits within the GrayImage
                    for (int i = 1; i < x + 1; i++)
                    {
                        pixel += (srcData[ptr + i] + srcData[ptr - i]) * filter[i];
                    }

                    // Part of the filter that falls off the left side
                    for (int i = x + 1; i < filter.Length; i++)
                    {
                        pixel += (srcData[ptr + i] + srcData[ptr + i]) * filter[i];
                    }

                    resData[destPtr++] = pixel; ptr++;
                }

                // Unchecked region
                for (int x = pad; x < data.Width - pad; x++)
                {
                    float pixel = srcData[ptr] * filter[0];

                    for (int i = 1; i < filter.Length; i++)
                    {
                        pixel += (srcData[ptr + i] + srcData[ptr - i]) * filter[i];
                    }

                    resData[destPtr++] = pixel; ptr++;
                }

                // Right checked region
                for (int x = data.Width - pad; x < data.Width; x++)
                {
                    float pixel = srcData[ptr] * filter[0];

                    // Part of the filter that fits within the GrayImage
                    for (int i = 0; i < (data.Width - x); i++)
                    {
                        pixel += (srcData[ptr + i] + srcData[ptr - i]) * filter[i];
                    }

                    // Part of the filter that falls off the right side
                    for (int i = (data.Width - x); i < filter.Length; i++)
                    {
                        pixel += (srcData[ptr + i] + srcData[ptr - i]) * filter[i];
                    }

                    resData[destPtr++] = pixel; ptr++;
                }
            }

            #endregion
        }
Пример #10
0
 public GrayImage Filter1DSymmetric(GrayImage data, float[] filter, bool transpose)
 {
     GrayImage image = transpose ? new GrayImage(data.Height, data.Width) : new GrayImage(data.Width, data.Height);
     int num = 0;
     int num2 = transpose ? num : (num * image.Width);
     FilterJob job2 = new FilterJob();
     job2.filter = filter;
     job2.data = data;
     job2.destPtr = num2;
     job2.result = image;
     job2.start = num;
     job2.end = data.Height / 2;
     FilterJob parameter = job2;
     ParameterizedThreadStart start = transpose ? new ParameterizedThreadStart(this.FilterPartSymmetricT) : new ParameterizedThreadStart(this.FilterPartSymmetric);
     Thread thread = new Thread(start);
     thread.Start(parameter);
     num = data.Height / 2;
     num2 = transpose ? num : (num * image.Width);
     parameter.start = num;
     parameter.destPtr = num2;
     parameter.end = data.Height;
     start(parameter);
     thread.Join();
     return image;
 }