Esempio n. 1
0
        static public ushort[] CreateDarkMedian(AstroPhoto.LibRaw.Instance libraw, string path)
        {
            var rawDir     = System.IO.Path.Combine(path, "RAW");
            var stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");

            ushort[][] pixels = new ushort[stackFiles.Length][];
            int        size   = -1;

            for (int i = 0; i < stackFiles.Length; i++)
            {
                using (var rawImage = libraw.load_raw(stackFiles[i])) {
                    size      = rawImage.Height * rawImage.Width;
                    pixels[i] = rawImage.GetRawPixels();
                }
            }
            ushort[] median = new ushort[size];
            for (int i = 0; i < size; i++)
            {
                ushort[] line = new ushort[stackFiles.Length];
                for (int j = 0; j < stackFiles.Length; j++)
                {
                    line[j] = pixels[j][i];
                }
                Array.Sort(line);
                if (stackFiles.Length % 2 == 0)
                {
                    median[i] = (ushort)((line[stackFiles.Length / 2 - 1] + line[stackFiles.Length / 2]) / 2);
                }
                else
                {
                    median[i] = line[stackFiles.Length / 2];
                }
            }
            return(median);
        }
Esempio n. 2
0
        private RawImage loadRaw(string filePath)
        {
            var ext = System.IO.Path.GetExtension(filePath).ToLower();

            if (ext == ".cfa" || ext == ".fit")
            {
                return(new RawImage(filePath));
            }
            return(libraw.load_raw(filePath));
        }
Esempio n. 3
0
        static public float[] CreateDarkAvg(AstroPhoto.LibRaw.Instance libraw, string path, out int width, out int height)
        {
            var rawDir     = System.IO.Path.Combine(path, "RAW");
            var stackFiles = System.IO.Directory.GetFiles(rawDir, "*.arw");

            float[] sum  = null;
            int     size = 0;

            width  = 0;
            height = 0;
            for (int i = 0; i < stackFiles.Length; i++)
            {
                using (var rawImage = libraw.load_raw(stackFiles[i])) {
                    if (sum == null)
                    {
                        width  = rawImage.Width;
                        height = rawImage.Height;
                        size   = width * height;
                        sum    = new float[size];
                        for (int j = 0; j < size; j++)
                        {
                            sum[j] = 0.0f;
                        }
                    }
                    ushort[] _pixels = rawImage.GetRawPixels();
                    for (int j = 0; j < size; j++)
                    {
                        sum[j] += _pixels[j];
                    }
                }
            }
            for (int j = 0; j < sum.Length; j++)
            {
                sum[j] /= stackFiles.Length;
            }
            return(sum);
        }