Ejemplo n.º 1
0
        public Shader DistanceHSV()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod());
            var hsv = new ColorMine.ColorSpaces.Hsv();

            double[] transform;
            //transform= Transform.Sin(distance);
            transform = Helper.NormalizeArray(distance);

            for (int i = transform.Length - 1; i > 0; i--)
            {
                //double temp = (!double.IsNaN(distance[i]) ? distance[i]: 0 ); //broken
                //double x = (temp != 0) ? distance[i] * 360 : 0; //broken

                double x = transform[i] * 360;
                hsv.H = x;
                hsv.S = 1;
                hsv.V = 1;

                var rgb = hsv.ToRgb();
                int r   = (int)rgb.R;
                int g   = (int)rgb.G;
                int b   = (int)rgb.B;

                canvas[i] = 255 << 24 | r << 16 | g << 8 | b << 0;
            }
            return(this);
        }
Ejemplo n.º 2
0
        static private void PresentationStatePerInstanceTest(string studyDirectoryPath, string outputFileName, string seriesDescription, int totalFigureCount)
        {
            string[] files = Directory.GetFiles(studyDirectoryPath);

            string[] sourceFilePaths = files.Where(a => DicomFile.Open(a).Dataset.GetSingleValue <string>(DicomTag.Modality) != "PR").OrderBy(a => DicomFile.Open(a).Dataset.GetSingleValue <int>(DicomTag.InstanceNumber)).ToArray();

            const float thickness      = 2F;
            int         figurePerFrame = totalFigureCount / sourceFilePaths.Length + 1;

            totalFigureCount = figurePerFrame * sourceFilePaths.Length;
            int totalFigureIndex = 0;

            for (int sourceFileIndex = 0; sourceFileIndex != sourceFilePaths.Length; sourceFileIndex++)
            {
                var   pre          = CreatePresentationState(new string[] { sourceFilePaths[sourceFileIndex] }, true, seriesDescription);
                float minImageSize = MathF.Min(pre.Columns, pre.Rows);
                float size         = minImageSize / 4;
                for (int figureIndex = 0; figureIndex != figurePerFrame; figureIndex++, totalFigureIndex++)
                {
                    ColorMine.ColorSpaces.Hsv color = new ColorMine.ColorSpaces.Hsv {
                        H = ((float)totalFigureIndex / totalFigureCount) * 360, S = 1F, V = 1F
                    };
                    float offset = thickness + ((float)totalFigureIndex / totalFigureCount) * (minImageSize - size);
                    AddPolyline(pre, offset, offset, size - thickness * 2, size - thickness * 2, thickness, color, 0, 0);
                }

                string destFilePath = Path.Combine(studyDirectoryPath, Path.GetFileNameWithoutExtension(outputFileName) + $"-{sourceFileIndex}.dcm");
                EnsureDirectories(Path.GetDirectoryName(destFilePath));
                new DicomFile(pre.PresentationStateDataset).Save(destFilePath);
            }
        }
Ejemplo n.º 3
0
        static private void LayerTest(string studyDirectoryPath, string outputFileName, string seriesDescription)
        {
            string[] files = Directory.GetFiles(studyDirectoryPath);

            string sourceFilePath = files.Single(a => DicomFile.Open(a).Dataset.GetSingleValue <string>(DicomTag.Modality) != "PR");

            const int   layerCount   = 25;
            var         pre          = CreatePresentationState(new[] { sourceFilePath }, true, seriesDescription, layerCount);
            const float thickness    = 5F;
            float       size         = MathF.Min(pre.Columns, pre.Rows) - thickness * (layerCount + 2);
            List <int>  layerIndices = new List <int>();

            for (int layerIndex = 0; layerIndex != layerCount; layerIndex++)
            {
                layerIndices.Add(layerIndex);
            }
            for (int figureIndex = 0; figureIndex != layerCount; figureIndex++)
            {
                ColorMine.ColorSpaces.Hsv color = new ColorMine.ColorSpaces.Hsv {
                    H = ((float)figureIndex / layerCount) * 360, S = 1F, V = 1F
                };
                float offset     = thickness * (figureIndex + 1);
                int   layerIndex = figureIndex < layerCount / 2 ? 0 : layerIndices.Count - 1;
                AddPolyline(pre, offset, offset, size, size, thickness, color, 0, layerIndices[layerIndex]);
                layerIndices.RemoveAt(layerIndex);
            }

            string destFilePath = Path.Combine(studyDirectoryPath, Path.GetFileNameWithoutExtension(outputFileName) + ".dcm");

            EnsureDirectories(Path.GetDirectoryName(destFilePath));
            new DicomFile(pre.PresentationStateDataset).Save(destFilePath);
        }
        private Color defineColorRadial(double value, double max, double min)
        {
            Color  c       = Color.Wheat;
            double range   = max - min;
            double percent = (value - min) / range;

            ColorMine.ColorSpaces.Hsv hsv = new ColorMine.ColorSpaces.Hsv();
            hsv.H = 360 * percent;
            hsv.S = 0.7;
            hsv.V = 1;
            var rgb = hsv.To <ColorMine.ColorSpaces.Rgb>();

            c = Color.FromArgb((int)rgb.R, (int)rgb.G, (int)rgb.B);
            return(c);
        }
Ejemplo n.º 5
0
        public Shader ExposureHSV()
        {
            Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod());
            highestActual = Helper.GetMinMax(exposure).Item2;
            var hsv = new ColorMine.ColorSpaces.Hsv();

            Helper.NormalizeArray(exposure);
            for (int i = exposure.Length - 1; i > 0; i--)
            {
                double x = (exposure[i] != 0) ? exposure[i] * 360 : 0;
                hsv.H = x;
                hsv.S = 1;
                hsv.V = 1;

                var rgb = hsv.ToRgb();
                int r   = (int)rgb.R;
                int g   = (int)rgb.G;
                int b   = (int)rgb.B;

                canvas[i] = 255 << 24 | r << 16 | g << 8 | b << 0;
            }
            return(this);
        }
Ejemplo n.º 6
0
        static private void GraphicObjectTest(string studyDirectoryPath, string outputFileName, bool colorSoftcopy, string seriesDescription, GraphicObjectType figureType, string text = "", bool useBoundingBox = false, bool showAnchor = false)
        {
            string[] files = Directory.GetFiles(studyDirectoryPath);

            string sourceFilePath = files.Single(a => DicomFile.Open(a).Dataset.GetSingleValue <string>(DicomTag.Modality) != "PR");

            var         pre          = CreatePresentationState(new[] { sourceFilePath }, colorSoftcopy, seriesDescription);
            const float minThickness = 1F;
            const float maxThickness = 8F;

            for (float y = maxThickness; y + y * 0.25F + maxThickness * 0.5F <= pre.Rows; y += y * 0.25F + maxThickness * 2F)
            {
                int count = 0;
                for (float x = maxThickness; x + x * 0.25F + maxThickness * 0.5F <= pre.Columns; x += x * 0.25F + maxThickness * 2F, count++)
                {
                    float height    = y * 0.25F;
                    float width     = x * 0.25F;
                    float diameter  = Math.Min(width, height) * 0.5F;
                    float thickness = minThickness + (maxThickness - minThickness) * (x / pre.Columns);
                    ColorMine.ColorSpaces.Hsv color = new ColorMine.ColorSpaces.Hsv {
                        H = ((x + width) / pre.Columns) * 360, S = ((1F - (y) / pre.Rows)), V = (1F - ((y) / pre.Rows))
                    };
                    switch (figureType)
                    {
                    case GraphicObjectType.Point:
                        AddPoint(pre, x, y, thickness, colorSoftcopy ? color : null);
                        break;

                    case GraphicObjectType.Polyline:
                        AddPolyline(pre, x, y, width, height, thickness, colorSoftcopy ? color : null);
                        break;

                    case GraphicObjectType.Interpolated:
                        AddInterpolated(pre, x, y, width, height, thickness, colorSoftcopy ? color : null);
                        break;

                    case GraphicObjectType.Circle:
                        AddCircle(pre, x, y, diameter, thickness, colorSoftcopy ? color : null);
                        break;

                    case GraphicObjectType.Ellipse:
                        AddEllipse(pre, x, y, width, height, thickness, colorSoftcopy ? color : null);
                        break;

                    case GraphicObjectType.Text:
                        AddPolyline(pre, x, y, width, height, minThickness, null);
                        AddText(pre, text, x, y, width, height, count % 3, count % 4, useBoundingBox, showAnchor, colorSoftcopy ? color : null);
                        break;
                    }
                }
            }
            if (figureType == GraphicObjectType.Text && !useBoundingBox)
            {
                AddText(pre, text, pre.Columns * 0.5F, pre.Rows, 0, 0, 0, 0, false, showAnchor, colorSoftcopy ? new ColorMine.ColorSpaces.Rgb {
                    R = 255, G = 255, B = 255
                } : null);
                AddText(pre, text, pre.Columns, pre.Rows * 0.5F, 0, 0, 0, 0, false, showAnchor, colorSoftcopy ? new ColorMine.ColorSpaces.Rgb {
                    R = 255, G = 255, B = 255
                } : null);
            }
            string destFilePath = Path.Combine(studyDirectoryPath, Path.GetFileNameWithoutExtension(outputFileName) + ".dcm");

            EnsureDirectories(Path.GetDirectoryName(destFilePath));
            new DicomFile(pre.PresentationStateDataset).Save(destFilePath);
        }