예제 #1
0
        private void DrawDepthColorMatrix()
        {
            var minValue = GetMinValueFromBlockDistMat();
            var maxValue = GetMaxValueFromBlockDistMat();

            workImageBlockMatch.Lock();
            for (int i = 0; i < workImageBlockMatch.Width; i++)
            {
                for (int j = 0; j < workImageBlockMatch.Height; j++)
                {
                    var   colorValue = (blockDistMatrix[i, j] * WHITE_COLOR_VALUE) / maxValue;
                    Color color      = Color.FromArgb(colorValue, colorValue, colorValue);

                    if (blockDistMatrix[i, j] == minValue)
                    {
                        color = Color.White;
                    }
                    else if (blockDistMatrix[i, j] == maxValue)
                    {
                        color = Color.Black;
                    }

                    workImageBlockMatch.SetPixel(i, j, color);
                }
            }
            panelDestination.BackgroundImage = null;
            panelDestination.BackgroundImage = workImageBlockMatch.GetBitMap();
            workImageBlockMatch.Unlock();
        }
예제 #2
0
        private void buttonGrayscale_Click(object sender, EventArgs e)
        {
            Color color;

            workImage.Lock();
            for (int i = 0; i < workImage.Width; i++)
            {
                for (int j = 0; j < workImage.Height; j++)
                {
                    color = workImage.GetPixel(i, j);
                    byte R = color.R;
                    byte G = color.G;
                    byte B = color.B;

                    byte average = (byte)((R + G + B) / 3);

                    color = Color.FromArgb(average, average, average);

                    workImage.SetPixel(i, j, color);
                }
            }

            panelDestination.BackgroundImage = null;
            panelDestination.BackgroundImage = workImage.GetBitMap();
            workImage.Unlock();
        }
예제 #3
0
 private void UpdateWorkImage()
 {
     panelDestination.BackgroundImage = null;
     panelDestination.BackgroundImage = workImage.GetBitMap();
 }
예제 #4
0
        private void btnBlockMatch_Click(object sender, EventArgs e)
        {
            Color colorRef;
            Color colorDest;

            lineSize  = Convert.ToInt32(textBoxLineSize.Text);
            blockSize = Convert.ToInt32(textBoxBlockSize.Text);
            var auxBitmap = workImageRight.GetBitMap();

            // all image search
            workImageLeft.Lock();
            for (int i = 0; i < workImageLeft.Width; i += blockSize)
            {
                for (int j = 0; j < workImageLeft.Height; j += blockSize)
                {
                    int sum_ref_R     = 0;
                    int sum_ref_G     = 0;
                    int sum_ref_B     = 0;
                    var dest_sum_list = new List <ColorExtension>();

                    // block image search
                    if (i + blockSize < workImageLeft.Width && j + blockSize < workImageLeft.Height)
                    {
                        // calc the block sum from LEFT image with default size S=4
                        for (int m = i; m < i + blockSize; m++)
                        {
                            for (int n = j; n < j + blockSize; n++)
                            {
                                colorRef   = workImageLeft.GetPixel(m, n);
                                sum_ref_R += colorRef.R;
                                sum_ref_G += colorRef.G;
                                sum_ref_B += colorRef.B;
                            }
                        }

                        // calc the sum from RIGHT image with sliding window D=16 default
                        if (i + lineSize < workImageRight.Width || j + lineSize < workImageRight.Height)
                        {
                            var ct        = 0;
                            var nextM     = i;
                            var nextN     = j;
                            var max_count = lineSize / blockSize;

                            while (ct < max_count)
                            {
                                int sum_dest_R = 0;
                                int sum_dest_G = 0;
                                int sum_dest_B = 0;
                                for (int m = nextM; m < nextM + blockSize; m++)
                                {
                                    for (int n = nextN; n < nextN + blockSize; n++)
                                    {
                                        colorDest   = auxBitmap.GetPixel(nextM, nextN);
                                        sum_dest_R += colorDest.R;
                                        sum_dest_G += colorDest.G;
                                        sum_dest_B += colorDest.B;
                                    }
                                }
                                dest_sum_list.Add(new ColorExtension(sum_dest_R, sum_dest_G, sum_dest_B));
                                nextN++;
                                ct++;
                            }
                        }

                        // calc the sum of absolut diff (LEFT - RIGHT)
                        var minBlockSum = new ColorExtension(int.MaxValue, int.MaxValue, int.MaxValue);
                        foreach (var elem in dest_sum_list)
                        {
                            var diff_R = sum_ref_R - elem.R;
                            var diff_G = sum_ref_G - elem.G;
                            var diff_B = sum_ref_B - elem.B;
                            if (diff_R < minBlockSum.R && diff_G < minBlockSum.G && diff_B < minBlockSum.B)
                            {
                                minBlockSum = elem;
                            }
                        }

                        // get the index of the minimum block sum in order to set the color
                        var index = dest_sum_list.IndexOf(minBlockSum);
                        SetBlockDistMatrix(i, j, Math.Abs(index + 1));
                    }
                }
            }
            workImageLeft.Unlock();

            DrawDepthColorMatrix();
        }