public static void SaveSegmentation(SegmenterImageStackSaveDescription segmenterImageStackSaveDescription)
        {
            var colorMapVolumeDescription = segmenterImageStackSaveDescription.VolumeDescriptions.Get("ColorMap");
            var colorMapDirectory         = segmenterImageStackSaveDescription.Directories.Get("ColorMap");

            Directory.CreateDirectory(colorMapDirectory);

            colorMapVolumeDescription.DataStream.Seek(0, SeekOrigin.Begin);

            for (var z = 0; z < colorMapVolumeDescription.NumVoxelsZ; z++)
            {
                var image = new Image <Rgb, Byte>(colorMapVolumeDescription.NumVoxelsX, colorMapVolumeDescription.NumVoxelsY);

                for (var y = 0; y < colorMapVolumeDescription.NumVoxelsY; y++)
                {
                    for (var x = 0; x < colorMapVolumeDescription.NumVoxelsX; x++)
                    {
                        var colorMapValue = colorMapVolumeDescription.DataStream.Read <int>();
                        var r             = (colorMapValue & (0x0000ff << 0)) >> 0;
                        var g             = (colorMapValue & (0x0000ff << 8)) >> 8;
                        var b             = (colorMapValue & (0x0000ff << 16)) >> 16;

                        image[y, x] = new Rgb(r, g, b);
                    }
                }

                image.Save(Path.Combine(colorMapDirectory, String.Format("{0:0000}.png", z)));
            }

            var idMapVolumeDescription = segmenterImageStackSaveDescription.VolumeDescriptions.Get("IdMap");
            var idMapDirectory         = segmenterImageStackSaveDescription.Directories.Get("IdMap");

            Interop.SegmenterImageStackLoader.SaveIdImages(idMapVolumeDescription, idMapDirectory);
        }
예제 #2
0
        public void SaveSegmentationAs(SegmenterImageStackSaveDescription segmenterImageStackSaveDescription)
        {
            CommitSegmentation();

            var colorMapDataStream =
                new DataStream(
                    Interop.VolumeDescription.NumVoxelsX * Interop.VolumeDescription.NumVoxelsY * Interop.VolumeDescription.NumVoxelsZ * NUM_BYTES_PER_COLOR_MAP_PIXEL,
                    true,
                    true);
            var idMapDataStream =
                new DataStream(
                    Interop.VolumeDescription.NumVoxelsX * Interop.VolumeDescription.NumVoxelsY * Interop.VolumeDescription.NumVoxelsZ * NUM_BYTES_PER_COLOR_MAP_PIXEL,
                    true,
                    true);

            var volumeDescriptions = new Dictionary <VolumeDescription>
            {
                {
                    "ColorMap", new VolumeDescription
                    {
                        DxgiFormat       = Format.R8G8B8A8_UNorm,
                        DataStream       = colorMapDataStream,
                        Data             = colorMapDataStream.DataPointer,
                        NumBytesPerVoxel = NUM_BYTES_PER_COLOR_MAP_PIXEL,
                        NumVoxelsX       = Interop.VolumeDescription.NumVoxelsX,
                        NumVoxelsY       = Interop.VolumeDescription.NumVoxelsY,
                        NumVoxelsZ       = Interop.VolumeDescription.NumVoxelsZ,
                        IsSigned         = false
                    }
                },
                {
                    "IdMap", new VolumeDescription
                    {
                        DxgiFormat       = Format.R32_UInt,
                        DataStream       = idMapDataStream,
                        Data             = idMapDataStream.DataPointer,
                        NumBytesPerVoxel = NUM_BYTES_PER_ID_MAP_PIXEL,
                        NumVoxelsX       = Interop.VolumeDescription.NumVoxelsX,
                        NumVoxelsY       = Interop.VolumeDescription.NumVoxelsY,
                        NumVoxelsZ       = Interop.VolumeDescription.NumVoxelsZ,
                        IsSigned         = false
                    }
                },
            };

            Interop.SaveSegmentationAs(volumeDescriptions);

            segmenterImageStackSaveDescription.VolumeDescriptions = volumeDescriptions;

            SegmenterImageStackLoader.SaveSegmentation(segmenterImageStackSaveDescription);
        }