1
0

MainWindow.xaml.cs 98 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Microsoft.Win32;
  16. using System.Drawing;
  17. using System.Threading;
  18. using System.Windows.Threading;
  19. using System.Drawing.Imaging;
  20. using System.IO;
  21. using System.Runtime.InteropServices;
  22. using AI.Common.Interface;
  23. using RawImageShowUtilsLib;
  24. using System.Reflection;
  25. using System.Runtime.InteropServices.ComTypes;
  26. using AI.Common.Implements;
  27. using AIModuleResultShowUtilsLib;
  28. using System.ComponentModel;
  29. namespace SegmentDescribDemo
  30. {
  31. enum ContourShape //轮廓形状
  32. {
  33. NoneShape = 0,
  34. Oval = 1, // 椭圆
  35. Round = 2, // 类圆
  36. Irregular = 3 // 不规则
  37. };
  38. enum Orientation //生长方向
  39. {
  40. NoneOrientation = 0,
  41. Parallel = 1, // 平行
  42. NonParallel = 2 // 非平行
  43. };
  44. enum EchoPattern //回声类型
  45. {
  46. NoneEcho = 0,
  47. Anechoic = 1, // 无回声
  48. Hypoechoic = 2, // 低回声
  49. Hyperechoic = 3, // 高回声
  50. Strongechoic = 4, // 强回声
  51. Complex = 5, // 混合回声
  52. Isoechoic = 6, // 等回声
  53. };
  54. enum Boundary //边界清晰度
  55. {
  56. NoneBoundary = 0,
  57. AbruptInterface = 1, //清晰
  58. EchogenicHalo = 2 //不清晰,模糊
  59. };
  60. enum MarginEnum //边缘光整度
  61. {
  62. NoneMargin = 0,
  63. Circumscribed = 1, //光整
  64. NonCircumscribed = 2 //不光整
  65. };
  66. enum Calcifications
  67. {
  68. NoneCalc = 0,
  69. NoCalcifications = 1, //无钙化
  70. Macrocalcifications = 2, //粗大钙化
  71. CalcificationsInMass = 3, //内部微钙化
  72. CalcificationsOutOfMass = 4 //外部微钙化
  73. };
  74. //局灶性强回声
  75. enum EchogenicFociEnum
  76. {
  77. NoCifications = 0, //无钙化
  78. Coarsecalcifications = 1, //粗钙化
  79. Microcalcifications = 2, //微钙化
  80. };
  81. public struct roiCoor
  82. {
  83. public int x;
  84. public int y;
  85. public int width;
  86. public int height;
  87. }
  88. /// <summary>
  89. /// MainWindow.xaml 的交互逻辑
  90. /// </summary>
  91. public partial class MainWindow : Window
  92. {
  93. #region private variables
  94. private BitmapImage _origimg;
  95. private BitmapImage _dstimg;
  96. private Queue<Bitmap> _imagesReadyToDrawBox = new Queue<Bitmap>();
  97. private Queue<SegDataInput> _testDatas = new Queue<SegDataInput>();
  98. private bool _stop = false;
  99. private bool _reuseimg = false;
  100. private System.Windows.Media.Brush _roiColor = System.Windows.Media.Brushes.Orange;
  101. private System.Drawing.Point _startpoint;
  102. private System.Drawing.Point _endpoint;
  103. private System.Drawing.Rectangle _drawingroi = System.Drawing.Rectangle.Empty;
  104. private volatile bool _roidrawn = false;
  105. private int _currentImgIdex;
  106. private string _currentImgId;
  107. private Bitmap _currentimg;
  108. private Queue<string> _imgNameQueue = new Queue<string>(); // 图像文件名(循环读图)
  109. private List<string> _imgNameList = new List<string>(); // 图像文件名
  110. private List<System.Drawing.Rectangle> _imgROIList = new List<System.Drawing.Rectangle>();
  111. private List<LesionDesGTImgInfo> _allImages = new List<LesionDesGTImgInfo>();
  112. //private AIDiagSystem _aiSeg;
  113. private IModule _module;
  114. private string _currentPath;
  115. private InferenceConfig _inferConfig = new InferenceConfig();
  116. private string _netDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  117. private volatile string _processId = string.Empty;
  118. private volatile string _caseId = string.Empty;
  119. private volatile string _dataId = string.Empty;
  120. private volatile bool _readingVideo;
  121. private volatile int _frameIndex;
  122. //回声
  123. private int _Anechoic_Anechoi_num = 0; //无回声 判为 无回声 的数目
  124. private int _Anechoic_Hyperechoic_num = 0; //无回声 判为 高回声 的数目
  125. private int _Anechoic_Isoechoic_num = 0;
  126. private int _Anechoic_Hypoechoic_num = 0;
  127. private int _Anechoic_HypoechoicLower_num = 0;
  128. private int _Hyperechoic_Hyperechoic_num = 0; //高回声 判为 高回声
  129. private int _Hyperechoic_Anechoic_num = 0;
  130. private int _Hyperechoic_Isoechoic_num = 0;
  131. private int _Hyperechoic_Hypoechoic_num = 0;
  132. private int _Hyperechoic_HypoechoicLower_num = 0;
  133. private int _Isoechoic_Isoechoic_num = 0; //等回声 判为 等回声
  134. private int _Isoechoic_Anechoic_num = 0;
  135. private int _Isoechoic_Hyperechoic_num = 0;
  136. private int _Isoechoic_Hypoechoic_num = 0;
  137. private int _Isoechoic_HypoechoicLower_num = 0;
  138. private int _Hypoechoic_Hypoechoic_num = 0; //低回声 判为 低回声
  139. private int _Hypoechoic_Anechoic_num = 0;
  140. private int _Hypoechoic_Hyperechoic_num = 0;
  141. private int _Hypoechoic_Isoechoic_num = 0;
  142. private int _Hypoechoic_HypoechoicLower_num = 0;
  143. private int _HypoechoicLower_HypoechoicLower_num = 0; //极低回声 判为 极低回声
  144. private int _HypoechoicLower_Anechoicr_num = 0;
  145. private int _HypoechoicLower_Hyperechoic_num = 0;
  146. private int _HypoechoicLower_Isoechoic_num = 0;
  147. private int _HypoechoicLower_Hypoechoic_num = 0;
  148. private int _Oval_Oval_num = 0; //椭圆 判为 椭圆
  149. private int _Oval_Round_num = 0; //椭圆 判为 类圆
  150. private int _Oval_Irregular_num = 0;//椭圆 判为 不规则
  151. private int _Round_Oval_num = 0;
  152. private int _Round_Round_num = 0;
  153. private int _Round_Irregular_num = 0;
  154. private int _Irregular_Oval_num = 0;
  155. private int _Irregular_Round_num = 0;
  156. private int _Irregular_Irregular_num = 0;
  157. private int _Circumscribed_Circumscribed_num = 0; //光整 判为 光整
  158. private int _Circumscribed_NonCircumscribed_num = 0; //光整 判为 不光整
  159. private int _NonCircumscribed_Circumscribed_num = 0;
  160. private int _NonCircumscribed_NonCircumscribed_num = 0;
  161. private int _AbruptInterface_AbruptInterface_num = 0; //清晰 判为 清晰
  162. private int _AbruptInterface_EchogenicHalo_num = 0; //清晰 判为 不清晰,模糊
  163. private int _EchogenicHalo_AbruptInterface_num = 0;
  164. private int _EchogenicHalo_EchogenicHalo_num = 0;
  165. private int _Parallel_Parallel_num = 0; //平行 判为 平行
  166. private int _Parallel_NonParallel_num = 0; //平行 判为 非平行
  167. private int _NonParallel_Parallel_num = 0;
  168. private int _NonParallel_NonParallel_num = 0;
  169. private int _Shadowing = 0;
  170. private int _Enhancement = 0;
  171. private int _Absent = 0;
  172. private int _Combined = 0;
  173. #endregion
  174. [DllImport(@"LesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
  175. public static extern void BreastDescriptionHaveModelProcess(byte[] img_data, int channels, int img_w, int img_h, roiCoor roi_vec, int num_pts,
  176. MyPoint[] contour_points, int contourNum, int[] contourLen, MyPoint[] calcificationPts, ref LesionDescriNow lesionDescr);
  177. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  178. public static extern void BreastDescriptionLesionsRect(int img_w, int img_h, MyPoint[] contour_points, int contourLen, roiCoor lesionRectPr, ref int sameLesion);
  179. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  180. public static extern void DescriptionLesionsRect(int img_w, int img_h, MyPoint[] contour_points, int contourLen, ref roiCoor lesionRectPr);
  181. [DllImport(@"LesionAxis.dll", CallingConvention = CallingConvention.Cdecl)]
  182. public static extern void LesionVerHorAxis(int img_w, int img_h, int contourLen, MyPoint[] contour_points, ref AxisPoint axisPt);
  183. [DllImport(@"LesionAxis.dll", CallingConvention = CallingConvention.Cdecl)]
  184. public static extern void MyLesionAxisProcess(roiCoor lesionRect, int contourLen, MyPoint[] contour_points, ref AxisPoint axisPt);
  185. #region 窗体响应
  186. public MainWindow()
  187. {
  188. InitializeComponent();
  189. _origimg = null;
  190. _dstimg = null;
  191. OrigImage.Source = _origimg;
  192. DstImage.Source = _dstimg;
  193. _currentPath = System.Environment.CurrentDirectory;
  194. _module = new AI.Vaid.Modules.BreastLesionDetect.BreastLesionDetect(_netDir, _inferConfig, EnumDeviceType.CPU);
  195. }
  196. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  197. {
  198. //ImageUtility.Dispose();
  199. }
  200. private void OnLoadOneImageClick(object sender, RoutedEventArgs e) // 加载1张图像
  201. {
  202. OpenFileDialog openFileDialog = new OpenFileDialog();
  203. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  204. openFileDialog.Multiselect = false;
  205. openFileDialog.Title = "选择一幅图像";
  206. if (openFileDialog.ShowDialog() ?? false)
  207. {
  208. Bitmap img = new Bitmap(openFileDialog.FileName);
  209. _imagesReadyToDrawBox.Enqueue(img);
  210. DoROIDrawing();
  211. }
  212. string tmp = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);
  213. _imgNameQueue.Enqueue(tmp);
  214. }
  215. private void OnStartContinuousTestClick(object sender, RoutedEventArgs e) // 加载多张图像
  216. {
  217. if (_imagesReadyToDrawBox.Count > 0 || _testDatas.Count > 0)
  218. {
  219. MessageBox.Show("请先停止连续测试.");
  220. return;
  221. }
  222. OpenFileDialog openFileDialog = new OpenFileDialog();
  223. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  224. openFileDialog.Multiselect = true;
  225. openFileDialog.Title = "选择一幅或多幅图像";
  226. if (openFileDialog.ShowDialog() ?? false)
  227. {
  228. foreach (string filename in openFileDialog.FileNames)
  229. {
  230. Bitmap img = new Bitmap(filename);
  231. _imagesReadyToDrawBox.Enqueue(img);
  232. //string tmp = System.IO.Path.GetFileName(filename);
  233. string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
  234. _imgNameQueue.Enqueue(imgName); // 图像文件名
  235. _imgNameList.Add(imgName);
  236. }
  237. _reuseimg = true;
  238. DoROIDrawing(); //画ROI
  239. }
  240. }
  241. private void OnUseCurrentROIClick(object sender, RoutedEventArgs e) // 使用当前的ROI
  242. {
  243. if (!_startpoint.IsEmpty && !_endpoint.IsEmpty && _currentimg != null)
  244. {
  245. int roileft = Math.Min(_startpoint.X, _endpoint.X);
  246. int roiright = Math.Max(_startpoint.X, _endpoint.X);
  247. int roitop = Math.Min(_startpoint.Y, _endpoint.Y);
  248. int roibottom = Math.Max(_startpoint.Y, _endpoint.Y);
  249. if (roileft == roiright || roitop == roibottom)
  250. {
  251. MessageBox.Show("绘制的矩形框尺寸不能为0.");
  252. return;
  253. }
  254. _drawingroi = new System.Drawing.Rectangle(roileft, roitop, roiright - roileft, roibottom - roitop);
  255. SegDataInput data;
  256. if (_currentimg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb ||
  257. _currentimg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)
  258. {
  259. data = new SegDataInput(_currentimg, _drawingroi);
  260. }
  261. else
  262. {
  263. data = new SegDataInput(_currentimg.Clone(new System.Drawing.Rectangle(0, 0, _currentimg.Width, _currentimg.Height),
  264. System.Drawing.Imaging.PixelFormat.Format24bppRgb), _drawingroi);
  265. }
  266. _testDatas.Enqueue(data);
  267. _roidrawn = true;
  268. _imgROIList.Add(_drawingroi);
  269. /// 开始图像分割
  270. if (_imagesReadyToDrawBox.Count > 0)
  271. {
  272. DoROIDrawing();
  273. }
  274. else
  275. {
  276. if (FuncFCM.IsChecked.Value)
  277. {
  278. DoTest("FCM");
  279. }
  280. else if (FuncACWE.IsChecked.Value)
  281. {
  282. DoTest("ACWE"); // ACWE活动轮廓算法
  283. }
  284. else if (FuncDRLSE.IsChecked.Value)
  285. {
  286. DoTest("DRLSE"); // DRLSE活动轮廓算法
  287. }
  288. else if (FuncLBF.IsChecked.Value)
  289. {
  290. DoTest("LBF"); // LBF活动轮廓算法
  291. }
  292. else if (FuncLSEWR.IsChecked.Value)
  293. {
  294. DoTest("LSEWR");
  295. }
  296. else if (FuncBLS.IsChecked.Value)
  297. {
  298. DoTest("BLS");
  299. }
  300. }
  301. }
  302. else
  303. {
  304. MessageBox.Show("请先加载待测图像并绘制ROI");
  305. }
  306. }
  307. private void OnStopContinuousTestClick(object sender, RoutedEventArgs e)
  308. {
  309. _stop = true;
  310. _reuseimg = false;
  311. }
  312. private void Canvas_SizeChanged(object sender, SizeChangedEventArgs e)
  313. {
  314. MyCanvas.Width = GridOrigImg.ActualWidth;
  315. MyCanvas.Height = GridOrigImg.ActualHeight;
  316. ImageUpdated();
  317. DrawingROIUpdated();
  318. }
  319. private void Canvas_MouseLeftBtnDown(object sender, MouseButtonEventArgs e)
  320. {
  321. int x = Convert.ToInt32(e.GetPosition(OrigImage).X / OrigImage.ActualWidth * _origimg.Width);
  322. int y = Convert.ToInt32(e.GetPosition(OrigImage).Y / OrigImage.ActualHeight * _origimg.Height);
  323. _startpoint = new System.Drawing.Point(x, y);
  324. }
  325. private void Canvas_MouseMove(object sender, MouseEventArgs e)
  326. {
  327. int x = Convert.ToInt32(e.GetPosition(OrigImage).X / OrigImage.ActualWidth * _origimg.Width);
  328. int y = Convert.ToInt32(e.GetPosition(OrigImage).Y / OrigImage.ActualHeight * _origimg.Height);
  329. MousePosition.Text = x.ToString() + "," + y.ToString();
  330. if (e.LeftButton == MouseButtonState.Pressed)
  331. {
  332. _endpoint = new System.Drawing.Point(x, y);
  333. DrawingROIUpdated();
  334. }
  335. }
  336. #endregion
  337. #region private funcs
  338. private void DoROIDrawing()
  339. {
  340. System.Threading.Tasks.Task.Run(() =>
  341. {
  342. if (_stop)
  343. {
  344. _stop = false;
  345. _imagesReadyToDrawBox.Clear();
  346. return;
  347. }
  348. if (_imagesReadyToDrawBox.Count <= 0)
  349. {
  350. return;
  351. }
  352. Bitmap origimage = _imagesReadyToDrawBox.Dequeue();
  353. DrawROIForOneImage(origimage); //对ROI坐标赋值
  354. });
  355. }
  356. private void DrawROIForOneImage(Bitmap image)
  357. {
  358. _origimg = ImageUtility.BitmapToBitmapImage(image);
  359. _currentimg = image;
  360. _drawingroi = System.Drawing.Rectangle.Empty;
  361. _roidrawn = false;
  362. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  363. {
  364. _dstimg = null;
  365. DstImage.Source = _dstimg;
  366. ImageUpdated();
  367. _startpoint = System.Drawing.Point.Empty;
  368. _endpoint = System.Drawing.Point.Empty;
  369. DrawingROIUpdated();
  370. ROI.Text = string.Empty;
  371. }));
  372. while (!_roidrawn)
  373. {
  374. Thread.Sleep(100);
  375. }
  376. }
  377. private void DoTest(string algriType) //循环处理已经选中的图像
  378. {
  379. System.Threading.Tasks.Task.Run(() =>
  380. {
  381. if (_testDatas.Count <= 0 || _stop)
  382. {
  383. _stop = false;
  384. _testDatas.Clear();
  385. return;
  386. }
  387. SegDataInput data = _testDatas.Dequeue();
  388. string img_name;
  389. if (_imgNameQueue.Count == 1)
  390. {
  391. img_name = _imgNameQueue.Peek(); // 返回队列开头的元素但不移除该元素
  392. }
  393. else
  394. { img_name = _imgNameQueue.Dequeue(); } // 移除队列开头的元素并返回该元素
  395. TestOneImage(data, algriType, img_name); // 处理图像
  396. if (_reuseimg)
  397. {
  398. _testDatas.Enqueue(data);
  399. }
  400. Thread.Sleep(50);
  401. DoTest(algriType);
  402. });
  403. }
  404. private unsafe void TestOneImage(SegDataInput data, string algriType, string imgName) // 调用接口函数
  405. {
  406. var starttime = Environment.TickCount;
  407. System.Drawing.PointF[] contours = null; //待画的病灶轮廓
  408. System.Drawing.PointF[] axis_h = new PointF[2];
  409. System.Drawing.PointF[] axis_v = new PointF[2];
  410. EnumSegMethod segMmethod = (EnumSegMethod)Enum.Parse(typeof(EnumSegMethod), algriType);
  411. contours = ImageUtility.ContourDetect(data, segMmethod); //调用病灶分割算法
  412. DesDataInput desData = new DesDataInput(data.InputImage, data.InputRoi, contours);
  413. /// 病灶轮廓描述
  414. AxisPoint axisPt = new AxisPoint();
  415. LesionDescriptionResult lesionDescr = ImageUtility.BreastDescription(desData, axisPt);
  416. int shapeDescri = lesionDescr.Shape; // 形状描述
  417. int growthDerec = lesionDescr.Orientation; // 生长方向
  418. int echoType = lesionDescr.Echo; // 回声类型
  419. int boundarySharpness = lesionDescr.Boundary; // 边界清晰度
  420. int edgeSmooth = lesionDescr.Margin; // 边缘光整度
  421. int echogenicFoci = lesionDescr.Calcification; // 钙化
  422. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  423. {
  424. if (shapeDescri == (int)ContourShape.Oval)
  425. {
  426. ContourShapeDescri.Text = "椭圆形";
  427. }
  428. else if (shapeDescri == (int)ContourShape.Round)
  429. {
  430. ContourShapeDescri.Text = "类圆形";
  431. }
  432. else if (shapeDescri == (int)ContourShape.Irregular)
  433. {
  434. ContourShapeDescri.Text = "不规则形";
  435. }
  436. else if (shapeDescri == (int)ContourShape.NoneShape)
  437. {
  438. ContourShapeDescri.Text = "未标注";
  439. }
  440. if (growthDerec == (int)Orientation.NonParallel)
  441. {
  442. GrowDirectionDescri.Text = "非平行";
  443. }
  444. else if (growthDerec == (int)Orientation.Parallel)
  445. {
  446. GrowDirectionDescri.Text = "平行";
  447. }
  448. else if (growthDerec == (int)Orientation.NoneOrientation)
  449. {
  450. GrowDirectionDescri.Text = "未标注";
  451. }
  452. if (echoType == (int)EchoPattern.Anechoic) // 1无回声
  453. {
  454. EchoPatternDescri.Text = "无回声";
  455. }
  456. else if (echoType == (int)EchoPattern.Hypoechoic) // 2低回声
  457. {
  458. EchoPatternDescri.Text = "低回声";
  459. }
  460. else if (echoType == (int)EchoPattern.Complex) // 5混合回声
  461. {
  462. EchoPatternDescri.Text = "混合回声";
  463. }
  464. else if (echoType == (int)EchoPattern.NoneEcho)
  465. {
  466. EchoPatternDescri.Text = "未标注";
  467. }
  468. // 边界清晰度
  469. if (boundarySharpness == (int)Boundary.AbruptInterface)
  470. {
  471. BoundaryBoundaryDescri.Text = "清晰";
  472. }
  473. else if (boundarySharpness == (int)Boundary.EchogenicHalo)
  474. {
  475. BoundaryBoundaryDescri.Text = "不清晰";
  476. }
  477. else if (boundarySharpness == (int)Boundary.NoneBoundary)
  478. {
  479. BoundaryBoundaryDescri.Text = "未标注";
  480. }
  481. // 边缘光整度
  482. if (edgeSmooth == (int)SegmentDescribDemo.MarginEnum.Circumscribed)
  483. {
  484. EdgeMarginDescri.Text = "光整";
  485. }
  486. else if (edgeSmooth == (int)SegmentDescribDemo.MarginEnum.NonCircumscribed)
  487. {
  488. EdgeMarginDescri.Text = "不光整";
  489. }
  490. else if (edgeSmooth == (int)SegmentDescribDemo.MarginEnum.NoneMargin)
  491. {
  492. EdgeMarginDescri.Text = "未标注";
  493. }
  494. // 局灶性强回声:钙化
  495. if (echogenicFoci == (int)Calcifications.NoCalcifications)
  496. {
  497. EdgeCificationDescri.Text = "无钙化";
  498. }
  499. else if (echogenicFoci == (int)Calcifications.Macrocalcifications)
  500. {
  501. EdgeCificationDescri.Text = "粗钙化";
  502. }
  503. else if (echogenicFoci == (int)Calcifications.CalcificationsInMass)
  504. {
  505. EdgeCificationDescri.Text = "微钙化";
  506. }
  507. else
  508. {
  509. EdgeCificationDescri.Text = "未标注";
  510. }
  511. }));
  512. var endtime = Environment.TickCount;
  513. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  514. {
  515. ElapsedTime.Text = (endtime - starttime).ToString();
  516. }));
  517. Bitmap dstimage = (Bitmap)data.InputImage.Clone();
  518. using (var g = Graphics.FromImage(dstimage))
  519. {
  520. if (contours.Length > 0)
  521. {
  522. //画病灶轮廓
  523. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  524. g.DrawLines(pen, contours);
  525. pen.Dispose();
  526. }
  527. //画轮廓的长短轴
  528. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  529. g.DrawLines(pen_h, axis_h); //横轴,浅绿色
  530. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 2);
  531. g.DrawLines(pen_v, axis_v); //纵轴,红色
  532. g.Dispose();
  533. }
  534. _dstimg = ImageUtility.BitmapToBitmapImage(dstimage);
  535. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  536. {
  537. DstImage.Source = _dstimg;
  538. }));
  539. dstimage.Dispose();
  540. }
  541. private void DrawingROIUpdated()
  542. {
  543. if (null == _origimg)
  544. {
  545. return;
  546. }
  547. System.Windows.Shapes.Rectangle drawingroi = MyCanvas.FindName("drawingroi") as System.Windows.Shapes.Rectangle;
  548. if (drawingroi != null)
  549. {
  550. MyCanvas.Children.Remove(drawingroi);
  551. MyCanvas.UnregisterName("drawingroi");
  552. }
  553. if (_startpoint.IsEmpty || _endpoint.IsEmpty)
  554. {
  555. return;
  556. }
  557. // 在原始图像上的坐标
  558. int roileft = Math.Min(_startpoint.X, _endpoint.X);
  559. int roiright = Math.Max(_startpoint.X, _endpoint.X);
  560. int roitop = Math.Min(_startpoint.Y, _endpoint.Y);
  561. int roibottom = Math.Max(_startpoint.Y, _endpoint.Y);
  562. ROI.Text = roileft.ToString() + "," + roitop + "," + roiright.ToString() + "," + roibottom.ToString();
  563. // 求在画布上的坐标
  564. double boxTopInCanvas = roitop * OrigImgScaleTramsform.ScaleY;
  565. double boxLeftInCanvas = roileft * OrigImgScaleTramsform.ScaleX;
  566. double boxWidthInCanvas = (roiright - roileft) * OrigImgScaleTramsform.ScaleX;
  567. double boxHeghtInCanvas = (roibottom - roitop) * OrigImgScaleTramsform.ScaleY;
  568. // 在画布上画矩形
  569. drawingroi = new System.Windows.Shapes.Rectangle();
  570. drawingroi.StrokeThickness = 3;
  571. drawingroi.Stroke = _roiColor;
  572. drawingroi.Width = boxWidthInCanvas;
  573. drawingroi.Height = boxHeghtInCanvas;
  574. Canvas.SetLeft(drawingroi, boxLeftInCanvas);
  575. Canvas.SetTop(drawingroi, boxTopInCanvas);
  576. MyCanvas.Children.Add(drawingroi);
  577. MyCanvas.RegisterName("drawingroi", drawingroi);
  578. }
  579. private void ImageUpdated()
  580. {
  581. if (null == _origimg)
  582. {
  583. return;
  584. }
  585. // 缩放
  586. double ratioW = GridOrigImg.ActualWidth / _origimg.Width;
  587. double ratioH = GridOrigImg.ActualHeight / _origimg.Height;
  588. double ratio = ratioW < ratioH ? ratioW : ratioH;
  589. OrigImgScaleTramsform.CenterX = 0;
  590. OrigImgScaleTramsform.CenterY = 0;
  591. OrigImgScaleTramsform.ScaleX = ratio;
  592. OrigImgScaleTramsform.ScaleY = ratio;
  593. // 使图像居中,需要平移
  594. double translateX = 0;
  595. double translateY = 0;
  596. if (Math.Abs(ratio - ratioW) < 0.0001)
  597. {
  598. translateY = 0.5 * (ratioH - ratio) * _origimg.Height;
  599. }
  600. else
  601. {
  602. translateX = 0.5 * (ratioW - ratio) * _origimg.Width;
  603. }
  604. // 更新画布尺寸,使其刚好只覆盖图像区域
  605. MyCanvas.Width = ratio * _origimg.Width;
  606. MyCanvas.Height = ratio * _origimg.Height;
  607. Canvas.SetLeft(MyCanvas, translateX);
  608. Canvas.SetTop(MyCanvas, translateY);
  609. MyCanvas.ClipToBounds = true;
  610. OrigImage.Source = _origimg;
  611. }
  612. #endregion
  613. private void OnLoadDataBaseClick(object sender, RoutedEventArgs e)
  614. {
  615. OpenFileDialog openFileDialog = new OpenFileDialog();
  616. openFileDialog.Filter = "数据库文件|*.db";
  617. openFileDialog.Multiselect = false;
  618. openFileDialog.Title = "选择一个数据库文件";
  619. string dbPath = "";
  620. if (openFileDialog.ShowDialog() ?? false)
  621. {
  622. dbPath = openFileDialog.FileName;
  623. }
  624. DataBase dataBase = new DataBase(dbPath);
  625. dataBase.ReadDataBase();
  626. if (dataBase._allImages.Count > 1)
  627. {
  628. _allImages = dataBase._allImages;
  629. if (_allImages.Count > 0)
  630. {
  631. MessageBox.Show("加载成功!");
  632. }
  633. }
  634. else
  635. {
  636. MessageBox.Show("读取失败!");
  637. }
  638. }
  639. private void OnLoadOneImagesClick(object sender, RoutedEventArgs e)
  640. {
  641. OpenFileDialog openFileDialog = new OpenFileDialog();
  642. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  643. openFileDialog.Multiselect = true;
  644. openFileDialog.Title = "选择一幅或多幅图像";
  645. if (openFileDialog.ShowDialog() ?? false)
  646. {
  647. foreach (string filename in openFileDialog.FileNames)
  648. {
  649. Bitmap img = new Bitmap(filename);
  650. _currentimg = img;
  651. string temp;
  652. int idx = filename.LastIndexOf("\\");
  653. temp = filename.Substring(idx);
  654. string[] strs1 = temp.Split('\\');
  655. temp = strs1[1];
  656. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  657. //string ImgId = strs2[0];
  658. string[] sArray = null;
  659. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  660. string ImgId = sArray[0];
  661. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  662. _currentImgId = ImgId;
  663. int imgIdx = _allImages.FindIndex(x => x.ImageId == _currentImgId);
  664. if (imgIdx < 0)
  665. {
  666. //return;
  667. continue;
  668. }
  669. else
  670. {
  671. _currentImgIdex = imgIdx;
  672. DoDescriAlgorithm(ImgId);
  673. }
  674. }
  675. Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
  676. Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
  677. Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
  678. Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
  679. Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
  680. Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
  681. Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
  682. Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
  683. Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
  684. Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
  685. Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
  686. Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
  687. Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
  688. Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
  689. Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
  690. Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
  691. Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
  692. Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
  693. Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
  694. Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
  695. Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
  696. Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
  697. Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
  698. Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
  699. Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
  700. ///
  701. Console.WriteLine("椭圆 -> 椭圆: " + _Oval_Oval_num);
  702. Console.WriteLine("椭圆 -> 类圆: " + _Oval_Round_num);
  703. Console.WriteLine("椭圆 -> 不规则: " + _Oval_Irregular_num);
  704. Console.WriteLine("类圆 -> 椭圆: " + _Round_Oval_num);
  705. Console.WriteLine("类圆 -> 类圆: " + _Round_Round_num);
  706. Console.WriteLine("类圆 -> 不规则: " + _Round_Irregular_num);
  707. Console.WriteLine("不规则 -> 椭圆: " + _Irregular_Oval_num);
  708. Console.WriteLine("不规则 -> 类圆: " + _Irregular_Round_num);
  709. Console.WriteLine("不规则 -> 不规则: " + _Irregular_Irregular_num);
  710. Console.WriteLine("光整 -> 光整: " + _Circumscribed_Circumscribed_num);
  711. Console.WriteLine("光整 -> 不光整: " + _Circumscribed_NonCircumscribed_num);
  712. Console.WriteLine("不光整 -> 光整: " + _NonCircumscribed_Circumscribed_num);
  713. Console.WriteLine("不光整 -> 不光整: " + _NonCircumscribed_NonCircumscribed_num);
  714. Console.WriteLine("清晰 -> 清晰: " + _AbruptInterface_AbruptInterface_num);
  715. Console.WriteLine("清晰 -> 不清晰: " + _AbruptInterface_EchogenicHalo_num);
  716. Console.WriteLine("不清晰 -> 清晰: " + _EchogenicHalo_AbruptInterface_num);
  717. Console.WriteLine("不清晰 -> 不清晰: " + _EchogenicHalo_EchogenicHalo_num);
  718. Console.WriteLine("平行 -> 平行: " + _Parallel_Parallel_num);
  719. Console.WriteLine("平行 -> 非平行: " + _Parallel_NonParallel_num);
  720. Console.WriteLine("非平行 -> 平行: " + _NonParallel_Parallel_num);
  721. Console.WriteLine("非平行 -> 非平行: " + _NonParallel_NonParallel_num);
  722. Console.WriteLine();
  723. }
  724. }
  725. //描述算法调用接口
  726. private void DoDescriAlgorithm(string name)
  727. {
  728. if (_currentimg == null)
  729. {
  730. MessageBox.Show("请先加载待测图像!");
  731. return;
  732. }
  733. Bitmap bmp = _currentimg;
  734. //RawImage rawImg = BitmapToRawImage(bmp);
  735. roiCoor roi;
  736. roi.x = 0;
  737. roi.y = 0;
  738. roi.width = _currentimg.Width;
  739. roi.height = _currentimg.Height;
  740. int LesionsNum = _allImages[_currentImgIdex].Lesions.Count;
  741. //确定存在病灶
  742. if (LesionsNum > 0)
  743. {
  744. Bitmap dstimage = (Bitmap)_currentimg.Clone();
  745. //Bitmap oriimage = (Bitmap)_currentimg.Clone();
  746. int lesionsNum = _allImages[_currentImgIdex].Lesions.Count;
  747. for (int ii = 0; ii < lesionsNum; ii++)
  748. {
  749. //获取病灶轮廓
  750. int num2 = _allImages[_currentImgIdex].Lesions[ii].Contour.Count;
  751. MyPoint[] lesionPts = new MyPoint[num2];
  752. System.Drawing.PointF[] lesionContour = new PointF[num2];
  753. for (int i = 0; i < num2; i++)
  754. {
  755. lesionPts[i].x = _allImages[_currentImgIdex].Lesions[ii].Contour[i].x;
  756. lesionPts[i].y = _allImages[_currentImgIdex].Lesions[ii].Contour[i].y;
  757. lesionContour[i].X = _allImages[_currentImgIdex].Lesions[ii].Contour[i].x;
  758. lesionContour[i].Y = _allImages[_currentImgIdex].Lesions[ii].Contour[i].y;
  759. }
  760. EchoPattern echoGT = (EchoPattern)(_allImages[_currentImgIdex].Lesions[ii].EchoPattern) + 1;
  761. Boundary boundaryGT = (Boundary)(_allImages[_currentImgIdex].Lesions[ii].Boundary) + 1;
  762. MarginEnum marginGT = (MarginEnum)(_allImages[_currentImgIdex].Lesions[ii].Margin) + 1;
  763. ContourShape shapeCppGT = (ContourShape)(_allImages[_currentImgIdex].Lesions[ii].Shape) + 1;
  764. Orientation orientationGT = (Orientation)(_allImages[_currentImgIdex].Lesions[ii].Orientation) + 1;
  765. LesionDescriNow desCpp = new LesionDescriNow();
  766. desCpp.echo = 0;
  767. desCpp.shape = 0;
  768. desCpp.margin = 0;
  769. desCpp.boundary = 0;
  770. desCpp.orientation = 0;
  771. desCpp.calcification = 0;
  772. //desCpp.echogenicFoci = 0;
  773. AxisPoint axisPtGt;
  774. axisPtGt = new AxisPoint();
  775. axisPtGt.horizontalPt1 = new MyPoint { x = 0, y = 0 };
  776. axisPtGt.horizontalPt2 = new MyPoint { x = 0, y = 0 };
  777. axisPtGt.verticalPt1 = new MyPoint { x = 0, y = 0 };
  778. axisPtGt.verticalPt2 = new MyPoint { x = 0, y = 0 };
  779. System.Drawing.PointF[] axisH = new PointF[2];
  780. System.Drawing.PointF[] axisV = new PointF[2];
  781. //WriteTxtToFile("E:\\image\\", "usename.txt", name, false);
  782. System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, 0, 0);
  783. SegDataInput data = new SegDataInput(_currentimg, rect);
  784. DesDataInput desData = new DesDataInput(data.InputImage, data.InputRoi, lesionContour);
  785. //roiCoor lesionRectPr = new roiCoor();
  786. //DescriptionLesionsRect(_currentimg.Width, _currentimg.Height, lesionPts, lesionPts.Length, ref lesionRectPr);
  787. //AxisPoint axisPt = new AxisPoint();
  788. //MyLesionAxisProcess(lesionRectPr, lesionPts.Length, lesionPts, ref axisPt);
  789. var starttime = Environment.TickCount;
  790. /// 病灶轮廓描述
  791. GCHandle hObjectContour = GCHandle.Alloc(lesionPts, GCHandleType.Pinned);
  792. IntPtr pObjectContour = hObjectContour.AddrOfPinnedObject();
  793. AxisPoint axisPt = new AxisPoint();
  794. roiCoor lesionRectPr = new roiCoor();
  795. DescriptionLesionsRect(_currentimg.Width, _currentimg.Height, lesionPts, lesionPts.Length, ref lesionRectPr);
  796. MyLesionAxisProcess(lesionRectPr, lesionPts.Length, lesionPts, ref axisPt);
  797. axisPtGt = axisPt;
  798. if (hObjectContour.IsAllocated)
  799. {
  800. hObjectContour.Free();
  801. }
  802. LesionDescriptionResult lesionDescr = ImageUtility.BreastDescription(desData, axisPtGt);
  803. var endtime = Environment.TickCount;
  804. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  805. {
  806. ElapsedTime.Text = (endtime - starttime).ToString();
  807. }));
  808. int shapeDescri = lesionDescr.Shape; // 形状描述
  809. int orientation = lesionDescr.Orientation; // 生长方向
  810. int echoType = lesionDescr.Echo ; // 回声类型
  811. int boundarySharpness = lesionDescr.Boundary; // 边界清晰度
  812. int margin = lesionDescr.Margin; // 边缘光整度
  813. int calcification = lesionDescr.Calcification; // 钙化
  814. AxisPoint axisPoint = axisPtGt; // 纵、横轴端点坐标
  815. MyPoint pt1 = axisPoint.horizontalPt1; // 横轴
  816. MyPoint pt2 = axisPoint.horizontalPt2;
  817. MyPoint pt3 = axisPoint.verticalPt1; // 纵轴
  818. MyPoint pt4 = axisPoint.verticalPt2;
  819. axisH[0].X = pt1.x;
  820. axisH[0].Y = pt1.y;
  821. axisH[1].X = pt2.x;
  822. axisH[1].Y = pt2.y;
  823. axisV[0].X = pt3.x;
  824. axisV[0].Y = pt3.y;
  825. axisV[1].X = pt4.x;
  826. axisV[1].Y = pt4.y;
  827. int resCa = -1;
  828. int resEcho = -1;
  829. int resShape = -1;
  830. //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  831. {
  832. if (shapeDescri == (int)ContourShape.Oval)
  833. {
  834. ContourShapeDescriPr.Text = "椭圆形";
  835. }
  836. else if (shapeDescri == (int)ContourShape.Round)
  837. {
  838. ContourShapeDescriPr.Text = "类圆形";
  839. }
  840. else if (shapeDescri == (int)ContourShape.Irregular)
  841. {
  842. ContourShapeDescriPr.Text = "不规则形";
  843. }
  844. else if (shapeDescri == (int)ContourShape.NoneShape)
  845. {
  846. ContourShapeDescriPr.Text = "未标注";
  847. }
  848. if (orientation == (int)Orientation.NonParallel)
  849. {
  850. GrowDirectionDescriPr.Text = "非平行";
  851. }
  852. else if (orientation == (int)Orientation.Parallel)
  853. {
  854. GrowDirectionDescriPr.Text = "平行";
  855. }
  856. else if (orientation == (int)Orientation.NoneOrientation)
  857. {
  858. GrowDirectionDescriPr.Text = "未标注";
  859. }
  860. if (echoType == (int)EchoPattern.Anechoic) // 1无回声
  861. {
  862. EchoPatternDescriPr.Text = "无回声";
  863. }
  864. else if (echoType == (int)EchoPattern.Hypoechoic) // 2低回声
  865. {
  866. EchoPatternDescriPr.Text = "低回声";
  867. }
  868. else if (echoType == (int)EchoPattern.Complex) // 5混合回声
  869. {
  870. EchoPatternDescriPr.Text = "混合回声";
  871. }
  872. else if (echoType == (int)EchoPattern.NoneEcho)
  873. {
  874. EchoPatternDescriPr.Text = "未标注";
  875. }
  876. // 边界清晰度
  877. if (boundarySharpness == (int)Boundary.AbruptInterface)
  878. {
  879. BoundaryBoundaryDescriPr.Text = "清晰";
  880. }
  881. else if (boundarySharpness == (int)Boundary.EchogenicHalo)
  882. {
  883. BoundaryBoundaryDescriPr.Text = "不清晰";
  884. }
  885. else if (boundarySharpness == (int)Boundary.NoneBoundary)
  886. {
  887. BoundaryBoundaryDescriPr.Text = "未标注";
  888. }
  889. // 边缘光整度
  890. if (margin == (int)SegmentDescribDemo.MarginEnum.Circumscribed)
  891. {
  892. EdgeMarginDescriPr.Text = "光整";
  893. }
  894. else if (margin == (int)SegmentDescribDemo.MarginEnum.NonCircumscribed)
  895. {
  896. EdgeMarginDescriPr.Text = "不光整";
  897. }
  898. else if (margin == (int)SegmentDescribDemo.MarginEnum.NoneMargin)
  899. {
  900. EdgeMarginDescriPr.Text = "未标注";
  901. }
  902. ///////////////////////////////////////////////////////////
  903. if (shapeCppGT == ContourShape.Oval)
  904. {
  905. ContourShapeDescri.Text = "椭圆形";
  906. }
  907. else if (shapeCppGT == ContourShape.Round)
  908. {
  909. ContourShapeDescri.Text = "类圆形";
  910. }
  911. else if (shapeCppGT == ContourShape.Irregular)
  912. {
  913. ContourShapeDescri.Text = "不规则形";
  914. }
  915. else if (shapeCppGT == ContourShape.NoneShape)
  916. {
  917. ContourShapeDescri.Text = "未标注";
  918. }
  919. if (orientationGT == Orientation.NonParallel)
  920. {
  921. GrowDirectionDescri.Text = "非平行";
  922. }
  923. else if (orientationGT == Orientation.Parallel)
  924. {
  925. GrowDirectionDescri.Text = "平行";
  926. }
  927. else if (orientationGT == Orientation.NoneOrientation)
  928. {
  929. GrowDirectionDescri.Text = "未标注";
  930. }
  931. if (echoGT == EchoPattern.Anechoic) // 1无回声
  932. {
  933. EchoPatternDescri.Text = "无回声";
  934. }
  935. else if (echoGT == EchoPattern.Hypoechoic) // 2低回声
  936. {
  937. EchoPatternDescri.Text = "低回声";
  938. }
  939. else if (echoGT == EchoPattern.Complex) // 5混合回声
  940. {
  941. EchoPatternDescri.Text = "混合回声";
  942. }
  943. else if (echoGT == EchoPattern.NoneEcho)
  944. {
  945. EchoPatternDescri.Text = "未标注";
  946. }
  947. // 边界清晰度
  948. if (boundaryGT == Boundary.AbruptInterface)
  949. {
  950. BoundaryBoundaryDescri.Text = "清晰";
  951. }
  952. else if (boundaryGT == Boundary.EchogenicHalo)
  953. {
  954. BoundaryBoundaryDescri.Text = "不清晰";
  955. }
  956. else if (boundaryGT == Boundary.NoneBoundary)
  957. {
  958. BoundaryBoundaryDescri.Text = "未标注";
  959. }
  960. // 边缘光整度
  961. if (marginGT == SegmentDescribDemo.MarginEnum.Circumscribed)
  962. {
  963. EdgeMarginDescri.Text = "光整";
  964. }
  965. else if (marginGT == SegmentDescribDemo.MarginEnum.NonCircumscribed)
  966. {
  967. EdgeMarginDescri.Text = "不光整";
  968. }
  969. else if (marginGT == SegmentDescribDemo.MarginEnum.NoneMargin)
  970. {
  971. EdgeMarginDescri.Text = "未标注";
  972. }
  973. }
  974. ////));
  975. ////////////////
  976. //string newPath = System.IO.Path.Combine(_currentPath, "result");
  977. //if (resShape == 0)
  978. //{
  979. // string nameSave = newPath + "\\00\\" + name + ".jpg";
  980. // if (shapeCppGT == ShapeEnum.WiderThanTall)
  981. // {
  982. // //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  983. // }
  984. //}
  985. //else if (resShape == 1)
  986. //{
  987. // string nameSave = newPath + "\\01\\" + name + ".jpg";
  988. // if (shapeCppGT == ShapeEnum.WiderThanTall)
  989. // {
  990. // // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  991. // }
  992. // //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  993. //}
  994. //if (echoFociGT == echoFoci)
  995. //{
  996. // if (echoFoci == EchogenicFociEnum.NoCifications)
  997. // {
  998. // _NoCifications_NoCifications_num++;
  999. // //result = 1;
  1000. // }
  1001. // if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
  1002. // {
  1003. // _Coarsecalcifications_Coarsecalcifications_num++;
  1004. // //result = 2;
  1005. // }
  1006. // if (echoFoci == EchogenicFociEnum.Microcalcifications)
  1007. // {
  1008. // _Macrocalcifications_Macrocalcifications_num++;
  1009. // //result = 3;
  1010. // }
  1011. //}
  1012. //else
  1013. //{
  1014. // if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  1015. // {
  1016. // _NoCifications_Coarsecalcifications_num++;
  1017. // //result = 4;
  1018. // }
  1019. // if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  1020. // {
  1021. // _NoCifications_Macrocalcifications_num++;
  1022. // //result = 5;
  1023. // }
  1024. // if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  1025. // {
  1026. // _Coarsecalcifications_NoCifications_num++;
  1027. // //result = 6;
  1028. // }
  1029. // if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  1030. // {
  1031. // _Coarsecalcifications_Macrocalcifications_num++;
  1032. // //result = 7;
  1033. // }
  1034. // if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  1035. // {
  1036. // _Macrocalcifications_NoCifications_num++;
  1037. // //result = 8;
  1038. // }
  1039. // if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  1040. // {
  1041. // _Macrocalcifications_Coarsecalcifications_num++;
  1042. // //result = 9;
  1043. // }
  1044. //}
  1045. if ((int)echoGT == echoType)
  1046. {
  1047. if (echoType == (int)EchoPattern.Anechoic)
  1048. {
  1049. _Anechoic_Anechoi_num++;
  1050. }
  1051. if (echoType == (int)EchoPattern.Hyperechoic)
  1052. {
  1053. _Hyperechoic_Hyperechoic_num++;
  1054. }
  1055. if (echoType == (int)EchoPattern.Isoechoic)
  1056. {
  1057. _Isoechoic_Isoechoic_num++;
  1058. }
  1059. if (echoType == (int)EchoPattern.Hypoechoic)
  1060. {
  1061. _Hypoechoic_Hypoechoic_num++;
  1062. }
  1063. if (echoType == (int)EchoPattern.Complex)
  1064. {
  1065. _HypoechoicLower_HypoechoicLower_num++;
  1066. }
  1067. }
  1068. else
  1069. {
  1070. //把无回声判为其它
  1071. if (echoGT == EchoPattern.Anechoic && echoType == (int)EchoPattern.Hyperechoic)
  1072. {
  1073. _Anechoic_Hyperechoic_num++;
  1074. }
  1075. if (echoGT == EchoPattern.Anechoic && echoType == (int)EchoPattern.Isoechoic)
  1076. {
  1077. _Anechoic_Isoechoic_num++;
  1078. }
  1079. if (echoGT == EchoPattern.Anechoic && echoType == (int)EchoPattern.Hypoechoic)
  1080. {
  1081. _Anechoic_Hypoechoic_num++;
  1082. }
  1083. if (echoGT == EchoPattern.Anechoic && echoType == (int)EchoPattern.Complex)
  1084. {
  1085. _Anechoic_HypoechoicLower_num++;
  1086. }
  1087. //把高回声判为其它
  1088. if (echoGT == EchoPattern.Hyperechoic && echoType == (int)EchoPattern.Anechoic)
  1089. {
  1090. _Hyperechoic_Anechoic_num++;
  1091. }
  1092. if (echoGT == EchoPattern.Hyperechoic && echoType == (int)EchoPattern.Isoechoic)
  1093. {
  1094. _Hyperechoic_Isoechoic_num++;
  1095. }
  1096. if (echoGT == EchoPattern.Hyperechoic && echoType == (int)EchoPattern.Hypoechoic)
  1097. {
  1098. _Hyperechoic_Hypoechoic_num++;
  1099. }
  1100. if (echoGT == EchoPattern.Hyperechoic && echoType == (int)EchoPattern.Complex)
  1101. {
  1102. _Hyperechoic_HypoechoicLower_num++;
  1103. }
  1104. //把等回声判为其它
  1105. if (echoGT == EchoPattern.Isoechoic && echoType == (int)EchoPattern.Anechoic)
  1106. {
  1107. _Isoechoic_Anechoic_num++;
  1108. }
  1109. if (echoGT == EchoPattern.Isoechoic && echoType == (int)EchoPattern.Hyperechoic)
  1110. {
  1111. _Isoechoic_Hyperechoic_num++;
  1112. }
  1113. if (echoGT == EchoPattern.Isoechoic && echoType == (int)EchoPattern.Hypoechoic)
  1114. {
  1115. _Isoechoic_Hypoechoic_num++;
  1116. }
  1117. if (echoGT == EchoPattern.Isoechoic && echoType == (int)EchoPattern.Complex)
  1118. {
  1119. _Isoechoic_HypoechoicLower_num++;
  1120. }
  1121. //低回声判为其它
  1122. if (echoGT == EchoPattern.Hypoechoic && echoType == (int)EchoPattern.Anechoic)
  1123. {
  1124. _Hypoechoic_Anechoic_num++;
  1125. }
  1126. if (echoGT == EchoPattern.Hypoechoic && echoType == (int)EchoPattern.Hyperechoic)
  1127. {
  1128. _Hypoechoic_Hyperechoic_num++;
  1129. }
  1130. if (echoGT == EchoPattern.Hypoechoic && echoType == (int)EchoPattern.Isoechoic)
  1131. {
  1132. _Hypoechoic_Isoechoic_num++;
  1133. }
  1134. if (echoGT == EchoPattern.Hypoechoic && echoType == (int)EchoPattern.Complex)
  1135. {
  1136. _Hypoechoic_HypoechoicLower_num++;
  1137. }
  1138. }
  1139. if ((int)shapeCppGT == shapeDescri)
  1140. {
  1141. if (shapeDescri == (int)ContourShape.Oval) // 椭圆
  1142. {
  1143. _Oval_Oval_num++;
  1144. }
  1145. if (shapeDescri == (int)ContourShape.Round) // 类圆
  1146. {
  1147. _Round_Round_num++;
  1148. }
  1149. if (shapeDescri == (int)ContourShape.Irregular)// 不规则
  1150. {
  1151. _Irregular_Irregular_num++;
  1152. }
  1153. }
  1154. else
  1155. {
  1156. //把 宽大于高 判为 高大于宽
  1157. if (shapeCppGT == ContourShape.Oval && shapeDescri == (int)ContourShape.Round)
  1158. {
  1159. _Oval_Round_num++;
  1160. }
  1161. if (shapeCppGT == ContourShape.Oval && shapeDescri == (int)ContourShape.Irregular)
  1162. {
  1163. _Oval_Irregular_num++;
  1164. }
  1165. if (shapeCppGT == ContourShape.Round && shapeDescri == (int)ContourShape.Oval)
  1166. {
  1167. _Round_Oval_num++;
  1168. }
  1169. if (shapeCppGT == ContourShape.Round && shapeDescri == (int)ContourShape.Irregular)
  1170. {
  1171. _Round_Irregular_num++;
  1172. }
  1173. if (shapeCppGT == ContourShape.Irregular && shapeDescri == (int)ContourShape.Oval)
  1174. {
  1175. _Irregular_Oval_num++;
  1176. }
  1177. if (shapeCppGT == ContourShape.Irregular && shapeDescri == (int)ContourShape.Round)
  1178. {
  1179. _Irregular_Round_num++;
  1180. }
  1181. }
  1182. if ((int)marginGT == margin)
  1183. {
  1184. if (margin == (int)MarginEnum.Circumscribed)
  1185. {
  1186. _Circumscribed_Circumscribed_num++;
  1187. }
  1188. if (margin == (int)MarginEnum.NonCircumscribed)
  1189. {
  1190. _NonCircumscribed_NonCircumscribed_num++;
  1191. }
  1192. }
  1193. else
  1194. {
  1195. //把 边缘光整 判成其它
  1196. if (marginGT == MarginEnum.Circumscribed && margin == (int)MarginEnum.NonCircumscribed)
  1197. {
  1198. _Circumscribed_NonCircumscribed_num++;
  1199. }
  1200. if (marginGT == MarginEnum.NonCircumscribed && margin == (int)MarginEnum.Circumscribed)
  1201. {
  1202. _NonCircumscribed_Circumscribed_num++;
  1203. }
  1204. }
  1205. if ((int)boundaryGT == boundarySharpness)
  1206. {
  1207. if (boundarySharpness == (int)Boundary.AbruptInterface)
  1208. {
  1209. _AbruptInterface_AbruptInterface_num++;
  1210. }
  1211. if (boundarySharpness == (int)Boundary.EchogenicHalo)
  1212. {
  1213. _EchogenicHalo_EchogenicHalo_num++;
  1214. }
  1215. }
  1216. else
  1217. {
  1218. //把 边界清晰 判成其它
  1219. if (boundaryGT == Boundary.AbruptInterface && boundarySharpness == (int)Boundary.EchogenicHalo)
  1220. {
  1221. _AbruptInterface_EchogenicHalo_num++;
  1222. }
  1223. if (boundaryGT == Boundary.EchogenicHalo && boundarySharpness == (int)Boundary.AbruptInterface)
  1224. {
  1225. _EchogenicHalo_AbruptInterface_num++;
  1226. }
  1227. }
  1228. if ((int)orientationGT == orientation)
  1229. {
  1230. if (orientation == (int)Orientation.Parallel)
  1231. {
  1232. _Parallel_Parallel_num++;
  1233. }
  1234. if (orientation == (int)Orientation.NonParallel)
  1235. {
  1236. _NonParallel_NonParallel_num++;
  1237. }
  1238. }
  1239. else
  1240. {
  1241. //把 边界清晰 判成其它
  1242. if (orientationGT == Orientation.Parallel && orientation == (int)Orientation.NonParallel)
  1243. {
  1244. _Parallel_NonParallel_num++;
  1245. }
  1246. if (orientationGT == Orientation.NonParallel && orientation == (int)Orientation.Parallel)
  1247. {
  1248. _NonParallel_Parallel_num++;
  1249. }
  1250. }
  1251. //using (var g = Graphics.FromImage(oriimage))
  1252. //{
  1253. // System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  1254. // Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
  1255. // g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  1256. // if (lesionContour.Length > 5)
  1257. // {
  1258. // System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  1259. // g.DrawLines(pen, lesionContour); //画病灶轮廓
  1260. // System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  1261. // if (lesionPts.Length > 0)
  1262. // {
  1263. // //g.DrawLines(pen2, lesionPts); //画肝脏轮廓
  1264. // }
  1265. // pen.Dispose();
  1266. // }
  1267. // //画轮廓的长短轴
  1268. // System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  1269. // g.DrawLines(pen_h, axisH); //横轴,浅绿色
  1270. // System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  1271. // g.DrawLines(pen_v, axisV); //纵轴,红色
  1272. // g.Dispose();
  1273. //}
  1274. using (var g = Graphics.FromImage(dstimage))
  1275. {
  1276. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  1277. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
  1278. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  1279. if (lesionContour.Length > 5)
  1280. {
  1281. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  1282. g.DrawLines(pen, lesionContour); //画病灶轮廓
  1283. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  1284. if (lesionPts.Length > 0)
  1285. {
  1286. //g.DrawLines(pen2, lesionPts); //画肝脏轮廓
  1287. }
  1288. pen.Dispose();
  1289. }
  1290. //画轮廓的长短轴
  1291. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  1292. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  1293. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  1294. g.DrawLines(pen_v, axisV); //纵轴,红色
  1295. g.Dispose();
  1296. }
  1297. }
  1298. _dstimg = ImageUtility.BitmapToBitmapImage(dstimage);
  1299. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  1300. {
  1301. DstImage.Source = _dstimg;
  1302. }));
  1303. //oriimage.Dispose();
  1304. dstimage.Dispose();
  1305. }
  1306. else
  1307. {
  1308. MessageBox.Show("未读取到病灶!");
  1309. }
  1310. }
  1311. private void OnModelsProcessClick(object sender, RoutedEventArgs e)
  1312. {
  1313. OpenFileDialog openFileDialog = new OpenFileDialog();
  1314. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1315. openFileDialog.Multiselect = false;
  1316. openFileDialog.Title = "选择一幅图像";
  1317. if (openFileDialog.ShowDialog() ?? false)
  1318. {
  1319. Bitmap img = new Bitmap(openFileDialog.FileName);
  1320. _imagesReadyToDrawBox.Enqueue(img);
  1321. _currentimg = img;
  1322. var filename = openFileDialog.FileName;
  1323. int idx = openFileDialog.FileName.LastIndexOf("\\");
  1324. string temp = filename.Substring(idx);
  1325. string[] strs1 = temp.Split('\\');
  1326. temp = strs1[1];
  1327. string[] sArray = null;
  1328. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1329. string ImgId = sArray[0];
  1330. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  1331. _currentImgId = ImgId;
  1332. int imgIdx = _allImages.FindIndex(x => x.ImageId == _currentImgId);
  1333. _currentImgIdex = imgIdx;
  1334. if (imgIdx < 0)
  1335. {
  1336. //return;
  1337. //continue;
  1338. }
  1339. else
  1340. {
  1341. _currentImgIdex = imgIdx;
  1342. }
  1343. DescriAlgorithmModelAll(img, openFileDialog.FileName);
  1344. }
  1345. string tmp = System.IO.Path.GetFileNameWithoutExtension(openFileDialog.FileName);
  1346. _imgNameQueue.Enqueue(tmp);
  1347. }
  1348. private void OnLoadOneImageDBClick(object sender, RoutedEventArgs e)
  1349. {
  1350. }
  1351. //单张处理图像对应的函数
  1352. private unsafe void DescriAlgorithmModelAll(Bitmap bmp, string name)
  1353. {
  1354. if (bmp == null)
  1355. {
  1356. //MessageBox.Show("请先加载待测图像!");
  1357. return;
  1358. }
  1359. var rawImage = RawImageShowUtils.BitmapToRawImage(bmp);
  1360. _caseId = Guid.NewGuid().ToString();
  1361. _dataId = name;
  1362. _readingVideo = false;
  1363. var extendData = new Dictionary<string, object>();
  1364. extendData.Add("CaseId", _caseId);
  1365. extendData.Add("DataId", _dataId);
  1366. extendData.Add("IsVideo", _readingVideo);
  1367. extendData.Add("TimeStamp", (double)_frameIndex);
  1368. _processId = _module.StartProcess();
  1369. var input = new ImageInputData(rawImage, extendData);
  1370. IDetectedObject[] result = _module.PushOnePieceOfData(_processId, input);
  1371. _module.EndProcess(_processId);
  1372. Bitmap dstimage = (Bitmap)_currentimg.Clone();
  1373. Bitmap oriimage = (Bitmap)_currentimg.Clone();
  1374. int lesionNum = 0;
  1375. string strDescriptionEcho = string.Empty;
  1376. string strDescriptionShape = string.Empty;
  1377. string strDescriptionMargin = string.Empty;
  1378. string strDescriptionEchogenicFoci = string.Empty;
  1379. System.Drawing.PointF[] axisH = new PointF[2];
  1380. System.Drawing.PointF[] axisV = new PointF[2];
  1381. foreach (var moduleResult in result)
  1382. {
  1383. var label = moduleResult.Label;
  1384. var nameOrgan = label.GroupName;
  1385. if(nameOrgan != "AI.Vaid.Breast.Lesion")
  1386. {
  1387. continue;
  1388. }
  1389. if (moduleResult.Contour == null || moduleResult.Measurements == null || moduleResult.Description == null)
  1390. {
  1391. continue;
  1392. }
  1393. var resultConversion = AIModuleResultShowUtils.GetObjectStr(moduleResult);
  1394. if (moduleResult.Contour?.Contours.Length > 0)
  1395. {
  1396. //ShowContour(moduleResult.Contour, brush, null, transform);
  1397. int count = moduleResult.Contour.Contours.Length;
  1398. for (int i = 0; i < count; i++)
  1399. {
  1400. var contourPoints = moduleResult.Contour.Contours[i];
  1401. int pointCount = contourPoints.Points.Length;
  1402. var points = new List<System.Windows.Point>();
  1403. System.Drawing.PointF[] lesionContour = new PointF[pointCount];
  1404. for (int j = 0; j < pointCount; j++)
  1405. {
  1406. var point = new System.Windows.Point(contourPoints.Points[j].X, contourPoints.Points[j].Y);
  1407. lesionContour[j].X = contourPoints.Points[j].X;
  1408. lesionContour[j].Y = contourPoints.Points[j].Y;
  1409. }
  1410. var desResult = moduleResult.Description;
  1411. var type = desResult.GetType();
  1412. string strDescription = string.Empty;
  1413. //if (type == typeof(BreastLesionDescription))
  1414. {
  1415. foreach (var key in desResult.Descriptions.Keys)
  1416. {
  1417. if (key == "Shape")
  1418. {
  1419. string des = string.Empty;
  1420. switch (desResult.Descriptions[key])
  1421. {
  1422. case "Oval":
  1423. des = "椭圆形";
  1424. break;
  1425. case "Round":
  1426. des = "类圆形";
  1427. break;
  1428. case "Irregular":
  1429. des = "不规则形";
  1430. break;
  1431. }
  1432. strDescription += "形状:" + des + Environment.NewLine;
  1433. }
  1434. if (key == "Orientation")
  1435. {
  1436. string des = string.Empty;
  1437. switch (desResult.Descriptions[key])
  1438. {
  1439. case "Parallel":
  1440. des = "平行";
  1441. break;
  1442. case "NonParallel":
  1443. des = "非平行";
  1444. break;
  1445. }
  1446. strDescription += "生长方向:" + des + Environment.NewLine;
  1447. }
  1448. if (key == "EchoPattern")
  1449. {
  1450. string des = string.Empty;
  1451. switch (desResult.Descriptions[key])
  1452. {
  1453. case "Anechoic":
  1454. des = "无回声";
  1455. break;
  1456. case "Hypoechoic":
  1457. des = "低回声";
  1458. break;
  1459. case "Isoechoic":
  1460. des = "等回声";
  1461. break;
  1462. case "Hyperechoic":
  1463. des = "高回声";
  1464. break;
  1465. case "Complex":
  1466. des = "混合回声";
  1467. break;
  1468. }
  1469. strDescription += "回声类型:" + des + Environment.NewLine;
  1470. }
  1471. if (key == "Boundary")
  1472. {
  1473. string des = string.Empty;
  1474. switch (desResult.Descriptions[key])
  1475. {
  1476. case "AbruptInterface":
  1477. des = "清晰";
  1478. break;
  1479. case "EchogenicHalo":
  1480. des = "模糊";
  1481. break;
  1482. }
  1483. strDescription += "边界:" + des + Environment.NewLine;
  1484. }
  1485. if (key == "Margin")
  1486. {
  1487. string des = string.Empty;
  1488. switch (desResult.Descriptions[key])
  1489. {
  1490. case "Circumscribed":
  1491. des = "光整";
  1492. break;
  1493. case "NonCircumscribed":
  1494. des = "不光整";
  1495. break;
  1496. }
  1497. strDescription += "边缘:" + des + Environment.NewLine;
  1498. }
  1499. if (key == "Calcification")
  1500. {
  1501. string des = string.Empty;
  1502. switch (desResult.Descriptions[key])
  1503. {
  1504. case "NoCalcifications":
  1505. des = "无钙化";
  1506. break;
  1507. case "Macrocalcifications":
  1508. des = "粗钙化";
  1509. break;
  1510. case "Microcalcifications":
  1511. des = "微钙化";
  1512. break;
  1513. }
  1514. strDescription += "钙化:" + des + Environment.NewLine;
  1515. }
  1516. if(key == "PosteriorAcousticFeature")
  1517. {
  1518. string des = string.Empty;
  1519. switch (desResult.Descriptions[key])
  1520. {
  1521. case "Shadowing":
  1522. des = "衰减";
  1523. _Shadowing++;
  1524. break;
  1525. case "Enhancement":
  1526. des = "增强";
  1527. _Enhancement++;
  1528. break;
  1529. case "Absent":
  1530. des = "无改变";
  1531. _Absent++;
  1532. break;
  1533. case "Combined":
  1534. des = "混合";
  1535. _Combined++;
  1536. break;
  1537. }
  1538. strDescription += "后部声学特征:" + des + Environment.NewLine;
  1539. }
  1540. }
  1541. }
  1542. var rect = moduleResult.BoundingBox.Contour.BoundingBox();
  1543. var roiBox = moduleResult.BoundingBox;
  1544. var ss = roiBox.Contour.Points;
  1545. var lesionSize = Array.Find(moduleResult.Measurements, x => x.GetType() == typeof(TransverseLongitudinalDiameterMeasurement));
  1546. var size = (TransverseLongitudinalDiameterMeasurement)lesionSize;
  1547. var pointLineH1 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineStart.X, size.TransverseDiameterMarkPosition.LineStart.Y);
  1548. var pointLineH2 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineEnd.X, size.TransverseDiameterMarkPosition.LineEnd.Y);
  1549. var pointLineV1 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineStart.X, size.LongitudinalDiameterMarkPosition.LineStart.Y);
  1550. var pointLineV2 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineEnd.X, size.LongitudinalDiameterMarkPosition.LineEnd.Y);
  1551. axisH[0].X = (int)pointLineH1.X;
  1552. axisH[0].Y = (int)pointLineH1.Y;
  1553. axisH[1].X = (int)pointLineH2.X;
  1554. axisH[1].Y = (int)pointLineH2.Y;
  1555. axisV[0].X = (int)pointLineV1.X;
  1556. axisV[0].Y = (int)pointLineV1.Y;
  1557. axisV[1].X = (int)pointLineV2.X;
  1558. axisV[1].Y = (int)pointLineV2.Y;
  1559. using (var g = Graphics.FromImage(dstimage))
  1560. {
  1561. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  1562. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
  1563. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  1564. if (lesionContour.Length > 1)//画直线要超过一个点
  1565. {
  1566. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  1567. g.DrawLines(pen, lesionContour); //画病灶轮廓
  1568. pen.Dispose();
  1569. }
  1570. //画轮廓的长短轴
  1571. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  1572. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  1573. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  1574. g.DrawLines(pen_v, axisV); //纵轴,红色
  1575. SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.GreenYellow);
  1576. g.DrawString(lesionNum.ToString(), new Font("Arial", 20),
  1577. drawBrush, lesionBox.Left, lesionBox.Top);
  1578. g.DrawString(strDescription, new Font("Arial", 20),
  1579. drawBrush, rect.Top + 10, rect.Top + 10);
  1580. g.Dispose();
  1581. }
  1582. }
  1583. }
  1584. }
  1585. EchoPatternDescri.Text = strDescriptionEcho;
  1586. //ShapeDescri.Text = strDescriptionShape;
  1587. //MarginDescri.Text = strDescriptionMargin;
  1588. //EchogenicFociDescri.Text = strDescriptionEchogenicFoci;
  1589. _dstimg = ImageUtility.BitmapToBitmapImage(dstimage);
  1590. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  1591. {
  1592. DstImage.Source = _dstimg;
  1593. }));
  1594. dstimage.Dispose();
  1595. _origimg = ImageUtility.BitmapToBitmapImage(oriimage);
  1596. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  1597. {
  1598. //OrigImage.Source = _origimg;
  1599. ImageUpdated();
  1600. }));
  1601. oriimage.Dispose();
  1602. //return result;
  1603. }
  1604. private void OnModelsProcessAllClick(object sender, RoutedEventArgs e)
  1605. {
  1606. OpenFileDialog openFileDialog = new OpenFileDialog();
  1607. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1608. openFileDialog.Multiselect = true;
  1609. openFileDialog.Title = "选择一幅或多幅图像";
  1610. if (openFileDialog.ShowDialog() ?? false)
  1611. {
  1612. foreach (string filename in openFileDialog.FileNames)
  1613. {
  1614. Bitmap img = new Bitmap(filename);
  1615. _currentimg = img;
  1616. string temp;
  1617. int idx = filename.LastIndexOf("\\");
  1618. temp = filename.Substring(idx);
  1619. string[] strs1 = temp.Split('\\');
  1620. temp = strs1[1];
  1621. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1622. //string ImgId = strs2[0];
  1623. string[] sArray = null;
  1624. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1625. string ImgId = sArray[0];
  1626. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  1627. _currentImgId = ImgId;
  1628. int imgIdx = _allImages.FindIndex(x => x.ImageId == _currentImgId);
  1629. //if (imgIdx < 0)
  1630. //{
  1631. // //return;
  1632. // //continue;
  1633. //}
  1634. //else
  1635. {
  1636. _currentImgIdex = imgIdx;
  1637. //DoDescriAlgorithm(ImgId);
  1638. DescriAlgorithmModelAll(img, openFileDialog.FileName);
  1639. }
  1640. }
  1641. }
  1642. Console.WriteLine("衰减: " + _Shadowing);
  1643. Console.WriteLine("增强: " + _Enhancement);
  1644. Console.WriteLine("无改变: " + _Absent);
  1645. Console.WriteLine("混合: " + _Combined);
  1646. Console.WriteLine();
  1647. }
  1648. private void OnDrawImageDBClick(object sender, RoutedEventArgs e)
  1649. {
  1650. OpenFileDialog openFileDialog = new OpenFileDialog();
  1651. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1652. openFileDialog.Multiselect = true;
  1653. openFileDialog.Title = "选择一幅或多幅图像";
  1654. if (openFileDialog.ShowDialog() ?? false)
  1655. {
  1656. foreach (string filename in openFileDialog.FileNames)
  1657. {
  1658. Bitmap img = new Bitmap(filename);
  1659. _currentimg = img;
  1660. string temp;
  1661. int idx = filename.LastIndexOf("\\");
  1662. temp = filename.Substring(idx);
  1663. string[] strs1 = temp.Split('\\');
  1664. temp = strs1[1];
  1665. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1666. //string ImgId = strs2[0];
  1667. string[] sArray = null;
  1668. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1669. string ImgId = sArray[0];
  1670. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  1671. _currentImgId = ImgId;
  1672. int imgIdx = _allImages.FindIndex(x => x.ImageId == _currentImgId);
  1673. if (imgIdx < 0)
  1674. {
  1675. //return;
  1676. continue;
  1677. }
  1678. else
  1679. {
  1680. _currentImgIdex = imgIdx;
  1681. //DoDescriAlgorithm(ImgId);
  1682. if (_currentimg == null)
  1683. {
  1684. MessageBox.Show("请先加载待测图像!");
  1685. return;
  1686. }
  1687. Bitmap bmp = _currentimg;
  1688. //RawImage rawImg = BitmapToRawImage(bmp);
  1689. roiCoor roi;
  1690. roi.x = 0;
  1691. roi.y = 0;
  1692. roi.width = _currentimg.Width;
  1693. roi.height = _currentimg.Height;
  1694. int LesionsNum = _allImages[_currentImgIdex].Lesions.Count;
  1695. //确定存在病灶
  1696. if (LesionsNum > 0)
  1697. {
  1698. Bitmap dstimage = (Bitmap)_currentimg.Clone();
  1699. //Bitmap oriimage = (Bitmap)_currentimg.Clone();
  1700. int lesionsNum = _allImages[_currentImgIdex].Lesions.Count;
  1701. for (int ii = 0; ii < lesionsNum; ii++)
  1702. {
  1703. //获取病灶轮廓
  1704. int num2 = _allImages[_currentImgIdex].Lesions[ii].Contour.Count;
  1705. MyPoint[] lesionPts = new MyPoint[num2];
  1706. System.Drawing.PointF[] lesionContour = new PointF[num2];
  1707. for (int i = 0; i < num2; i++)
  1708. {
  1709. lesionPts[i].x = _allImages[_currentImgIdex].Lesions[ii].Contour[i].x;
  1710. lesionPts[i].y = _allImages[_currentImgIdex].Lesions[ii].Contour[i].y;
  1711. lesionContour[i].X = _allImages[_currentImgIdex].Lesions[ii].Contour[i].x;
  1712. lesionContour[i].Y = _allImages[_currentImgIdex].Lesions[ii].Contour[i].y;
  1713. }
  1714. EchoPattern echoGT = (EchoPattern)(_allImages[_currentImgIdex].Lesions[ii].EchoPattern) + 1;
  1715. Boundary boundaryGT = (Boundary)(_allImages[_currentImgIdex].Lesions[ii].Boundary) + 1;
  1716. MarginEnum marginGT = (MarginEnum)(_allImages[_currentImgIdex].Lesions[ii].Margin) + 1;
  1717. ContourShape shapeCppGT = (ContourShape)(_allImages[_currentImgIdex].Lesions[ii].Shape) + 1;
  1718. Orientation orientationGT = (Orientation)(_allImages[_currentImgIdex].Lesions[ii].Orientation) + 1;
  1719. int resMar = -1;
  1720. int resShape = -1;
  1721. string strDescription = string.Empty;
  1722. //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  1723. {
  1724. string strName = string.Empty;
  1725. if (shapeCppGT == ContourShape.Oval)
  1726. {
  1727. ContourShapeDescriPr.Text = "椭圆形";
  1728. strName = "椭圆形";
  1729. resShape = 1;
  1730. }
  1731. else if (shapeCppGT == ContourShape.Round)
  1732. {
  1733. strName = "类圆形";
  1734. ContourShapeDescriPr.Text = strName;
  1735. resShape = 2;
  1736. }
  1737. else if (shapeCppGT == ContourShape.Irregular)
  1738. {
  1739. strName = "不规则形";
  1740. ContourShapeDescriPr.Text = strName;
  1741. resShape = 3;
  1742. }
  1743. else if (shapeCppGT == ContourShape.NoneShape)
  1744. {
  1745. strName = "未标注";
  1746. ContourShapeDescriPr.Text = "未标注";
  1747. }
  1748. strDescription += " 形状:" + strName + "\r\n";
  1749. strName = string.Empty;
  1750. if (orientationGT == Orientation.NonParallel)
  1751. {
  1752. strName = "非平行";
  1753. GrowDirectionDescriPr.Text = "非平行";
  1754. }
  1755. else if (orientationGT == Orientation.Parallel)
  1756. {
  1757. strName = "平行";
  1758. GrowDirectionDescriPr.Text = "平行";
  1759. }
  1760. else if (orientationGT == Orientation.NoneOrientation)
  1761. {
  1762. strName = "未标注";
  1763. GrowDirectionDescriPr.Text = "未标注";
  1764. }
  1765. strDescription += " 方向:" + strName + "\r\n";
  1766. strName = string.Empty;
  1767. if (echoGT == EchoPattern.Anechoic) // 1无回声
  1768. {
  1769. strName = "无回声";
  1770. EchoPatternDescriPr.Text = "无回声";
  1771. }
  1772. else if (echoGT == EchoPattern.Hypoechoic) // 2低回声
  1773. {
  1774. strName = "低回声";
  1775. EchoPatternDescriPr.Text = "低回声";
  1776. }
  1777. else if (echoGT == EchoPattern.Complex) // 5混合回声
  1778. {
  1779. strName = "混合回声";
  1780. EchoPatternDescriPr.Text = "混合回声";
  1781. }
  1782. else if (echoGT == EchoPattern.NoneEcho)
  1783. {
  1784. strName = "未标注";
  1785. EchoPatternDescriPr.Text = "未标注";
  1786. }
  1787. strDescription += " 回声:" + strName + "\r\n";
  1788. strName = string.Empty;
  1789. // 边界清晰度
  1790. if (boundaryGT == Boundary.AbruptInterface)
  1791. {
  1792. strName = "清晰";
  1793. BoundaryBoundaryDescriPr.Text = "清晰";
  1794. }
  1795. else if (boundaryGT == Boundary.EchogenicHalo)
  1796. {
  1797. strName = "不清晰";
  1798. BoundaryBoundaryDescriPr.Text = "不清晰";
  1799. }
  1800. else if (boundaryGT == Boundary.NoneBoundary)
  1801. {
  1802. strName = "未标注";
  1803. BoundaryBoundaryDescriPr.Text = "未标注";
  1804. }
  1805. strDescription += " 边界:" + strName + "\r\n";
  1806. strName = string.Empty;
  1807. // 边缘光整度
  1808. if (marginGT == SegmentDescribDemo.MarginEnum.Circumscribed)
  1809. {
  1810. strName = "光整";
  1811. EdgeMarginDescriPr.Text = "光整";
  1812. resMar = 1;
  1813. }
  1814. else if (marginGT == SegmentDescribDemo.MarginEnum.NonCircumscribed)
  1815. {
  1816. strName = "不光整";
  1817. EdgeMarginDescriPr.Text = "不光整";
  1818. resMar = 2;
  1819. }
  1820. else if (marginGT == SegmentDescribDemo.MarginEnum.NoneMargin)
  1821. {
  1822. strName = "未标注";
  1823. EdgeMarginDescriPr.Text = "未标注";
  1824. }
  1825. strDescription += " 边缘:" + strName + "\r\n";
  1826. strName = string.Empty;
  1827. ///////////////////////////////////////////////////////////
  1828. }
  1829. ////));
  1830. using (var g = Graphics.FromImage(dstimage))
  1831. {
  1832. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  1833. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
  1834. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  1835. if (lesionContour.Length > 5)
  1836. {
  1837. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  1838. g.DrawLines(pen, lesionContour); //画病灶轮廓
  1839. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  1840. if (lesionPts.Length > 0)
  1841. {
  1842. //g.DrawLines(pen2, lesionPts); //画肝脏轮廓
  1843. }
  1844. pen.Dispose();
  1845. }
  1846. //画轮廓的长短轴
  1847. //System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  1848. //g.DrawLines(pen_h, axisH); //横轴,浅绿色
  1849. //System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  1850. //g.DrawLines(pen_v, axisV); //纵轴,红色
  1851. SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.GreenYellow);
  1852. g.DrawString(strDescription, new Font("Arial", 20),drawBrush, roi.x + 10, roi.y + 10);
  1853. g.Dispose();
  1854. }
  1855. string newPath = System.IO.Path.Combine(_currentPath, "result");
  1856. if (resMar == 1)
  1857. {
  1858. string nameSave = newPath + "\\01\\" + _currentImgId + ".jpg";
  1859. //if (shapeCppGT == ShapeEnum.WiderThanTall)
  1860. {
  1861. dstimage.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1862. }
  1863. }
  1864. else if (resMar == 2)
  1865. {
  1866. string nameSave = newPath + "\\02\\" + _currentImgId + ".jpg";
  1867. //if (shapeCppGT == ShapeEnum.WiderThanTall)
  1868. {
  1869. dstimage.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1870. }
  1871. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1872. }
  1873. //if (resShape == 1)
  1874. //{
  1875. // string nameSave = newPath + "\\01\\" + _currentImgId + ".jpg";
  1876. // //if (shapeCppGT == ShapeEnum.WiderThanTall)
  1877. // {
  1878. // dstimage.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1879. // }
  1880. //}
  1881. //else if (resShape == 2)
  1882. //{
  1883. // string nameSave = newPath + "\\02\\" + _currentImgId + ".jpg";
  1884. // //if (shapeCppGT == ShapeEnum.WiderThanTall)
  1885. // {
  1886. // dstimage.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1887. // }
  1888. // //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1889. //}
  1890. //else if (resShape == 3)
  1891. //{
  1892. // string nameSave = newPath + "\\03\\" + _currentImgId + ".jpg";
  1893. // dstimage.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  1894. //}
  1895. }
  1896. }
  1897. }
  1898. }
  1899. }
  1900. }
  1901. }
  1902. }