Пример #1
0
        static private (ushort l, ushort a, ushort b) GetDicomColor(ColorMine.ColorSpaces.ColorSpace color)
        {
            var    lab = color.To <ColorMine.ColorSpaces.Lab>();
            ushort l   = (ushort)(lab.L * 0.01 * ushort.MaxValue);
            ushort a   = (ushort)((Math.Clamp(((lab.A + 128) / 255), 0.0, 1.0)) * ushort.MaxValue);
            ushort b   = (ushort)((Math.Clamp(((lab.B + 128) / 255), 0.0, 1.0)) * ushort.MaxValue);

            return(l, a, b);
        }
Пример #2
0
        static private void AddText(DicomPre pre, string text, float x, float y, float width, float height, int horizontalAlignment, int verticalAlignment, bool useBoundingBox, bool showAnchor, ColorMine.ColorSpaces.ColorSpace color, int fileIndex = 0, int layerIndex = 0)
        {
            float x1 = x;
            float y1 = y;
            float x2 = x + width;
            float y2 = y + height;

            var textObjectItem = new DicomDataset();

            if (useBoundingBox)
            {
                textObjectItem.Add(DicomTag.BoundingBoxAnnotationUnits, "PIXEL");
                textObjectItem.Add(DicomTag.BoundingBoxTopLeftHandCorner, x1, y1);
                textObjectItem.Add(DicomTag.BoundingBoxBottomRightHandCorner, x2, y2);
                textObjectItem.Add(DicomTag.BoundingBoxTextHorizontalJustification, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER");
            }
            else
            {
                textObjectItem.Add(DicomTag.AnchorPointAnnotationUnits, "PIXEL");
                textObjectItem.Add(DicomTag.AnchorPointVisibility, showAnchor ? "Y" : "N");
                textObjectItem.Add(DicomTag.AnchorPoint, x1, y1);
                textObjectItem.Add(DicomTag.BoundingBoxTextHorizontalJustification, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER");
            }
            textObjectItem.Add(DicomTag.UnformattedTextValue, Encoding.UTF8, text);

            var textStyleSequence     = new DicomSequence(DicomTag.TextStyleSequence);
            var textStyleSequenceItem = new DicomDataset();

            textStyleSequenceItem.Add(DicomTag.HorizontalAlignment, horizontalAlignment == 0 ? "LEFT" : horizontalAlignment == 1 ? "RIGHT" : "CENTER");
            textStyleSequenceItem.Add(DicomTag.VerticalAlignment, verticalAlignment == 0 ? "BOTTOM" : verticalAlignment == 1 ? "TOP" : "CENTER");
            if (color != null)
            {
                var dicomColor = GetDicomColor(color);
                textStyleSequenceItem.Add(DicomTag.TextColorCIELabValue, dicomColor.l, dicomColor.a, dicomColor.b);
            }
            textStyleSequence.Items.Add(textStyleSequenceItem);
            textObjectItem.Add(textStyleSequence);

            pre.TextObjectSequences[fileIndex][layerIndex].Items.Add(textObjectItem);
        }
Пример #3
0
        static private void AddEllipse(DicomPre pre, float x, float y, float width, float height, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0)
        {
            float x1 = x + width * 0.5F;
            float y1 = y;

            float x2 = x + width * 0.5F;
            float y2 = y + height;

            float x3 = x;
            float y3 = y + height * 0.5F;

            float x4 = x + width;
            float y4 = y + height * 0.5F;

            var graphicObjectItem = new DicomDataset
            {
                { DicomTag.GraphicAnnotationUnits, "PIXEL" },
                { DicomTag.GraphicDimensions, (ushort)2 },
                { DicomTag.NumberOfGraphicPoints, (ushort)4 },
                { DicomTag.GraphicType, "ELLIPSE" },
                { DicomTag.GraphicFilled, "N" },
                { DicomTag.GraphicData, x1, y1, x2, y2, x3, y3, x4, y4 },
            };

            AddLineStyleSequence(graphicObjectItem, thickness, lineColor);
            pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem);
        }
Пример #4
0
        static private void AddCircle(DicomPre pre, float x, float y, float diameter, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0)
        {
            float x1 = x + diameter * 0.5F;
            float y1 = y + diameter * 0.5F;

            float x2 = x;
            float y2 = y;

            var graphicObjectItem = new DicomDataset
            {
                { DicomTag.GraphicAnnotationUnits, "PIXEL" },
                { DicomTag.GraphicDimensions, (ushort)2 },
                { DicomTag.NumberOfGraphicPoints, (ushort)2 },
                { DicomTag.GraphicType, "CIRCLE" },
                { DicomTag.GraphicFilled, "N" },
                { DicomTag.GraphicData, x1, y1, x2, y2 },
            };

            AddLineStyleSequence(graphicObjectItem, thickness, lineColor);
            pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem);
        }
Пример #5
0
        static private void AddPoint(DicomPre pre, float x, float y, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor, int fileIndex = 0, int layerIndex = 0)
        {
            var graphicObjectItem = new DicomDataset
            {
                { DicomTag.GraphicAnnotationUnits, "PIXEL" },
                { DicomTag.GraphicDimensions, (ushort)2 },
                { DicomTag.NumberOfGraphicPoints, (ushort)1 },
                { DicomTag.GraphicType, "POINT" },
                { DicomTag.GraphicFilled, "N" },
                { DicomTag.GraphicData, x, y },
            };

            AddLineStyleSequence(graphicObjectItem, thickness, lineColor);

            pre.GraphicObjectSequences[fileIndex][layerIndex].Items.Add(graphicObjectItem);
        }
Пример #6
0
        static private void AddLineStyleSequence(DicomDataset graphicObjectDataset, float thickness, ColorMine.ColorSpaces.ColorSpace lineColor)
        {
            DicomSequence lineStyleSequence = new DicomSequence(DicomTag.LineStyleSequence);
            DicomDataset  lineStyleDataset  = new DicomDataset();

            if (lineColor != null)
            {
                var dicomColor = GetDicomColor(lineColor);
                lineStyleDataset.Add(DicomTag.PatternOnColorCIELabValue, dicomColor.l, dicomColor.a, dicomColor.b);
            }
            lineStyleDataset.Add(DicomTag.LineThickness, thickness);
            lineStyleSequence.Items.Add(lineStyleDataset);
            graphicObjectDataset.Add(lineStyleSequence);
        }