Пример #1
0
        public static Func <byte, byte, byte, Pixel> Equalize(PNM pnm)
        {
            double[] rawDataR   = pnm.GetHistogramRed();
            double[] rawDataG   = pnm.GetHistogramGreen();
            double[] rawDataB   = pnm.GetHistogramBlue();
            double[] rlum       = new double[256];
            double[] glum       = new double[256];
            double[] blum       = new double[256];
            double   cumulatedR = 0;
            double   cumulatedG = 0;
            double   cumulatedB = 0;

            for (int i = 0; i < 256; i++)
            {
                cumulatedR += rawDataR[i];
                cumulatedG += rawDataG[i];
                cumulatedB += rawDataB[i];
                rlum[i]     = cumulatedR;
                glum[i]     = cumulatedG;
                blum[i]     = cumulatedB;
            }
            return((r, g, b) =>
            {
                return new Pixel(Convert.ToByte(rlum[r] * 255), Convert.ToByte(glum[g] * 255), Convert.ToByte(blum[b] * 255));
            });
        }
Пример #2
0
 public static Func<byte, byte, byte, Pixel> Equalize(PNM pnm)
 {
     double[] rawDataR = pnm.GetHistogramRed();
     double[] rawDataG = pnm.GetHistogramGreen();
     double[] rawDataB = pnm.GetHistogramBlue();
     double[] rlum = new double[256];
     double[] glum = new double[256];
     double[] blum = new double[256];
     double cumulatedR = 0;
     double cumulatedG = 0;
     double cumulatedB = 0;
     for (int i = 0; i < 256; i++)
     {
         cumulatedR += rawDataR[i];
         cumulatedG += rawDataG[i];
         cumulatedB += rawDataB[i];
         rlum[i] = cumulatedR;
         glum[i] = cumulatedG;
         blum[i] = cumulatedB;
     }
     return (r, g, b) =>
     {
         return new Pixel(Convert.ToByte(rlum[r] * 255), Convert.ToByte(glum[g] * 255), Convert.ToByte(blum[b] * 255));
     };
 }
Пример #3
0
        public static Func<byte, byte, byte, Pixel> Stretch(PNM pnm)
        {
            double[] histogramR = pnm.GetHistogramRed();
            double[] histogramG = pnm.GetHistogramGreen();
            double[] histogramB = pnm.GetHistogramBlue();
            double[] cumulativeR = CumulativeHistogram(histogramR);
            double[] cumulativeG = CumulativeHistogram(histogramG);
            double[] cumulativeB = CumulativeHistogram(histogramB);

            Tuple<int, int> rangeR = FindPercentiles(cumulativeR);
            Tuple<int, int> rangeG = FindPercentiles(cumulativeG);
            Tuple<int, int> rangeB = FindPercentiles(cumulativeB);

            int[] LUTR = GetStretchLUT(histogramR, rangeR.Item1, rangeR.Item2);
            int[] LUTG = GetStretchLUT(histogramG, rangeG.Item1, rangeG.Item2);
            int[] LUTB = GetStretchLUT(histogramB, rangeB.Item1, rangeB.Item2);

            return (r, g, b) =>
            {
                return new Pixel(Convert.ToByte(LUTR[r]), Convert.ToByte(LUTG[g]), Convert.ToByte(LUTB[b]));
            };
        }
Пример #4
0
        public static Func <byte, byte, byte, Pixel> Stretch(PNM pnm)
        {
            double[] histogramR  = pnm.GetHistogramRed();
            double[] histogramG  = pnm.GetHistogramGreen();
            double[] histogramB  = pnm.GetHistogramBlue();
            double[] cumulativeR = CumulativeHistogram(histogramR);
            double[] cumulativeG = CumulativeHistogram(histogramG);
            double[] cumulativeB = CumulativeHistogram(histogramB);

            Tuple <int, int> rangeR = FindPercentiles(cumulativeR);
            Tuple <int, int> rangeG = FindPercentiles(cumulativeG);
            Tuple <int, int> rangeB = FindPercentiles(cumulativeB);

            int[] LUTR = GetStretchLUT(histogramR, rangeR.Item1, rangeR.Item2);
            int[] LUTG = GetStretchLUT(histogramG, rangeG.Item1, rangeG.Item2);
            int[] LUTB = GetStretchLUT(histogramB, rangeB.Item1, rangeB.Item2);

            return((r, g, b) =>
            {
                return new Pixel(Convert.ToByte(LUTR[r]), Convert.ToByte(LUTG[g]), Convert.ToByte(LUTB[b]));
            });
        }