瀏覽代碼

颈动脉裁剪

Jeremy 2 年之前
父節點
當前提交
4312955846
共有 2 個文件被更改,包括 66 次插入1 次删除
  1. 2 1
      Carotid/ResampleModel.cs
  2. 64 0
      Carotid/Utilities/ImageCrop.cs

+ 2 - 1
Carotid/ResampleModel.cs

@@ -339,7 +339,8 @@ namespace WingAIDiagnosisService.Carotid
                     {
                         CvInvoke.Imdecode(img.ImageData, ImreadModes.Grayscale, mat);
                         CvInvoke.Resize(mat, resizeImage, result.ResizeSize);
-                        result.Edge = ImageEdgeDetector.DetectImageEdge(resizeImage.Mat);
+                        //result.Edge = ImageEdgeDetector.DetectImageEdge(resizeImage.Mat);
+                        result.Edge = ImageCrop.CropImageByInfo(resizeImage.Mat, img, _scanDepth);
                     }
                 }
 

+ 64 - 0
Carotid/Utilities/ImageCrop.cs

@@ -0,0 +1,64 @@
+using System;
+using System.Collections.Generic;
+using Emgu.CV;
+using Emgu.CV.Structure;
+using System.Drawing;
+using WingServerCommon.Log;
+using WingAIDiagnosisService.Carotid.CarotidInterFacesData;
+using WingAIDiagnosisService.Carotid.MathTools;
+using WingAIDiagnosisService.Carotid.Utilities.DetectIntima;
+using Vinno.vCloud.Common.Vid2;
+using Vinno.vCloud.Common.Vid2.Visuals;
+using System.Linq;
+
+namespace WingAIDiagnosisService.Carotid.Utilities
+{
+    public class ImageCrop
+    {
+        //获取图像在物理坐标下的有效宽度(除去黑色背景区域)
+        public static float GetPhysicalWidth(VinnoImage vinnoImage)
+        {
+            if (vinnoImage.Visuals.First() is Vinno2DVisual visual)
+            {
+                if (visual.PhysicalCoordinates.ContainsKey(VinnoVisualAreaType.Tissue))
+                {
+                    var physicalCoordinate = visual.PhysicalCoordinates[VinnoVisualAreaType.Tissue];
+                    if (physicalCoordinate is VinnoTissuePhysicalCoordinate coordinate)
+                        return (float)(coordinate.Width);
+                }
+            }
+
+            return 0;
+        }
+
+        //通过VID文件的属性计算图像在像素坐标下的有效区域的坐标
+        public static ImageEdge CropImageByInfo(Mat mat, VinnoImage vinnoImage, float scanDepth)
+        {
+            //裁剪黑色背景之前图像的宽,像素单位
+            int imgWidth0 = mat.Width;
+            //图像的高,像素单位
+            int imgHeight = mat.Height;
+            ImageEdge edge = new ImageEdge(imgWidth0, imgHeight);
+            //图像的宽,物理单位,厘米
+            float physicalWidth = GetPhysicalWidth(vinnoImage);
+            //单位像素的物理距离
+            float cmPerPix = scanDepth / imgHeight;
+            //裁剪黑色背景后图像的有效宽度,像素单位
+            int imgWidth = (int) (physicalWidth / cmPerPix);
+            edge.Left = (imgWidth0 - imgWidth) / 2;
+            edge.Right = edge.Left + imgWidth;
+
+            ///把裁剪后的图像宽度调整为 4的倍数
+            ImageEdgeDetector.AdjustEdge(edge);
+            //reset if not valid
+            if (!edge.IsValid)
+            {
+                edge.Left = 0;
+                edge.Right = mat.Width - 1;
+                return edge;
+            }
+            return edge;
+        }
+
+    }
+}