public void FromDataset_WindowCenterWidth_ReturnsSameAsFromWindowLevel(
            ushort bitsAllocated,
            ushort bitsStored,
            ushort pixelRepresentation,
            double rescaleSlope,
            double rescaleIntercept,
            double windowWidth,
            double windowCenter,
            string voiLutFunction)
        {
            var dataset = new DicomDataset(
                new DicomCodeString(DicomTag.PhotometricInterpretation, "MONOCHROME1"),
                new DicomUnsignedShort(DicomTag.BitsAllocated, bitsAllocated),
                new DicomUnsignedShort(DicomTag.BitsStored, bitsStored),
                new DicomUnsignedShort(DicomTag.PixelRepresentation, pixelRepresentation),
                new DicomDecimalString(DicomTag.RescaleSlope, (decimal)rescaleSlope),
                new DicomDecimalString(DicomTag.RescaleIntercept, (decimal)rescaleIntercept),
                new DicomDecimalString(DicomTag.WindowWidth, (decimal)windowWidth),
                new DicomDecimalString(DicomTag.WindowCenter, (decimal)windowCenter),
                new DicomCodeString(DicomTag.VOILUTFunction, voiLutFunction));

            var expected = GrayscaleRenderOptions.FromWindowLevel(dataset);
            var actual   = GrayscaleRenderOptions.FromDataset(dataset);

            Assert.Equal(expected.WindowWidth, actual.WindowWidth);
            Assert.Equal(expected.WindowCenter, actual.WindowCenter);
        }
        public void ColorMap_Monochrome2ImageOptions_ReturnsMonochrome2ColorMap()
        {
            var file    = DicomFile.Open(@".\Test Data\CT1_J2KI");
            var options = GrayscaleRenderOptions.FromDataset(file.Dataset);

            Assert.Same(ColorTable.Monochrome2, options.ColorMap);
        }
        public void FromDataset_PixelLimits_ReturnsSameAsFromImagePixelValueTags(
            ushort bitsAllocated,
            ushort bitsStored,
            double rescaleSlope,
            double rescaleIntercept,
            short smallestImagePixelValue,
            short largestImagePixelValue,
            string voiLutFunction,
            double expectedWindowWidth,
            double expectedWindowCenter)
        {
            var dataset = new DicomDataset(
                new DicomCodeString(DicomTag.PhotometricInterpretation, "MONOCHROME1"),
                new DicomUnsignedShort(DicomTag.BitsAllocated, bitsAllocated),
                new DicomUnsignedShort(DicomTag.BitsStored, bitsStored),
                new DicomUnsignedShort(DicomTag.PixelRepresentation, 1),
                new DicomDecimalString(DicomTag.RescaleSlope, (decimal)rescaleSlope),
                new DicomDecimalString(DicomTag.RescaleIntercept, (decimal)rescaleIntercept),
                new DicomSignedShort(DicomTag.SmallestImagePixelValue, smallestImagePixelValue),
                new DicomSignedShort(DicomTag.LargestImagePixelValue, largestImagePixelValue),
                new DicomCodeString(DicomTag.VOILUTFunction, voiLutFunction));

            var expected = GrayscaleRenderOptions.FromImagePixelValueTags(dataset);
            var actual   = GrayscaleRenderOptions.FromDataset(dataset);

            Assert.Equal(expected.WindowWidth, actual.WindowWidth);
            Assert.Equal(expected.WindowCenter, actual.WindowCenter);
        }
示例#4
0
        private void CreatePipeline()
        {
            if (_pipeline != null)
            {
                return;
            }

            var pi = Dataset.Get <PhotometricInterpretation>(DicomTag.PhotometricInterpretation);

            if (pi == PhotometricInterpretation.Monochrome1 || pi == PhotometricInterpretation.Monochrome2)
            {
                if (_renderOptions == null)
                {
                    _renderOptions = GrayscaleRenderOptions.FromDataset(Dataset);
                }
                _pipeline = new GenericGrayscalePipeline(_renderOptions);
            }
            else if (pi == PhotometricInterpretation.Rgb)
            {
                _pipeline = new RgbColorPipeline();
            }
            else
            {
                throw new DicomImagingException("Unsupported pipeline photometric interpretation: {0}", pi.Value);
            }
        }
        public void ColorMap_Setter_ReturnsSetColorMap()
        {
            var file    = DicomFile.Open(@".\Test Data\CT1_J2KI");
            var options = GrayscaleRenderOptions.FromDataset(file.Dataset);

            options.ColorMap = ColorTable.Monochrome1;
            Assert.Same(ColorTable.Monochrome1, options.ColorMap);
        }
示例#6
0
        /// <summary>
        /// Create image rendering pipeline according to the Dataset <see cref="PhotometricInterpretation"/>.
        /// </summary>
        private void CreatePipeline()
        {
            if (_pipeline != null)
            {
                return;
            }

            var pi      = Dataset.Get <PhotometricInterpretation>(DicomTag.PhotometricInterpretation);
            var samples = Dataset.Get <ushort>(DicomTag.SamplesPerPixel, 0, 0);

            // temporary fix for JPEG compressed YBR images
            if ((Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 || Dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) && samples == 3)
            {
                pi = PhotometricInterpretation.Rgb;
            }

            // temporary fix for JPEG 2000 Lossy images
            if (pi == PhotometricInterpretation.YbrIct || pi == PhotometricInterpretation.YbrRct)
            {
                pi = PhotometricInterpretation.Rgb;
            }

            if (pi == null)
            {
                // generally ACR-NEMA
                if (samples == 0 || samples == 1)
                {
                    if (Dataset.Contains(DicomTag.RedPaletteColorLookupTableData))
                    {
                        pi = PhotometricInterpretation.PaletteColor;
                    }
                    else
                    {
                        pi = PhotometricInterpretation.Monochrome2;
                    }
                }
                else
                {
                    // assume, probably incorrectly, that the image is RGB
                    pi = PhotometricInterpretation.Rgb;
                }
            }

            if (pi == PhotometricInterpretation.Monochrome1 || pi == PhotometricInterpretation.Monochrome2)
            {
                //Monochrom1 or Monochrome2 for grayscale image
                if (_renderOptions == null)
                {
                    _renderOptions = GrayscaleRenderOptions.FromDataset(Dataset);
                }
                _pipeline = new GenericGrayscalePipeline(_renderOptions);
            }
            else if (pi == PhotometricInterpretation.Rgb)
            {
                //RGB for color image
                _pipeline = new RgbColorPipeline();
            }
            else if (pi == PhotometricInterpretation.PaletteColor)
            {
                //PALETTE COLOR for Palette image
                _pipeline = new PaletteColorPipeline(PixelData);
            }
            else
            {
                throw new DicomImagingException("Unsupported pipeline photometric interpretation: {0}", pi.Value);
            }
        }
示例#7
0
        /// <summary>
        /// Create image rendering pipeline according to the <see cref="DicomPixelData.PhotometricInterpretation">photometric interpretation</see>
        /// of the pixel data.
        /// </summary>
        private static PipelineData CreatePipelineData(DicomDataset dataset, DicomPixelData pixelData)
        {
            var pi      = pixelData.PhotometricInterpretation;
            var samples = dataset.GetSingleValueOrDefault(DicomTag.SamplesPerPixel, (ushort)0);

            // temporary fix for JPEG compressed YBR images
            if ((dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess1 ||
                 dataset.InternalTransferSyntax == DicomTransferSyntax.JPEGProcess2_4) && samples == 3)
            {
                pi = PhotometricInterpretation.Rgb;
            }

            // temporary fix for JPEG 2000 Lossy images
            if (pi == PhotometricInterpretation.YbrIct || pi == PhotometricInterpretation.YbrRct)
            {
                pi = PhotometricInterpretation.Rgb;
            }

            if (pi == null)
            {
                // generally ACR-NEMA
                if (samples == 0 || samples == 1)
                {
                    pi = dataset.Contains(DicomTag.RedPaletteColorLookupTableData)
                        ? PhotometricInterpretation.PaletteColor
                        : PhotometricInterpretation.Monochrome2;
                }
                else
                {
                    // assume, probably incorrectly, that the image is RGB
                    pi = PhotometricInterpretation.Rgb;
                }
            }

            IPipeline pipeline;
            GrayscaleRenderOptions renderOptions = null;

            if (pi == PhotometricInterpretation.Monochrome1 || pi == PhotometricInterpretation.Monochrome2)
            {
                //Monochrome1 or Monochrome2 for grayscale image
                renderOptions = GrayscaleRenderOptions.FromDataset(dataset);
                pipeline      = new GenericGrayscalePipeline(renderOptions);
            }
            else if (pi == PhotometricInterpretation.Rgb || pi == PhotometricInterpretation.YbrFull ||
                     pi == PhotometricInterpretation.YbrFull422 || pi == PhotometricInterpretation.YbrPartial422)
            {
                //RGB for color image
                pipeline = new RgbColorPipeline();
            }
            else if (pi == PhotometricInterpretation.PaletteColor)
            {
                //PALETTE COLOR for Palette image
                pipeline = new PaletteColorPipeline(pixelData);
            }
            else
            {
                throw new DicomImagingException("Unsupported pipeline photometric interpretation: {0}", pi);
            }

            return(new PipelineData {
                Pipeline = pipeline, RenderOptions = renderOptions
            });
        }