AutoBlineCalculationResults.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. using System;
  2. using System.Runtime.Serialization;
  3. using AI.Common;
  4. namespace AutoBlineCalculationLib
  5. {
  6. /// <summary>
  7. /// B线评分类别
  8. /// </summary>
  9. public enum EnumBlineScoreType
  10. {
  11. /// <summary>
  12. /// 空
  13. /// </summary>
  14. Null = 0,
  15. /// <summary>
  16. /// 孤立B线
  17. /// </summary>
  18. IsolatedBLine = 1,
  19. /// <summary>
  20. /// 融合B线
  21. /// </summary>
  22. FusionBLine = 2,
  23. /// <summary>
  24. /// 肺实变
  25. /// </summary>
  26. LungConsolidation = 3,
  27. }
  28. /// <summary>
  29. /// B线评分相关信息
  30. /// </summary>
  31. public struct BLineScoringInfo
  32. {
  33. private EnumBlineScoreType _type;
  34. private IUltrasoundImageRegion _ultrasoundImageRegion;
  35. /// <summary>
  36. /// B线评分类别
  37. /// </summary>
  38. public EnumBlineScoreType Type
  39. {
  40. get => _type;
  41. set => _type = value;
  42. }
  43. public IUltrasoundImageRegion UltrasoundImageRegion
  44. {
  45. get => _ultrasoundImageRegion;
  46. set => _ultrasoundImageRegion = value;
  47. }
  48. /// <summary>
  49. /// 构造函数
  50. /// </summary>
  51. /// <param name="type"></param>
  52. /// <param name="ultrasoundImageRegion"></param>
  53. public BLineScoringInfo(EnumBlineScoreType type, IUltrasoundImageRegion ultrasoundImageRegion)
  54. {
  55. _type = type;
  56. _ultrasoundImageRegion = ultrasoundImageRegion;
  57. }
  58. public static readonly BLineScoringInfo Empty = new BLineScoringInfo(EnumBlineScoreType.Null, null);
  59. public bool Equals(BLineScoringInfo other)
  60. {
  61. return Equals(this, other);
  62. }
  63. public static bool Equals(BLineScoringInfo one, BLineScoringInfo other)
  64. {
  65. if (one.Type != other.Type || one.UltrasoundImageRegion != other.UltrasoundImageRegion)
  66. {
  67. return false;
  68. }
  69. return true;
  70. }
  71. public override bool Equals(object obj)
  72. {
  73. if (obj == null || !(obj is BLineScoringInfo))
  74. {
  75. return false;
  76. }
  77. BLineScoringInfo other = (BLineScoringInfo)obj;
  78. return Equals(this, other);
  79. }
  80. public static bool operator ==(BLineScoringInfo one, BLineScoringInfo other)
  81. {
  82. return Equals(one, other);
  83. }
  84. public static bool operator !=(BLineScoringInfo one, BLineScoringInfo other)
  85. {
  86. return !Equals(one, other);
  87. }
  88. }
  89. /// <summary>
  90. /// B线模型分割类别
  91. /// </summary>
  92. public enum EnumBlineRecognizedObjectType
  93. {
  94. /// <summary>
  95. /// 空
  96. /// </summary>
  97. Null = 0,
  98. /// <summary>
  99. /// 胸膜线
  100. /// </summary>
  101. Pline = 1,
  102. /// <summary>
  103. /// B线
  104. /// </summary>
  105. Bline = 2,
  106. /// <summary>
  107. /// A线
  108. /// </summary>
  109. Aline = 3,
  110. /// <summary>
  111. /// 肺实变
  112. /// </summary>
  113. LungConsolidation = 4,
  114. }
  115. /// <summary>
  116. /// B线模型识别到的目标的相关信息
  117. /// </summary>
  118. public struct BlineRecognizedObjectInfo
  119. {
  120. private EnumBlineRecognizedObjectType _type;
  121. private float _confidence;
  122. private Point2D[] _contour;
  123. /// <summary>
  124. /// 被识别到的目标的类别
  125. /// </summary>
  126. public EnumBlineRecognizedObjectType Type
  127. {
  128. get => _type;
  129. set => _type = value;
  130. }
  131. /// <summary>
  132. /// 识别正确的可能性
  133. /// </summary>
  134. public float Confidence
  135. {
  136. get => _confidence;
  137. set => _confidence = value;
  138. }
  139. /// <summary>
  140. /// 该目标的轮廓
  141. /// </summary>
  142. public Point2D[] Contour
  143. {
  144. get => _contour;
  145. set => _contour = value;
  146. }
  147. /// <summary>
  148. /// 构造函数
  149. /// </summary>
  150. /// <param name="type"></param>
  151. /// <param name="confidence"></param>
  152. /// <param name="contour"></param>
  153. public BlineRecognizedObjectInfo(EnumBlineRecognizedObjectType type, float confidence, Point2D[] contour)
  154. {
  155. _type = type;
  156. _confidence = confidence;
  157. _contour = contour;
  158. }
  159. public static readonly BlineRecognizedObjectInfo Empty = new BlineRecognizedObjectInfo(EnumBlineRecognizedObjectType.Null, 0, Array.Empty<Point2D>());
  160. public bool Equals(BlineRecognizedObjectInfo other)
  161. {
  162. return Equals(this, other);
  163. }
  164. public static bool Equals(BlineRecognizedObjectInfo one, BlineRecognizedObjectInfo other)
  165. {
  166. if (one.Type != other.Type || one.Confidence != other.Confidence)
  167. {
  168. return false;
  169. }
  170. if (one.Contour == null && other.Contour == null)
  171. {
  172. return true;
  173. }
  174. if ((one.Contour == null && other.Contour != null) || (one.Contour != null && other.Contour == null))
  175. {
  176. return false;
  177. }
  178. if (one.Contour.Length != other.Contour.Length)
  179. {
  180. return false;
  181. }
  182. for (int ni = 0; ni < one.Contour.Length; ni++)
  183. {
  184. if (one.Contour[ni] != other.Contour[ni])
  185. {
  186. return false;
  187. }
  188. }
  189. return true;
  190. }
  191. public override bool Equals(object obj)
  192. {
  193. if (obj == null || !(obj is BlineRecognizedObjectInfo))
  194. {
  195. return false;
  196. }
  197. BlineRecognizedObjectInfo other = (BlineRecognizedObjectInfo)obj;
  198. return Equals(this, other);
  199. }
  200. public static bool operator ==(BlineRecognizedObjectInfo one, BlineRecognizedObjectInfo other)
  201. {
  202. return Equals(one, other);
  203. }
  204. public static bool operator !=(BlineRecognizedObjectInfo one, BlineRecognizedObjectInfo other)
  205. {
  206. return !Equals(one, other);
  207. }
  208. }
  209. /// <summary>
  210. /// 感兴趣区域相关信息
  211. /// </summary>
  212. public struct RegionOfInterestInfo
  213. {
  214. #region private
  215. private float _regionOfInterestScore;
  216. private IUltrasoundImageRegion _ultrasoundRegionOfInterest;
  217. #endregion
  218. /// <summary>
  219. /// 单帧图像中感兴趣区域得分
  220. /// </summary>
  221. public float RegionOfInterestScore
  222. {
  223. get => _regionOfInterestScore;
  224. set => _regionOfInterestScore = value;
  225. }
  226. public IUltrasoundImageRegion UltrasoundRegionOfInterest
  227. {
  228. get => _ultrasoundRegionOfInterest;
  229. set => _ultrasoundRegionOfInterest = value;
  230. }
  231. /// <summary>
  232. /// 构造函数
  233. /// </summary>
  234. /// <param name="ultrasoundRegionOfInterest"></param>
  235. /// <param name="ultrasoundRegionOfInterest"></param>
  236. public RegionOfInterestInfo(float regionOfInterestScore, IUltrasoundImageRegion ultrasoundRegionOfInterest)
  237. {
  238. _regionOfInterestScore = regionOfInterestScore;
  239. _ultrasoundRegionOfInterest = ultrasoundRegionOfInterest;
  240. }
  241. public static readonly RegionOfInterestInfo Empty = new RegionOfInterestInfo(0, null);
  242. public bool Equals(RegionOfInterestInfo other)
  243. {
  244. return Equals(this, other);
  245. }
  246. public static bool Equals(RegionOfInterestInfo one, RegionOfInterestInfo other)
  247. {
  248. if (one.RegionOfInterestScore != other.RegionOfInterestScore || one.UltrasoundRegionOfInterest != other.UltrasoundRegionOfInterest)
  249. {
  250. return false;
  251. }
  252. return true;
  253. }
  254. public override bool Equals(object obj)
  255. {
  256. if (obj == null || !(obj is RegionOfInterestInfo))
  257. {
  258. return false;
  259. }
  260. RegionOfInterestInfo other = (RegionOfInterestInfo)obj;
  261. return Equals(this, other);
  262. }
  263. public static bool operator ==(RegionOfInterestInfo one, RegionOfInterestInfo other)
  264. {
  265. return Equals(one, other);
  266. }
  267. public static bool operator !=(RegionOfInterestInfo one, RegionOfInterestInfo other)
  268. {
  269. return !Equals(one, other);
  270. }
  271. }
  272. /// <summary>
  273. /// 单幅图像的B线计算结果
  274. /// </summary>
  275. [DataContract]
  276. public struct BlineScoringResults
  277. {
  278. #region field
  279. private int _blineScore;
  280. private BLineScoringInfo[] _blineScoringInfo;
  281. private BlineRecognizedObjectInfo[] _recognizedObjects;
  282. private RegionOfInterestInfo _regionOfInterestInfo;
  283. #endregion
  284. #region public funcs
  285. /// <summary>
  286. /// 单幅图像中B线的评分
  287. /// </summary>
  288. public int BlineScore { get => _blineScore; set => _blineScore = value; }
  289. /// <summary>
  290. /// 单幅图像中B线计算的目标
  291. /// </summary>
  292. public BLineScoringInfo[] BlineScoringInfo
  293. {
  294. get => _blineScoringInfo;
  295. set => _blineScoringInfo = value;
  296. }
  297. /// <summary>
  298. /// B线模型分割目标
  299. /// </summary>
  300. public BlineRecognizedObjectInfo[] RecognizedObjects
  301. {
  302. get => _recognizedObjects;
  303. set => _recognizedObjects = value;
  304. }
  305. public RegionOfInterestInfo RegionOfInterestInfo
  306. {
  307. get => _regionOfInterestInfo;
  308. set => _regionOfInterestInfo = value;
  309. }
  310. /// <summary>
  311. /// 构造函数
  312. /// </summary>
  313. /// <param name="blineScore"></param>
  314. /// <param name="blineScoringInfo"></param>
  315. /// <param name="recognizedObjects"></param>
  316. public BlineScoringResults(int blineScore, BLineScoringInfo[] blineScoringInfo, BlineRecognizedObjectInfo[] recognizedObjects, RegionOfInterestInfo regionOfInterestInfo)
  317. {
  318. _blineScore = blineScore;
  319. _blineScoringInfo = blineScoringInfo;
  320. _recognizedObjects = recognizedObjects;
  321. _regionOfInterestInfo = regionOfInterestInfo;
  322. }
  323. public static readonly BlineScoringResults Empty = new BlineScoringResults(0, Array.Empty<BLineScoringInfo>(), Array.Empty<BlineRecognizedObjectInfo>(), RegionOfInterestInfo.Empty);
  324. public bool Equals(BlineScoringResults other)
  325. {
  326. return Equals(this, other);
  327. }
  328. public static bool Equals(BlineScoringResults one, BlineScoringResults other)
  329. {
  330. if (one.BlineScore != other.BlineScore)
  331. {
  332. return false;
  333. }
  334. // BlineScoringInfo
  335. if (one.BlineScoringInfo == null && other.BlineScoringInfo == null)
  336. {
  337. return true;
  338. }
  339. if ((one.BlineScoringInfo != null && other.BlineScoringInfo == null) || (one.BlineScoringInfo == null && other.BlineScoringInfo != null))
  340. {
  341. return false;
  342. }
  343. if (one.BlineScoringInfo.Length != other.BlineScoringInfo.Length)
  344. {
  345. return false;
  346. }
  347. return true;
  348. // RecognizedObjects
  349. if (one.RecognizedObjects == null && other.RecognizedObjects == null)
  350. {
  351. return true;
  352. }
  353. if ((one.RecognizedObjects != null && other.RecognizedObjects == null) || (one.RecognizedObjects == null && other.RecognizedObjects != null))
  354. {
  355. return false;
  356. }
  357. if (one.RecognizedObjects.Length != other.RecognizedObjects.Length)
  358. {
  359. return false;
  360. }
  361. for (int ni = 0; ni < one.RecognizedObjects.Length; ni++)
  362. {
  363. if (one.RecognizedObjects[ni] != other.RecognizedObjects[ni])
  364. {
  365. return false;
  366. }
  367. }
  368. return true;
  369. // RegionOfInterestInfo
  370. if (one.RegionOfInterestInfo == null && other.RegionOfInterestInfo == null)
  371. {
  372. return true;
  373. }
  374. if ((one.RegionOfInterestInfo != null && other.RegionOfInterestInfo == null) || (one.RegionOfInterestInfo == null && other.RegionOfInterestInfo != null))
  375. {
  376. return false;
  377. }
  378. return true;
  379. }
  380. public override bool Equals(object obj)
  381. {
  382. if (obj == null || !(obj is BlineScoringResults))
  383. {
  384. return false;
  385. }
  386. BlineScoringResults other = (BlineScoringResults)obj;
  387. return Equals(this, other);
  388. }
  389. public static bool operator ==(BlineScoringResults one, BlineScoringResults other)
  390. {
  391. return Equals(one, other);
  392. }
  393. public static bool operator !=(BlineScoringResults one, BlineScoringResults other)
  394. {
  395. return !Equals(one, other);
  396. }
  397. #endregion
  398. }
  399. }