示例#1
0
        /// <summary>
        /// Converts a volume set of images into a sequential series of values.
        /// </summary>
        /// <param name="dimensions">The XYZ dimensions of the volume.</param>
        /// <param name="paths">The set of image paths comprising the volume.</param>
        /// <returns>The set of sequential values for the volume.</returns>
        private int[] FillSequentialData(Vector3Int dimensions, List <string> paths)
        {
            var data    = new List <int>(dimensions.x * dimensions.y * dimensions.z);
            var texture = new Texture2D(1, 1);

            foreach (var path in paths)
            {
                byte[] bytes = File.ReadAllBytes(path);
                texture.LoadImage(bytes);

                Color[] pixels    = texture.GetPixels(); // Order priority: X -> Y -> Z
                int[]   imageData = DensityHelper.ConvertColorsToDensities(pixels);

                data.AddRange(imageData);
            }

            return(data.ToArray());
        }
        /// <summary>
        /// Converts a volume set of images into a sequential series of values.
        /// </summary>
        /// <param name="dimensions">The XYZ dimensions of the volume.</param>
        /// <param name="paths">The set of image paths comprising the volume.</param>
        /// <returns>The set of sequential values for the volume.</returns>
        private int[] FillSequentialData(Vector3Int dimensions, List <string> paths)
        {
            var data    = new List <int>(dimensions.x * dimensions.y * dimensions.z);
            var texture = new Texture2D(1, 1);

            foreach (var path in paths)
            {
                byte[] bytes = File.ReadAllBytes(path);
                texture.LoadImage(bytes);

                if (texture.width != dimensions.x || texture.height != dimensions.y)
                {
                    Texture2D.DestroyImmediate(texture);
                    throw new IndexOutOfRangeException("Image sequence has non-uniform dimensions");
                }

                Color[] pixels    = texture.GetPixels(); // Order priority: X -> Y -> Z
                int[]   imageData = DensityHelper.ConvertColorsToDensities(pixels);

                data.AddRange(imageData);
            }
            Texture2D.DestroyImmediate(texture);
            return(data.ToArray());
        }