public void FromImagePixelValueTags_ValidSignedInput_CorrectOutput(
            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 actual = GrayscaleRenderOptions.FromImagePixelValueTags(dataset);

            Assert.Equal(expectedWindowWidth, actual.WindowWidth);
            Assert.Equal(expectedWindowCenter, actual.WindowCenter);
        }
        public void FromImagePixelValueTags_SmallestGreaterThanLargest_Throws()
        {
            var dataset = new DicomDataset(
                new DicomCodeString(DicomTag.PhotometricInterpretation, "MONOCHROME1"),
                new DicomUnsignedShort(DicomTag.BitsAllocated, 8),
                new DicomUnsignedShort(DicomTag.BitsStored, 8),
                new DicomUnsignedShort(DicomTag.PixelRepresentation, 0),
                new DicomDecimalString(DicomTag.RescaleSlope, (decimal)1),
                new DicomDecimalString(DicomTag.RescaleIntercept, (decimal)0),
                new DicomUnsignedShort(DicomTag.SmallestImagePixelValue, 180),
                new DicomUnsignedShort(DicomTag.LargestImagePixelValue, 90),
                new DicomCodeString(DicomTag.VOILUTFunction, "LINEAR"));

            Assert.Throws <DicomImagingException>(() => GrayscaleRenderOptions.FromImagePixelValueTags(dataset));
        }
Exemplo n.º 3
0
        private void OnKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Right)
            {
                _frame++;
                if (_frame >= _image.NumberOfFrames)
                {
                    _frame--;
                }
                DisplayImage(_image);
                return;
            }

            if (e.KeyCode == Keys.Left)
            {
                _frame--;
                if (_frame < 0)
                {
                    _frame++;
                }
                DisplayImage(_image);
                return;
            }

            if (e.KeyCode == Keys.O)
            {
                _image.ShowOverlays = !_image.ShowOverlays;
                DisplayImage(_image);
                return;
            }

            GrayscaleRenderOptions options = null;

            if (e.KeyCode == Keys.D0)
            {
                options = GrayscaleRenderOptions.FromDataset(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D1)
            {
                options = GrayscaleRenderOptions.FromWindowLevel(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D2)
            {
                options = GrayscaleRenderOptions.FromImagePixelValueTags(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D3)
            {
                options = GrayscaleRenderOptions.FromMinMax(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D4)
            {
                options = GrayscaleRenderOptions.FromBitRange(_image.Dataset);
            }
            else if (e.KeyCode == Keys.D5)
            {
                options = GrayscaleRenderOptions.FromHistogram(_image.Dataset, 90);
            }

            if (options != null)
            {
                _image.WindowWidth  = options.WindowWidth;
                _image.WindowCenter = options.WindowCenter;

                DisplayImage(_image);
            }
        }