Ejemplo n.º 1
0
        // Get a depth map from a single sub-aperture image grid
        public static double[][] GetDepthMap_Grid()
        {
            Lytro.CheckConstants_DEBUG();

            SceneView[][] views =
                Lytro.CreateViewArrayFromBitmap(new Bitmap("Images/sample2.bmp"));

            SceneView[] flattenedViews = views.SelectMany(inner => inner).ToArray();

            double[][] depthBuffer = DepthEstimator.CalculateDepthMap(flattenedViews[0],
                                                                      flattenedViews.Skip(1).ToArray());

            /*
             * // Take the log of every depth. This helps smooth out noise
             * for (int y = 0; y < depthBuffer.Length; y++)
             * {
             *  for (int x = 0; x < depthBuffer[0].Length; x++)
             *  {
             *      double depth = depthBuffer[y][x];
             *
             *      if (depth != DepthEstimator.Constants.InvalidDepth &&
             *          !double.IsInfinity(depth))
             *          depthBuffer[y][x] = Math.Log(depth);
             *  }
             * }
             */
            return(depthBuffer);
        }
Ejemplo n.º 2
0
        static LytroDepthEstimatorOld()
        {
            viewIndices = new Dictionary <SceneView, Point2Di>();

            SceneView[][] viewArr = Lytro.CreateEmptyViewArray();

            xLookup = new Tuple <int, int> [viewArr.Length][][];
            yLookup = new Tuple <int, int> [viewArr.Length][][];

            Debug.Assert(viewArr.Length == viewArr[0].Length &&
                         viewArr[0][0].Image.Width == viewArr[0][0].Image.Height,
                         "This algorithm relies on the Lytro image array and sub-images being square");

            int imgDim = viewArr[0][0].Image.Width;

            for (int sourceXY = 0; sourceXY < viewArr.Length; sourceXY++)
            {
                Tuple <int, int>[][] xSourceRow = new Tuple <int, int> [viewArr.Length][];
                Tuple <int, int>[][] ySourceRow = new Tuple <int, int> [viewArr.Length][];

                for (int targetXY = 0; targetXY < viewArr.Length; targetXY++)
                {
                    Tuple <int, int>[] xTargetRow = new Tuple <int, int> [imgDim];
                    Tuple <int, int>[] yTargetRow = new Tuple <int, int> [imgDim];

                    for (int pixelXY = 0; pixelXY < viewArr[0][0].Image.Width; pixelXY++)
                    {
                        Point2Df sourcePt = new Point2Df(pixelXY, pixelXY);

                        SceneView source = viewArr[sourceXY][sourceXY];
                        SceneView target = viewArr[targetXY][targetXY];

                        Point2Di endpoint1 =
                            source.FindInOtherView((Point2Df)sourcePt, target, MIN_DEPTH).Round();
                        Point2Di endpoint2 =
                            source.FindInOtherView((Point2Df)sourcePt, target, MAX_DEPTH).Round();

                        Tuple <int, int> xEndpointCoords =
                            new Tuple <int, int>(endpoint1.X, endpoint2.X);
                        Tuple <int, int> yEndpointCoords =
                            new Tuple <int, int>(endpoint1.Y, endpoint2.Y);

                        xTargetRow[pixelXY] = xEndpointCoords;
                        yTargetRow[pixelXY] = yEndpointCoords;
                    }

                    xSourceRow[targetXY] = xTargetRow;
                    ySourceRow[targetXY] = yTargetRow;
                }

                xLookup[sourceXY] = xSourceRow;
                yLookup[sourceXY] = ySourceRow;
            }

            Debug.WriteLine("Done preprocessing");
        }