Esempio n. 1
0
        public unsafe static void ModifyHistogram(WriteableBitmap image, int gMin, int gMax)
        {
            int[] redLookUpTable   = new int[256];
            int[] greenLookUpTable = new int[256];
            int[] blueLookUpTable  = new int[256];

            double        valueBase     = gMax / gMin;
            int           sum           = image.PixelHeight * image.PixelWidth;
            HistogramData histogramData = GenerateHistogramData(image);

            for (int i = 0; i < 256; i++)
            {
                double bluePower = GetPowerForHistogramModification(histogramData.BlueData, i, sum);
                blueLookUpTable[i] = (int)(Math.Pow(valueBase, bluePower) * gMin);
                double redPower = GetPowerForHistogramModification(histogramData.RedData, i, sum);
                redLookUpTable[i] = (int)(Math.Pow(valueBase, redPower) * gMin);
                double greenPower = GetPowerForHistogramModification(histogramData.GreenData, i, sum);
                greenLookUpTable[i] = (int)(Math.Pow(valueBase, greenPower) * gMin);
            }

            ChangePixelsValue(image, redLookUpTable, new List <int>()
            {
                ColorChannel.Red
            });
            ChangePixelsValue(image, blueLookUpTable, new List <int>()
            {
                ColorChannel.Blue
            });
            ChangePixelsValue(image, greenLookUpTable, new List <int>()
            {
                ColorChannel.Green
            });
        }
Esempio n. 2
0
        public unsafe static HistogramData GenerateHistogramData(WriteableBitmap image)
        {
            HistogramData result = new HistogramData();

            byte *imagePointer = (byte *)image.BackBuffer;
            int   stride       = image.BackBufferStride;

            for (int i = 0; i < image.PixelHeight; i++)
            {
                for (int j = 0; j < image.PixelWidth; j++)
                {
                    int index = i * stride + j * ImageConstants.bytesPerPixel;
                    result.BlueData[imagePointer[index]]++;

                    index++;
                    result.GreenData[imagePointer[index]]++;

                    index++;
                    result.RedData[imagePointer[index]]++;
                }
            }

            return(result);
        }