MainWindow.xaml.cs 217 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403
  1. using DescriptionDeeplearn;
  2. using Microsoft.Win32;
  3. using Newtonsoft.Json;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.SQLite;
  7. using System.Drawing;
  8. using System.Drawing.Imaging;
  9. ///for DllImport
  10. using System.IO;
  11. using System.Runtime.InteropServices;
  12. using System.Security.Cryptography;
  13. using System.Text;
  14. using System.Windows;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Threading;
  17. using System.Xml.Linq;
  18. using System.Windows.Controls;
  19. using AI.Common.Interface;
  20. using System.Xml.Linq;
  21. using AI.Common.Implements;
  22. using RawImageShowUtilsLib;
  23. using AIModuleResultShowUtilsLib;
  24. using System.Reflection;
  25. namespace ThyroidDescriptionUI
  26. {
  27. /// <summary>
  28. /// Interaction logic for MainWindow.xaml
  29. /// </summary>
  30. public partial class MainWindow : Window
  31. {
  32. #region private variables
  33. private BitmapImage _origImg;
  34. private BitmapImage _dstImg;
  35. private Queue<Bitmap> _imagesReadyToDrawBox = new Queue<Bitmap>();
  36. private Queue<SegDataInput> _testDatas = new Queue<SegDataInput>();
  37. private System.Windows.Media.Brush _roiColor = System.Windows.Media.Brushes.Orange;
  38. private System.Drawing.Rectangle _drawingRoi = System.Drawing.Rectangle.Empty;
  39. private Bitmap _currentImg;
  40. private Queue<string> _imgNameQueue = new Queue<string>(); // 图像文件名(循环读图)
  41. private List<string> _imgNameList = new List<string>(); // 图像文件名
  42. #endregion
  43. //private AIDiagSystem _aiSeg;
  44. private List<GTImgInfo> _allImgInfo;
  45. private string _currentImgId;
  46. private int _currentImgIdex;
  47. private string _currentBinPath;
  48. private Bitmap _showImg;
  49. private string _dbPathChoose;
  50. private string _imgPathChoose;
  51. private ProcessData _UseNet = null;
  52. private DescriptionCoreDeeplearning _inferNet = null;
  53. private string _netsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  54. private readonly DescriptionDeeplearn.InferenceCore _inferCore = new DescriptionDeeplearn.InferenceCore();
  55. private readonly DescriptionDeeplearn.EnumDeviceType _deviceType = DescriptionDeeplearn.EnumDeviceType.CPU;
  56. //
  57. private IModule _module;
  58. //private string _currentPath;
  59. private InferenceConfig _inferConfig = new InferenceConfig();
  60. private string _netDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
  61. private volatile string _processId = string.Empty;
  62. private volatile string _caseId = string.Empty;
  63. private volatile string _dataId = string.Empty;
  64. private volatile bool _readingVideo;
  65. private volatile int _frameIndex;
  66. //局灶性强回声
  67. private int _NoCifications_NoCifications_num = 0; //无钙化 判为 无钙化
  68. private int _NoCifications_Coarsecalcifications_num = 0;
  69. private int _NoCifications_Macrocalcifications_num = 0;
  70. private int _Coarsecalcifications_Coarsecalcifications_num = 0; //粗钙化 判为 粗钙化
  71. private int _Coarsecalcifications_NoCifications_num = 0;
  72. private int _Coarsecalcifications_Macrocalcifications_num = 0;
  73. private int _Macrocalcifications_Macrocalcifications_num = 0; //微钙化 判为 微钙化
  74. private int _Macrocalcifications_NoCifications_num = 0;
  75. private int _Macrocalcifications_Coarsecalcifications_num = 0;
  76. //回声
  77. private int _Anechoic_Anechoi_num = 0; //无回声 判为 无回声 的数目
  78. private int _Anechoic_Hyperechoic_num = 0; //无回声 判为 高回声 的数目
  79. private int _Anechoic_Isoechoic_num = 0;
  80. private int _Anechoic_Hypoechoic_num = 0;
  81. private int _Anechoic_HypoechoicLower_num = 0;
  82. private int _Hyperechoic_Hyperechoic_num = 0; //高回声 判为 高回声
  83. private int _Hyperechoic_Anechoic_num = 0;
  84. private int _Hyperechoic_Isoechoic_num = 0;
  85. private int _Hyperechoic_Hypoechoic_num = 0;
  86. private int _Hyperechoic_HypoechoicLower_num = 0;
  87. private int _Isoechoic_Isoechoic_num = 0; //等回声 判为 等回声
  88. private int _Isoechoic_Anechoic_num = 0;
  89. private int _Isoechoic_Hyperechoic_num = 0;
  90. private int _Isoechoic_Hypoechoic_num = 0;
  91. private int _Isoechoic_HypoechoicLower_num = 0;
  92. private int _Hypoechoic_Hypoechoic_num = 0; //低回声 判为 低回声
  93. private int _Hypoechoic_Anechoic_num = 0;
  94. private int _Hypoechoic_Hyperechoic_num = 0;
  95. private int _Hypoechoic_Isoechoic_num = 0;
  96. private int _Hypoechoic_HypoechoicLower_num = 0;
  97. private int _HypoechoicLower_HypoechoicLower_num = 0; //极低回声 判为 极低回声
  98. private int _HypoechoicLower_Anechoicr_num = 0;
  99. private int _HypoechoicLower_Hyperechoic_num = 0;
  100. private int _HypoechoicLower_Isoechoic_num = 0;
  101. private int _HypoechoicLower_Hypoechoic_num = 0;
  102. //形状
  103. private int _WT_WT_num = 0; //宽大于高 判为 宽大于高
  104. private int _WT_TW_num = 0; //宽大于高 判为 高大于宽
  105. private int _TW_TW_num = 0; //高大于宽 判为 高大于宽
  106. private int _TW_WT_num = 0; //高大于宽 判为 宽大于高
  107. //边缘
  108. int _Smooth_Smooth_num = 0; //光整 判为 模糊
  109. int _Smooth_IllDefined_num = 0;
  110. int _Smooth_Lobulated_num = 0;
  111. int _Smooth_Irregular_num = 0;
  112. int _Smooth_ExtraThyroidalExtension_num = 0;
  113. int _IllDefined_IllDefined_num = 0; //模糊 判为 模糊
  114. int _IllDefined_Smooth_num = 0;
  115. int _IllDefined_Lobulated_num = 0;
  116. int _IllDefined_Irregular_num = 0;
  117. int _IllDefined_ExtraThyroidalExtension_num = 0;
  118. int _Lobulated_Lobulated_num = 0; //分叶 判为 分叶
  119. int _Lobulated_Smooth_num = 0;
  120. int _Lobulated_IllDefined_num = 0;
  121. int _Lobulated_Irregular_num = 0;
  122. int _Lobulated_ExtraThyroidalExtension_num = 0;
  123. int _Irregular_Irregular_num = 0; //不规则 判为 不规则
  124. int _Irregular_Smooth_num = 0;
  125. int _Irregular_IllDefined_num = 0;
  126. int _Irregular_Lobulated_num = 0;
  127. int _Irregular_ExtraThyroidalExtension_num = 0;
  128. int _ExtraThyroidalExtension_ExtraThyroidalExtension_num = 0; //甲状腺外侵犯 判为 甲状腺外侵犯
  129. int _ExtraThyroidalExtension_Smooth_num = 0;
  130. int _ExtraThyroidalExtension_IllDefined_num = 0;
  131. int _ExtraThyroidalExtension_Lobulated_num = 0;
  132. int _ExtraThyroidalExtension_Irregular_num = 0;
  133. int testNUm = 0;
  134. public MainWindow()
  135. {
  136. InitializeComponent();
  137. _origImg = null;
  138. _dstImg = null;
  139. OrigImage.Source = _origImg;
  140. DstImage.Source = _dstImg;
  141. _showImg = null;
  142. _currentBinPath = System.Environment.CurrentDirectory;
  143. //button1.Visibility = Visibility.Collapsed;
  144. _module = new AI.Vaid.Modules.ThyroidLesionDetect.ThyroidLesionDetect(_netDir, _inferConfig, AI.Common.Interface.EnumDeviceType.CPU);
  145. }
  146. private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
  147. {
  148. }
  149. private void OnErrorOccur(object sender, ErrorEventArgs e)
  150. {
  151. MessageBox.Show("接收到task发出的错误:" + e.GetException());
  152. }
  153. [DllImport(@"LesionAxis.dll", CallingConvention = CallingConvention.Cdecl)]
  154. public static unsafe extern void MyLesionAxisProcess(roiCoor roiVec, int ptsNum, StructPoint[] lesionPts, ref AxisPoint axis);
  155. [DllImport(@"BreastLesionSeg.dll", CallingConvention = CallingConvention.Cdecl)]
  156. public static unsafe extern int ContourDetectBLS(byte[] img_data, int channels, int img_width, int img_height,
  157. roiCoor roi_vec, [In, Out] StructPoint[] contour_points);
  158. [DllImport(@"BreastLesionSeg.dll", CallingConvention = CallingConvention.Cdecl)]
  159. public static unsafe extern int ContourDetectBLSForThyroid(byte[] img_data, int channels, int img_width, int img_height,
  160. roiCoor roi_vec, [In, Out] StructPoint[] contour_points);
  161. [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
  162. public static extern void ThyroidDescription(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
  163. StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, ref LesionDescri lesionDescr);
  164. [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
  165. public static extern void ThyroidDescriptionGetLesionPart(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
  166. StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, int index, char[] imgName);
  167. [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
  168. public static extern void ThyroidDescriptionModelAfterProcess_1(byte[] imgDataModel, int imgWModel, int imgHModel, int channelModel, roiCoor roiVecModel,
  169. byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
  170. StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, ref LesionDescri lesionDescr);
  171. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  172. ///与病灶细分割配合使用
  173. public static extern void ThyroidDescriptionContour(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1, StructPoint[] lesionPts
  174. , ref roiCoor roi);
  175. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  176. public static extern void ThyroidDescriptionModelProcess(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
  177. StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, int modelW, int modelH, int modelChannel,
  178. ref roiCoor roiDst, byte[] imgDataDst);
  179. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  180. public static extern void ThyroidDescriptionModelProcessModelImage(byte[] imgModelData, int imgModelW,
  181. int imgModelH, int channelModel, roiCoor roiModelVec,
  182. ref int contourNum, int[] contourLen, [In, Out] StructPoint[] calcificationPts);
  183. [DllImport(@"LesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
  184. public static extern void ThyroidDescriptionModelAfterProcess(byte[] imgData, int channels, int imgW, int imgH, /*roiCoor roiVec,*/ int ptsNum1,
  185. StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts,
  186. int contourNum, int[] contourLen, StructPoint[] calcificationPts, roiCoor roiVecModel, ref LesionDescri lesionDescr);
  187. [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
  188. public static extern void video2image();
  189. /// 更新显示已有的轮廓
  190. private void ShowContour()
  191. {
  192. if (_origImg == null || _allImgInfo.Count <= 0)
  193. {
  194. return;
  195. }
  196. // 显示甲状腺轮廓
  197. List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
  198. int num1 = thyroidCont.Count;
  199. if (_allImgInfo[_currentImgIdex].Lesions.Count <= 0)
  200. {
  201. return;
  202. }
  203. // 显示新的病灶
  204. //LesionInfo lesion = _allImgInfo[_currentImgIdex].Lesions[0];
  205. //int num2 = lesion.LesionContour.Count;
  206. Bitmap origImg = (Bitmap)_currentImg.Clone();
  207. using (var g = Graphics.FromImage(origImg))
  208. {
  209. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  210. //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
  211. //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  212. System.Drawing.PointF[] thyroidContour = new PointF[num1];
  213. for (int i = 0; i < num1; i++)
  214. {
  215. thyroidContour[i].X = thyroidCont[i].X;
  216. thyroidContour[i].Y = thyroidCont[i].Y;
  217. }
  218. int numLesion = _allImgInfo[_currentImgIdex].Lesions.Count;
  219. System.Drawing.PointF[][] lesionContours = new PointF[numLesion][];
  220. for (int ni = 0; ni < numLesion; ni++)
  221. {
  222. int num = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour.Count;
  223. lesionContours[ni] = new PointF[num];
  224. for (int nj = 0; nj < num; nj++)
  225. {
  226. lesionContours[ni][nj].X = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour[nj].X;
  227. lesionContours[ni][nj].Y = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour[nj].Y;
  228. }
  229. }
  230. //画点
  231. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  232. for (int ni = 0; ni < numLesion; ni++)
  233. {
  234. if (lesionContours[ni] != null)
  235. {
  236. g.DrawLines(pen, lesionContours[ni]); //画病灶轮廓
  237. }
  238. }
  239. pen.Dispose();
  240. if (num1 > 0)
  241. {
  242. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  243. g.DrawLines(pen2, thyroidContour); //画甲状腺轮廓
  244. pen2.Dispose();
  245. }
  246. for (int ni = 0; ni < numLesion; ni++)
  247. {
  248. LesionInfo lesion = _allImgInfo[_currentImgIdex].Lesions[ni];
  249. System.Drawing.PointF[] axisH = new PointF[2];
  250. System.Drawing.PointF[] axisV = new PointF[2];
  251. axisH[0].X = lesion.HorizontalPoint1.X;
  252. axisH[0].Y = lesion.HorizontalPoint1.Y;
  253. axisH[1].X = lesion.HorizontalPoint2.X;
  254. axisH[1].Y = lesion.HorizontalPoint2.Y;
  255. axisV[0].X = lesion.VerticalPoint1.X;
  256. axisV[0].Y = lesion.VerticalPoint1.Y;
  257. axisV[1].X = lesion.VerticalPoint2.X;
  258. axisV[1].Y = lesion.VerticalPoint2.Y;
  259. //画轮廓的长短轴
  260. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  261. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  262. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  263. g.DrawLines(pen_v, axisV); //纵轴,红色
  264. }
  265. g.Dispose();
  266. }
  267. //origImg.Save("E:\\SVN\\Trunk\\SourceCode\\OnGoingTasks\\ThyroidLesionDetect\\SourceCode\\ThyroidDescriptionCore\\Bin\\1.jpg");
  268. _showImg = origImg;
  269. _origImg = ImageUtility.BitmapToBitmapImage(origImg);
  270. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  271. {
  272. OrigImage.Source = _origImg;
  273. }));
  274. origImg.Dispose();
  275. }
  276. private void OnLoadDataBaseClick(object sender, RoutedEventArgs e)
  277. {
  278. OpenFileDialog openFileDialog = new OpenFileDialog();
  279. openFileDialog.Filter = "数据库文件|*.db";
  280. openFileDialog.Multiselect = false;
  281. openFileDialog.Title = "选择一个数据库文件";
  282. string dbPath = "";
  283. if (openFileDialog.ShowDialog() ?? false)
  284. {
  285. dbPath = openFileDialog.FileName;
  286. }
  287. DataBase dataBase = new DataBase(dbPath);
  288. bool readDb = dataBase.ReadDataBase();
  289. if (readDb)
  290. {
  291. _allImgInfo = dataBase._allImages;
  292. if (_allImgInfo.Count > 0)
  293. {
  294. MessageBox.Show("加载成功!");
  295. }
  296. }
  297. else
  298. {
  299. MessageBox.Show("读取失败!");
  300. }
  301. }
  302. // 加载1张图像
  303. private void OnLoadOneImageClick(object sender, RoutedEventArgs e)
  304. {
  305. if (DstImage.Source != null)
  306. {
  307. DstImage.Source = null;
  308. }
  309. OpenFileDialog openFileDialog = new OpenFileDialog();
  310. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  311. openFileDialog.Multiselect = false;
  312. openFileDialog.Title = "选择一幅图像";
  313. if (openFileDialog.ShowDialog() ?? false)
  314. {
  315. Bitmap img = new Bitmap(openFileDialog.FileName);
  316. string temp = openFileDialog.FileName;
  317. int idx = temp.LastIndexOf("\\");
  318. temp = temp.Substring(idx);
  319. string[] strs1 = temp.Split('\\');
  320. temp = strs1[1];
  321. //string[] strs2 = temp.Split(new char[4] { '.','j','p','g'}, 2);
  322. string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  323. _currentImgId = strs2[0];
  324. _currentImg = img;
  325. }
  326. _origImg = ImageUtility.BitmapToBitmapImage(_currentImg);
  327. OrigImage.Source = _origImg.Clone();
  328. int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
  329. if (imgIdx < 0)
  330. {
  331. return;
  332. }
  333. _currentImgIdex = imgIdx;
  334. DstImage.Source = _origImg.Clone();
  335. ShowContour();
  336. int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
  337. if (LesionsNum > 0)
  338. {
  339. int lesionNum = 0;
  340. string strDescriptionEcho = string.Empty;
  341. string strDescriptionShape = string.Empty;
  342. string strDescriptionMargin = string.Empty;
  343. string strDescriptionEchogenicFoci = string.Empty;
  344. for (int ii = 0; ii < LesionsNum; ii++)
  345. {
  346. EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
  347. ShapeEnum shapeGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
  348. MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
  349. EchogenicFociEnum echogenicFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
  350. string strEcho = string.Empty;
  351. if (echoGT == EchoPatternEnum.Anechoic)
  352. {
  353. strEcho = "无回声";
  354. }
  355. else if (echoGT == EchoPatternEnum.Hyperechoic)
  356. {
  357. strEcho = "高回声";
  358. }
  359. else if (echoGT == EchoPatternEnum.Isoechoic)
  360. {
  361. strEcho = "等回声";
  362. }
  363. else if (echoGT == EchoPatternEnum.Hypoechoic)
  364. {
  365. strEcho = "低回声";
  366. }
  367. else if (echoGT == EchoPatternEnum.HypoechoicLower)
  368. {
  369. strEcho = "极低回声";
  370. }
  371. strDescriptionEcho += lesionNum.ToString() + ":" + strEcho + "\r\n";
  372. string strShape = string.Empty;
  373. if (shapeGT == ShapeEnum.WiderThanTall)
  374. {
  375. strShape = "宽大于高";
  376. }
  377. else if (shapeGT == ShapeEnum.TallThanWider)
  378. {
  379. strShape = "高大于宽";
  380. }
  381. strDescriptionShape += lesionNum.ToString() + ":" + strShape + "\r\n";
  382. string strMargin = string.Empty;
  383. if (marginGT == MarginEnum.Smooth)
  384. {
  385. strMargin = "边缘光整";
  386. }
  387. else if (marginGT == MarginEnum.IllDefined)
  388. {
  389. strMargin = "边缘模糊";
  390. }
  391. else if (marginGT == MarginEnum.Lobulated)
  392. {
  393. strMargin = "边缘分叶状";
  394. }
  395. else if (marginGT == MarginEnum.Irregular)
  396. {
  397. strMargin = "边缘不规则";
  398. }
  399. else if (marginGT == MarginEnum.ExtraThyroidalExtension)
  400. {
  401. strMargin = "甲状腺外侵犯";
  402. }
  403. strDescriptionMargin += lesionNum.ToString() + ":" + strMargin + "\r\n";
  404. string strEchogenicFoci = string.Empty;
  405. if (echogenicFociGT == EchogenicFociEnum.NoCifications)
  406. {
  407. strEchogenicFoci = "无钙化";
  408. }
  409. else if (echogenicFociGT == EchogenicFociEnum.Coarsecalcifications)
  410. {
  411. strEchogenicFoci = "粗钙化";
  412. }
  413. else if (echogenicFociGT == EchogenicFociEnum.Microcalcifications)
  414. {
  415. strEchogenicFoci = "微钙化";
  416. }
  417. strDescriptionEchogenicFoci += lesionNum.ToString() + ":" + strEchogenicFoci + "\r\n";
  418. lesionNum++;
  419. }
  420. EchoPatternDescriGT.Text = strDescriptionEcho;
  421. ShapeDescriGT.Text = strDescriptionShape;
  422. MarginDescriGT.Text = strDescriptionMargin;
  423. EchogenicFociDescriGT.Text = strDescriptionEchogenicFoci;
  424. }
  425. else
  426. {
  427. MessageBox.Show("请先加载待测图像!");
  428. }
  429. }
  430. private void OnThyroidDescriClick(object sender, RoutedEventArgs e)
  431. {
  432. if (_currentImg != null)
  433. {
  434. string name = "sos";
  435. DoDescriAlgorithm(name);
  436. }
  437. else
  438. {
  439. MessageBox.Show("请先加载待测图像!");
  440. }
  441. }
  442. //甲状腺描述算法调用接口
  443. private void DoDescriAlgorithm(string name)
  444. {
  445. if (_currentImg == null)
  446. {
  447. MessageBox.Show("请先加载待测图像!");
  448. return;
  449. }
  450. Bitmap bmp = _currentImg;
  451. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
  452. int channel = BitmapChannel(bmp);
  453. roiCoor roi;
  454. roi.x = 0;
  455. roi.y = 0;
  456. roi.width = _currentImg.Width;
  457. roi.height = _currentImg.Height;
  458. int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
  459. int ThyroidNum = _allImgInfo[_currentImgIdex].ThyroidContour.Count;
  460. //确定存在病灶
  461. if (LesionsNum > 0 && ThyroidNum > 0)
  462. {
  463. Bitmap dstimage = (Bitmap)_currentImg.Clone();
  464. int lesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
  465. for (int ii = 0; ii < lesionsNum; ii++)
  466. {
  467. //获取病灶轮廓
  468. int num2 = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour.Count;
  469. StructPoint[] lesionPts = new StructPoint[num2];
  470. System.Drawing.PointF[] lesionContour = new PointF[num2];
  471. for (int i = 0; i < num2; i++)
  472. {
  473. lesionPts[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
  474. lesionPts[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
  475. lesionContour[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
  476. lesionContour[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
  477. }
  478. //获取甲状腺轮廓
  479. List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
  480. int num1 = thyroidCont.Count;
  481. StructPoint[] thyroidPts = new StructPoint[num1];
  482. System.Drawing.PointF[] thyroidContour = new PointF[num1];
  483. for (int i = 0; i < num1; i++)
  484. {
  485. thyroidPts[i].X = thyroidCont[i].X;
  486. thyroidPts[i].Y = thyroidCont[i].Y;
  487. thyroidContour[i].X = thyroidCont[i].X;
  488. thyroidContour[i].Y = thyroidCont[i].Y;
  489. }
  490. EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
  491. EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
  492. ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
  493. MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
  494. LesionDescri desCpp = new LesionDescri();
  495. desCpp.echo = 0;
  496. desCpp.shape = 0;
  497. desCpp.margin = 0;
  498. desCpp.echogenicFoci = 0;
  499. desCpp.axisPt = new AxisPoint();
  500. desCpp.axisPt.horizontalPt1 = new StructPoint { X = 0, Y = 0 };
  501. desCpp.axisPt.horizontalPt2 = new StructPoint { X = 0, Y = 0 };
  502. desCpp.axisPt.verticalPt1 = new StructPoint { X = 0, Y = 0 };
  503. desCpp.axisPt.verticalPt2 = new StructPoint { X = 0, Y = 0 };
  504. System.Drawing.PointF[] axisH = new PointF[2];
  505. System.Drawing.PointF[] axisV = new PointF[2];
  506. //WriteTxtToFile("E:\\image\\", "usename.txt", name, false);
  507. var starttime = Environment.TickCount;
  508. ThyroidDescription(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
  509. roi, num1, thyroidPts, num2, lesionPts, ref desCpp);
  510. ThyroidDescriptionGetLesionPart(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
  511. roi, num1, thyroidPts, num2, lesionPts, ii, name.ToCharArray());
  512. var endtime = Environment.TickCount;
  513. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  514. {
  515. ElapsedTime.Text = (endtime - starttime).ToString();
  516. }));
  517. int echoCpp = desCpp.echo; // 回声
  518. int shapeCpp = desCpp.shape; // 形状
  519. int marginCpp = desCpp.margin; // 边缘
  520. int echogenicFociCpp = desCpp.echogenicFoci; // 局灶性强回声
  521. EchogenicFociEnum echoFoci = (EchogenicFociEnum)desCpp.echogenicFoci;
  522. EchoPatternEnum echo = (EchoPatternEnum)desCpp.echo;
  523. ShapeEnum shape = (ShapeEnum)desCpp.shape;
  524. MarginEnum margin = (MarginEnum)desCpp.margin;
  525. AxisPoint axisPoint = desCpp.axisPt; // 纵、横轴端点坐标
  526. StructPoint pt1 = axisPoint.horizontalPt1; // 横轴
  527. StructPoint pt2 = axisPoint.horizontalPt2;
  528. StructPoint pt3 = axisPoint.verticalPt1; // 纵轴
  529. StructPoint pt4 = axisPoint.verticalPt2;
  530. axisH[0].X = pt1.X;
  531. axisH[0].Y = pt1.Y;
  532. axisH[1].X = pt2.X;
  533. axisH[1].Y = pt2.Y;
  534. axisV[0].X = pt3.X;
  535. axisV[0].Y = pt3.Y;
  536. axisV[1].X = pt4.X;
  537. axisV[1].Y = pt4.Y;
  538. int resCa = -1;
  539. int resEcho = -1;
  540. int resShape = -1;
  541. //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  542. {
  543. if (echoCpp == (int)EchoPatternEnum.Anechoic)
  544. {
  545. EchoPatternDescri.Text = "无回声";
  546. resEcho = 0;
  547. }
  548. else if (echoCpp == (int)EchoPatternEnum.Hyperechoic)
  549. {
  550. EchoPatternDescri.Text = "高回声";
  551. resEcho = 1;
  552. }
  553. else if (echoCpp == (int)EchoPatternEnum.Isoechoic)
  554. {
  555. EchoPatternDescri.Text = "等回声";
  556. resEcho = 2;
  557. }
  558. else if (echoCpp == (int)EchoPatternEnum.Hypoechoic)
  559. {
  560. EchoPatternDescri.Text = "低回声";
  561. resEcho = 3;
  562. }
  563. else if (echoCpp == (int)EchoPatternEnum.HypoechoicLower)
  564. {
  565. EchoPatternDescri.Text = "极低回声";
  566. resEcho = 4;
  567. }
  568. if (shapeCpp == (int)ShapeEnum.WiderThanTall)
  569. {
  570. ShapeDescri.Text = "宽大于高";
  571. resShape = 0;
  572. }
  573. else if (shapeCpp == (int)ShapeEnum.TallThanWider)
  574. {
  575. ShapeDescri.Text = "高大于宽";
  576. resShape = 1;
  577. }
  578. if (marginCpp == (int)MarginEnum.Smooth)
  579. {
  580. MarginDescri.Text = "边缘光整";
  581. }
  582. else if (marginCpp == (int)MarginEnum.IllDefined)
  583. {
  584. MarginDescri.Text = "边缘模糊";
  585. }
  586. else if (marginCpp == (int)MarginEnum.Lobulated)
  587. {
  588. MarginDescri.Text = "边缘分叶状";
  589. }
  590. else if (marginCpp == (int)MarginEnum.Irregular)
  591. {
  592. MarginDescri.Text = "边缘不规则";
  593. }
  594. else if (marginCpp == (int)MarginEnum.ExtraThyroidalExtension)
  595. {
  596. MarginDescri.Text = "甲状腺外侵犯";
  597. }
  598. if (echogenicFociCpp == (int)EchogenicFociEnum.NoCifications)
  599. {
  600. EchogenicFociDescri.Text = "无钙化";
  601. resCa = 0;
  602. }
  603. else if (echogenicFociCpp == (int)EchogenicFociEnum.Coarsecalcifications)
  604. {
  605. EchogenicFociDescri.Text = "粗钙化";
  606. resCa = 1;
  607. }
  608. else if (echogenicFociCpp == (int)EchogenicFociEnum.Microcalcifications)
  609. {
  610. EchogenicFociDescri.Text = "微钙化";
  611. resCa = 2;
  612. }
  613. }
  614. //));
  615. //////////////
  616. string newPath = System.IO.Path.Combine(_currentBinPath, "result");
  617. //if (resCa == 0)
  618. //{
  619. // string nameSave = newPath + "\\00\\" + name + ".jpg";
  620. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  621. //}
  622. //else if (resCa == 1)
  623. //{
  624. // string nameSave = newPath + "\\01\\" + name + ".jpg";
  625. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  626. //}
  627. //else if (resCa == 2)
  628. //{
  629. // string nameSave = newPath + "\\02\\" + name + ".jpg";
  630. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  631. //}
  632. //if (resEcho == 0)
  633. //{
  634. // string nameSave = newPath + "\\00\\" + name + ".jpg";
  635. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  636. //}
  637. //else if (resEcho == 1)
  638. //{
  639. // string nameSave = newPath + "\\01\\" + name + ".jpg";
  640. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  641. //}
  642. //else if (resEcho == 2)
  643. //{
  644. // string nameSave = newPath + "\\02\\" + name + ".jpg";
  645. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  646. //}
  647. //else if (resEcho == 3)
  648. //{
  649. // string nameSave = newPath + "\\03\\" + name + ".jpg";
  650. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  651. //}
  652. //else if (resEcho == 4)
  653. //{
  654. // string nameSave = newPath + "\\04\\" + name + ".jpg";
  655. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  656. //}
  657. if (resShape == 0)
  658. {
  659. string nameSave = newPath + "\\00\\" + name + ".jpg";
  660. if (shapeCppGT == ShapeEnum.WiderThanTall)
  661. {
  662. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  663. }
  664. }
  665. else if (resShape == 1)
  666. {
  667. string nameSave = newPath + "\\01\\" + name + ".jpg";
  668. if (shapeCppGT == ShapeEnum.WiderThanTall)
  669. {
  670. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  671. }
  672. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  673. }
  674. if (echoFociGT == echoFoci)
  675. {
  676. if (echoFoci == EchogenicFociEnum.NoCifications)
  677. {
  678. _NoCifications_NoCifications_num++;
  679. //result = 1;
  680. }
  681. if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
  682. {
  683. _Coarsecalcifications_Coarsecalcifications_num++;
  684. //result = 2;
  685. }
  686. if (echoFoci == EchogenicFociEnum.Microcalcifications)
  687. {
  688. _Macrocalcifications_Macrocalcifications_num++;
  689. //result = 3;
  690. }
  691. }
  692. else
  693. {
  694. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  695. {
  696. _NoCifications_Coarsecalcifications_num++;
  697. //result = 4;
  698. }
  699. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  700. {
  701. _NoCifications_Macrocalcifications_num++;
  702. //result = 5;
  703. }
  704. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  705. {
  706. _Coarsecalcifications_NoCifications_num++;
  707. //result = 6;
  708. }
  709. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  710. {
  711. _Coarsecalcifications_Macrocalcifications_num++;
  712. //result = 7;
  713. }
  714. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  715. {
  716. _Macrocalcifications_NoCifications_num++;
  717. //result = 8;
  718. }
  719. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  720. {
  721. _Macrocalcifications_Coarsecalcifications_num++;
  722. //result = 9;
  723. }
  724. }
  725. if (echoGT == echo)
  726. {
  727. if (echo == EchoPatternEnum.Anechoic)
  728. {
  729. _Anechoic_Anechoi_num++;
  730. }
  731. if (echo == EchoPatternEnum.Hyperechoic)
  732. {
  733. _Hyperechoic_Hyperechoic_num++;
  734. }
  735. if (echo == EchoPatternEnum.Isoechoic)
  736. {
  737. _Isoechoic_Isoechoic_num++;
  738. }
  739. if (echo == EchoPatternEnum.Hypoechoic)
  740. {
  741. _Hypoechoic_Hypoechoic_num++;
  742. }
  743. if (echo == EchoPatternEnum.HypoechoicLower)
  744. {
  745. _HypoechoicLower_HypoechoicLower_num++;
  746. }
  747. }
  748. else
  749. {
  750. //把无回声判为其它
  751. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
  752. {
  753. _Anechoic_Hyperechoic_num++;
  754. }
  755. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
  756. {
  757. _Anechoic_Isoechoic_num++;
  758. }
  759. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
  760. {
  761. _Anechoic_Hypoechoic_num++;
  762. }
  763. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
  764. {
  765. _Anechoic_HypoechoicLower_num++;
  766. }
  767. //把高回声判为其它
  768. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
  769. {
  770. _Hyperechoic_Anechoic_num++;
  771. }
  772. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
  773. {
  774. _Hyperechoic_Isoechoic_num++;
  775. }
  776. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
  777. {
  778. _Hyperechoic_Hypoechoic_num++;
  779. }
  780. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
  781. {
  782. _Hyperechoic_HypoechoicLower_num++;
  783. }
  784. //把等回声判为其它
  785. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
  786. {
  787. _Isoechoic_Anechoic_num++;
  788. }
  789. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
  790. {
  791. _Isoechoic_Hyperechoic_num++;
  792. }
  793. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
  794. {
  795. _Isoechoic_Hypoechoic_num++;
  796. }
  797. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
  798. {
  799. _Isoechoic_HypoechoicLower_num++;
  800. }
  801. //低回声判为其它
  802. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
  803. {
  804. _Hypoechoic_Anechoic_num++;
  805. }
  806. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
  807. {
  808. _Hypoechoic_Hyperechoic_num++;
  809. }
  810. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
  811. {
  812. _Hypoechoic_Isoechoic_num++;
  813. }
  814. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
  815. {
  816. _Hypoechoic_HypoechoicLower_num++;
  817. }
  818. //极低回声判为其它
  819. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
  820. {
  821. _HypoechoicLower_Anechoicr_num++;
  822. }
  823. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
  824. {
  825. _HypoechoicLower_Hyperechoic_num++;
  826. }
  827. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
  828. {
  829. _HypoechoicLower_Isoechoic_num++;
  830. }
  831. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
  832. {
  833. _HypoechoicLower_Hypoechoic_num++;
  834. }
  835. }
  836. if (shapeCppGT == shape)
  837. {
  838. if (shape == ShapeEnum.WiderThanTall)
  839. {
  840. _WT_WT_num++;
  841. }
  842. if (shape == ShapeEnum.TallThanWider)
  843. {
  844. _TW_TW_num++;
  845. }
  846. }
  847. else
  848. {
  849. //把 宽大于高 判为 高大于宽
  850. if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
  851. {
  852. _WT_TW_num++;
  853. }
  854. if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
  855. {
  856. _TW_WT_num++;
  857. }
  858. }
  859. if (marginGT == margin)
  860. {
  861. if (margin == MarginEnum.Smooth)
  862. {
  863. _Smooth_Smooth_num++;
  864. }
  865. if (margin == MarginEnum.IllDefined)
  866. {
  867. _IllDefined_IllDefined_num++;
  868. }
  869. if (margin == MarginEnum.Lobulated)
  870. {
  871. _Lobulated_Lobulated_num++;
  872. }
  873. if (margin == MarginEnum.Irregular)
  874. {
  875. _Irregular_Irregular_num++;
  876. }
  877. if (margin == MarginEnum.ExtraThyroidalExtension)
  878. {
  879. _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
  880. }
  881. }
  882. else
  883. {
  884. //把 边缘光整 判成其它
  885. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
  886. {
  887. _Smooth_IllDefined_num++;
  888. }
  889. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
  890. {
  891. _Smooth_Lobulated_num++;
  892. }
  893. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
  894. {
  895. _Smooth_Irregular_num++;
  896. }
  897. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
  898. {
  899. _Smooth_ExtraThyroidalExtension_num++;
  900. }
  901. //把 边缘模糊 判成其它
  902. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
  903. {
  904. _IllDefined_Smooth_num++;
  905. }
  906. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
  907. {
  908. _IllDefined_Lobulated_num++;
  909. }
  910. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
  911. {
  912. _IllDefined_Irregular_num++;
  913. }
  914. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
  915. {
  916. _IllDefined_ExtraThyroidalExtension_num++;
  917. }
  918. //把 边缘分叶状 判成其它
  919. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
  920. {
  921. _Lobulated_Smooth_num++;
  922. }
  923. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
  924. {
  925. _Lobulated_IllDefined_num++;
  926. }
  927. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
  928. {
  929. _Lobulated_Irregular_num++;
  930. }
  931. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
  932. {
  933. _Lobulated_ExtraThyroidalExtension_num++;
  934. }
  935. //把 边缘不规则 判成其它
  936. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
  937. {
  938. _Irregular_Smooth_num++;
  939. }
  940. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
  941. {
  942. _Irregular_IllDefined_num++;
  943. }
  944. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
  945. {
  946. _Irregular_Lobulated_num++;
  947. }
  948. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
  949. {
  950. _Irregular_ExtraThyroidalExtension_num++;
  951. }
  952. //把 甲状腺外侵犯 判成其它
  953. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
  954. {
  955. _ExtraThyroidalExtension_Smooth_num++;
  956. }
  957. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
  958. {
  959. _ExtraThyroidalExtension_IllDefined_num++;
  960. }
  961. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
  962. {
  963. _ExtraThyroidalExtension_Lobulated_num++;
  964. }
  965. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
  966. {
  967. _ExtraThyroidalExtension_Irregular_num++;
  968. }
  969. }
  970. using (var g = Graphics.FromImage(dstimage))
  971. {
  972. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  973. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
  974. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  975. if (lesionContour.Length > 0)
  976. {
  977. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  978. g.DrawLines(pen, lesionContour); //画病灶轮廓
  979. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  980. if (thyroidContour.Length > 0)
  981. {
  982. g.DrawLines(pen2, thyroidContour); //画肝脏轮廓
  983. }
  984. pen.Dispose();
  985. }
  986. //画轮廓的长短轴
  987. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  988. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  989. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  990. g.DrawLines(pen_v, axisV); //纵轴,红色
  991. g.Dispose();
  992. }
  993. }
  994. _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
  995. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  996. {
  997. DstImage.Source = _dstImg;
  998. }));
  999. dstimage.Dispose();
  1000. }
  1001. else
  1002. {
  1003. MessageBox.Show("未读取到病灶!");
  1004. }
  1005. }
  1006. public static int BitmapChannel(Bitmap image, bool keepChannel = false)
  1007. {
  1008. int width = image.Width;
  1009. int height = image.Height;
  1010. PixelFormat pixelFormat = image.PixelFormat;
  1011. if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
  1012. pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
  1013. pixelFormat != PixelFormat.Format8bppIndexed)
  1014. {
  1015. throw new Exception("Unexpected image pixel format:" + pixelFormat);
  1016. }
  1017. int origChannel = 3;
  1018. if (pixelFormat == PixelFormat.Format24bppRgb)
  1019. {
  1020. origChannel = 3;
  1021. }
  1022. else if (pixelFormat == PixelFormat.Format8bppIndexed)
  1023. {
  1024. origChannel = 1;
  1025. }
  1026. else
  1027. {
  1028. origChannel = 4;
  1029. }
  1030. int dstChannel = 3;
  1031. //if (keepChannel)
  1032. //{
  1033. // dstChannel = origChannel;
  1034. //}
  1035. dstChannel = origChannel;
  1036. return dstChannel;
  1037. }
  1038. /// <summary>
  1039. /// 将System.Drawimg.Bitmap转为RawImage
  1040. /// </summary>
  1041. /// <param name="image"></param>
  1042. /// <param name="keepChannel"></param>
  1043. /// <returns></returns>
  1044. public static RawImage BitmapToRawImage(Bitmap image, bool keepChannel = false)
  1045. {
  1046. int width = image.Width;
  1047. int height = image.Height;
  1048. PixelFormat pixelFormat = image.PixelFormat;
  1049. if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
  1050. pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
  1051. pixelFormat != PixelFormat.Format8bppIndexed)
  1052. {
  1053. throw new Exception("Unexpected image pixel format:" + pixelFormat);
  1054. }
  1055. int origChannel = 3;
  1056. if (pixelFormat == PixelFormat.Format24bppRgb)
  1057. {
  1058. origChannel = 3;
  1059. }
  1060. else if (pixelFormat == PixelFormat.Format8bppIndexed)
  1061. {
  1062. origChannel = 1;
  1063. }
  1064. else
  1065. {
  1066. origChannel = 4;
  1067. }
  1068. int dstChannel = 3;
  1069. if (keepChannel)
  1070. {
  1071. dstChannel = origChannel;
  1072. }
  1073. var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat);
  1074. byte[] dstDataArray = new byte[width * height * dstChannel];
  1075. unsafe
  1076. {
  1077. int stride = bmData.Stride;
  1078. int dstStride = width * dstChannel;
  1079. IntPtr ptr = bmData.Scan0;
  1080. IntPtr ptrH, ptrW;
  1081. for (int nh = 0; nh < height; nh++)
  1082. {
  1083. ptrH = IntPtr.Add(ptr, nh * stride);
  1084. if (origChannel == dstChannel)
  1085. {
  1086. Marshal.Copy(ptrH, dstDataArray, nh * dstStride, dstStride);
  1087. }
  1088. else if (origChannel > dstChannel)
  1089. {
  1090. for (int nw = 0; nw < width; nw++)
  1091. {
  1092. ptrW = IntPtr.Add(ptrH, nw * origChannel);
  1093. Marshal.Copy(ptrW, dstDataArray, nh * dstStride + nw * dstChannel, dstChannel);
  1094. }
  1095. }
  1096. else
  1097. {
  1098. for (int nw = 0; nw < width; nw++)
  1099. {
  1100. ptrW = IntPtr.Add(ptrH, nw * origChannel);
  1101. for (int nc = 0; nc < dstChannel; nc++)
  1102. {
  1103. Marshal.Copy(ptrW, dstDataArray, nh * dstStride + nw * dstChannel + nc, 1);
  1104. }
  1105. }
  1106. }
  1107. }
  1108. }
  1109. image.UnlockBits(bmData);
  1110. //return new RawImage(dstDataArray, width, height, dstChannel);
  1111. return new RawImage(dstDataArray, width, height, EnumColorType.Gray8);
  1112. }
  1113. //private RawImage AIBitmapToRawImage(Bitmap image)
  1114. //{
  1115. // int width = image.Width;
  1116. // int height = image.Height;
  1117. // AI.Common.Interface.EnumColorType ColorType = AI.Common.Interface.EnumColorType.Bgr;
  1118. // int channel = 3;
  1119. // PixelFormat pixelFormat = image.PixelFormat;
  1120. // if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
  1121. // pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
  1122. // pixelFormat != PixelFormat.Format8bppIndexed)
  1123. // {
  1124. // throw new Exception("Unexpected image pixel format:" + pixelFormat);
  1125. // }
  1126. // if (pixelFormat == PixelFormat.Format24bppRgb)
  1127. // {
  1128. // channel = 3;
  1129. // ColorType = AI.Common.Interface.EnumColorType.Bgr;
  1130. // }
  1131. // else if (pixelFormat == PixelFormat.Format8bppIndexed)
  1132. // {
  1133. // channel = 1;
  1134. // ColorType = AI.Common.Interface.EnumColorType.Gray8;
  1135. // }
  1136. // else
  1137. // {
  1138. // channel = 4;
  1139. // ColorType = AI.Common.Interface.EnumColorType.Bgra;
  1140. // }
  1141. // var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, pixelFormat);
  1142. // byte[] srcDataArray = new byte[bmData.Stride * height];
  1143. // byte[] dstDataArray = new byte[width * height * channel];
  1144. // System.Runtime.InteropServices.Marshal.Copy(bmData.Scan0, srcDataArray, 0, bmData.Stride * height);
  1145. // for (int nh = 0; nh < height; nh++)
  1146. // {
  1147. // Array.Copy(srcDataArray, nh * bmData.Stride, dstDataArray, nh * width * channel, width * channel);
  1148. // }
  1149. // image.UnlockBits(bmData);
  1150. // return RawImage(dstDataArray, width, height, ColorType);
  1151. //}
  1152. //private RawImage BitmapToRawImage(Bitmap image)
  1153. //{
  1154. // int width = image.Width;
  1155. // int height = image.Height;
  1156. // int channel = 3;
  1157. // PixelFormat pixelFormat = image.PixelFormat;
  1158. // if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
  1159. // pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
  1160. // pixelFormat != PixelFormat.Format8bppIndexed)
  1161. // {
  1162. // throw new Exception("Unexpected image pixel format:" + pixelFormat);
  1163. // }
  1164. // if (pixelFormat == PixelFormat.Format24bppRgb)
  1165. // {
  1166. // channel = 3;
  1167. // }
  1168. // else if (pixelFormat == PixelFormat.Format8bppIndexed)
  1169. // {
  1170. // channel = 1;
  1171. // }
  1172. // else
  1173. // {
  1174. // channel = 4;
  1175. // }
  1176. // var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, pixelFormat);
  1177. // byte[] srcDataArray = new byte[bmData.Stride * height];
  1178. // byte[] dstDataArray = new byte[width * height * channel];
  1179. // System.Runtime.InteropServices.Marshal.Copy(bmData.Scan0, srcDataArray, 0, bmData.Stride * height);
  1180. // for (int nh = 0; nh < height; nh++)
  1181. // {
  1182. // Array.Copy(srcDataArray, nh * bmData.Stride, dstDataArray, nh * width * channel, width * channel);
  1183. // }
  1184. // image.UnlockBits(bmData);
  1185. // return new RawImage(dstDataArray, width, height, channel);
  1186. //}
  1187. public void Save(Bitmap image, int imageId,string imageName)
  1188. {
  1189. _currentBinPath = System.Environment.CurrentDirectory;
  1190. string newPath = System.IO.Path.Combine(_currentBinPath, "result");
  1191. System.IO.Directory.CreateDirectory(newPath);
  1192. int imgNum = _allImgInfo.Count;
  1193. if (image == null || _allImgInfo.Count <= 0)
  1194. {
  1195. return;
  1196. }
  1197. // 显示甲状腺轮廓
  1198. List<MyPoint> thyroidCont = _allImgInfo[imageId].ThyroidContour;
  1199. int num1 = thyroidCont.Count;
  1200. int path = 0;
  1201. if (_allImgInfo[imageId].Lesions.Count <= 0)
  1202. {
  1203. string name = newPath + "\\" + imageName + ".png";
  1204. //image.Save(name, System.Drawing.Imaging.ImageFormat.Png);
  1205. }
  1206. else
  1207. {
  1208. int numLesions = _allImgInfo[imageId].Lesions.Count;
  1209. Bitmap origImg = image;
  1210. //int numLesions = _allImgInfo[imageId].Lesions.Count;
  1211. for (int jj = 0; jj < numLesions; jj++)
  1212. {
  1213. EchoPatternEnum echoGT = _allImgInfo[imageId].Lesions[jj].EchoPattern;
  1214. ShapeEnum shapeGT = _allImgInfo[imageId].Lesions[jj].Shape;
  1215. MarginEnum marginGT = _allImgInfo[imageId].Lesions[jj].Margin;
  1216. EchogenicFociEnum echogenicFociGT = _allImgInfo[imageId].Lesions[jj].EchogenicFoci;
  1217. string echo = null, shape = null, margin = null, echogenicFoci = null;
  1218. if (echoGT == EchoPatternEnum.Anechoic)
  1219. {
  1220. echo = "无回声";
  1221. path = 0;
  1222. }
  1223. else if (echoGT == EchoPatternEnum.Hyperechoic)
  1224. {
  1225. echo = "高回声";
  1226. path = 1;
  1227. }
  1228. else if (echoGT == EchoPatternEnum.Isoechoic)
  1229. {
  1230. echo = "等回声";
  1231. path = 2;
  1232. }
  1233. else if (echoGT == EchoPatternEnum.Hypoechoic)
  1234. {
  1235. echo = "低回声";
  1236. path = 3;
  1237. }
  1238. else if (echoGT == EchoPatternEnum.HypoechoicLower)
  1239. {
  1240. echo = "极低回声";
  1241. path = 4;
  1242. }
  1243. if (shapeGT == ShapeEnum.WiderThanTall)
  1244. {
  1245. shape = "宽大于高";
  1246. }
  1247. else if (shapeGT == ShapeEnum.TallThanWider)
  1248. {
  1249. shape = "高大于宽";
  1250. }
  1251. if (marginGT == MarginEnum.Smooth)
  1252. {
  1253. margin = "边缘光整";
  1254. }
  1255. else if (marginGT == MarginEnum.IllDefined)
  1256. {
  1257. margin = "边缘模糊";
  1258. }
  1259. else if (marginGT == MarginEnum.Lobulated)
  1260. {
  1261. margin = "边缘分叶状";
  1262. }
  1263. else if (marginGT == MarginEnum.Irregular)
  1264. {
  1265. margin = "边缘不规则";
  1266. }
  1267. else if (marginGT == MarginEnum.ExtraThyroidalExtension)
  1268. {
  1269. margin = "甲状腺外侵犯";
  1270. }
  1271. if (echogenicFociGT == EchogenicFociEnum.NoCifications)
  1272. {
  1273. echogenicFoci = "无钙化";
  1274. //path = 0;
  1275. }
  1276. else if (echogenicFociGT == EchogenicFociEnum.Coarsecalcifications)
  1277. {
  1278. echogenicFoci = "粗钙化";
  1279. //path = 1;
  1280. }
  1281. else if (echogenicFociGT == EchogenicFociEnum.Microcalcifications)
  1282. {
  1283. echogenicFoci = "微钙化";
  1284. //path = 2;
  1285. }
  1286. // 显示新的病灶
  1287. LesionInfo lesion = _allImgInfo[imageId].Lesions[jj];
  1288. int num2 = lesion.LesionContour.Count;
  1289. using (var g = Graphics.FromImage(origImg))
  1290. {
  1291. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  1292. //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
  1293. //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  1294. System.Drawing.PointF[] thyroidContour = new PointF[num1];
  1295. for (int i = 0; i < num1; i++)
  1296. {
  1297. thyroidContour[i].X = thyroidCont[i].X;
  1298. thyroidContour[i].Y = thyroidCont[i].Y;
  1299. }
  1300. System.Drawing.PointF[] lesionContour = new PointF[num2];
  1301. for (int i = 0; i < num2; i++)
  1302. {
  1303. lesionContour[i].X = _allImgInfo[imageId].Lesions[jj].LesionContour[i].X;
  1304. lesionContour[i].Y = _allImgInfo[imageId].Lesions[jj].LesionContour[i].Y;
  1305. }
  1306. if (num2 > 0)
  1307. {
  1308. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  1309. g.DrawLines(pen, lesionContour); //画病灶轮廓
  1310. pen.Dispose();
  1311. }
  1312. if (num1 > 0)
  1313. {
  1314. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  1315. g.DrawLines(pen2, thyroidContour); //画甲状腺轮廓
  1316. pen2.Dispose();
  1317. }
  1318. System.Drawing.PointF[] axisH = new PointF[2];
  1319. System.Drawing.PointF[] axisV = new PointF[2];
  1320. axisH[0].X = lesion.HorizontalPoint1.X;
  1321. axisH[0].Y = lesion.HorizontalPoint1.Y;
  1322. axisH[1].X = lesion.HorizontalPoint2.X;
  1323. axisH[1].Y = lesion.HorizontalPoint2.Y;
  1324. axisV[0].X = lesion.VerticalPoint1.X;
  1325. axisV[0].Y = lesion.VerticalPoint1.Y;
  1326. axisV[1].X = lesion.VerticalPoint2.X;
  1327. axisV[1].Y = lesion.VerticalPoint2.Y;
  1328. //画轮廓的长短轴
  1329. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  1330. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  1331. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  1332. g.DrawLines(pen_v, axisV); //纵轴,红色
  1333. //写汉字
  1334. Font drawFont = new Font("黑体", 24);
  1335. SolidBrush drawBrush = new SolidBrush(Color.GreenYellow);
  1336. float x = 10.0f;
  1337. float y = 0.0f + 20;
  1338. string drawText = echo;//
  1339. g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * 4 * jj);
  1340. drawText = shape;
  1341. g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 1));
  1342. drawText = margin;
  1343. g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 2));
  1344. drawText = echogenicFoci;
  1345. g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 3));
  1346. //
  1347. drawText = jj.ToString();
  1348. g.DrawString(drawText, drawFont, drawBrush, axisH[0].X, axisH[0].Y);
  1349. g.Dispose();
  1350. }
  1351. }
  1352. string name = newPath + "\\" + imageName + ".png";
  1353. origImg.Save(name, System.Drawing.Imaging.ImageFormat.Png);
  1354. origImg.Dispose();
  1355. }
  1356. }
  1357. /// <summary>
  1358. /// 将医生的标注结果保存
  1359. /// </summary>
  1360. /// <param name="sender"></param>
  1361. /// <param name="e"></param>
  1362. private void OnLoadImageClick(object sender, RoutedEventArgs e)
  1363. {
  1364. OpenFileDialog openFileDialog = new OpenFileDialog();
  1365. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1366. openFileDialog.Multiselect = true;
  1367. openFileDialog.Title = "选择一幅或多幅图像";
  1368. if (openFileDialog.ShowDialog() ?? false)
  1369. {
  1370. foreach (string filename in openFileDialog.FileNames)
  1371. {
  1372. Bitmap img = new Bitmap(filename);
  1373. string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
  1374. string temp;
  1375. int idx = filename.LastIndexOf("\\");
  1376. temp = filename.Substring(idx);
  1377. string[] strs1 = temp.Split('\\');
  1378. temp = strs1[1];
  1379. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1380. string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1381. string ImgId = strs2[0];
  1382. int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
  1383. int imageId = imgIdx;
  1384. //_showImg = img;
  1385. if(imageId >=0)
  1386. {
  1387. Save(img, imageId, ImgId);
  1388. }
  1389. }
  1390. }
  1391. }
  1392. /// <summary>
  1393. /// 将不同db文件复制到一个文件中(每个db文件中的图像可以选择,不需要db文件中全部图像)
  1394. /// 最后获得的db文件不用先生成,由当前函数生成
  1395. /// </summary>
  1396. /// <param name="sender"></param>
  1397. /// <param name="e"></param>
  1398. private void OnCreatDbClick(object sender, RoutedEventArgs e)
  1399. {
  1400. string dataFolder = System.Environment.CurrentDirectory;
  1401. _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
  1402. _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_datas.db");
  1403. if (_allImgInfo.Count <= 0)
  1404. {
  1405. MessageBox.Show("先加载数据库");
  1406. }
  1407. if (File.Exists(_dbPathChoose))
  1408. {
  1409. MessageBox.Show("数据库已存在");
  1410. return;
  1411. //throw new Exception("数据库已存在,请检查.");
  1412. }
  1413. else
  1414. {
  1415. DataBase db = new DataBase(_dbPathChoose);
  1416. db.CreateDataBase(); //创建一个新的数据库文件
  1417. }
  1418. OpenFileDialog openFileDialog = new OpenFileDialog();
  1419. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1420. openFileDialog.Multiselect = true;
  1421. openFileDialog.Title = "选择一幅或多幅图像";
  1422. if (openFileDialog.ShowDialog() ?? false)
  1423. {
  1424. foreach (string filename in openFileDialog.FileNames)
  1425. {
  1426. //Bitmap img = new Bitmap(filename);
  1427. string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
  1428. string temp;
  1429. int idx = filename.LastIndexOf("\\");
  1430. temp = filename.Substring(idx);
  1431. string[] strs1 = temp.Split('\\');
  1432. temp = strs1[1];
  1433. string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1434. string ImgId = strs2[0];
  1435. int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
  1436. int numLesions= _allImgInfo[imgIndex].Lesions.Count;
  1437. if (imgIndex >= 0 && numLesions > 0)
  1438. {
  1439. AddExistImage(ImgId);
  1440. ////AddNewImage(filename);
  1441. //////////////////
  1442. //int lesionsNum = _allImgInfo[imgIndex].Lesions.Count;
  1443. //List<LesionInfo> tmpLe = new List<LesionInfo>();
  1444. //LesionInfo tmp = new LesionInfo();
  1445. //tmpLe = _allImgInfo[imgIndex].Lesions;
  1446. //for (int jj = 0; jj < lesionsNum; jj++)
  1447. //{
  1448. // tmpLe[jj].HorizontalPoint1 = null;
  1449. // tmpLe[jj].HorizontalPoint2 = null;
  1450. // tmpLe[jj].VerticalPoint1 = null;
  1451. // tmpLe[jj].VerticalPoint2 = null;
  1452. // tmpLe[jj].EchoPattern = 0;
  1453. // tmpLe[jj].Shape = 0;
  1454. // tmpLe[jj].Margin = 0;
  1455. // tmpLe[jj].EchogenicFoci = 0;
  1456. //}
  1457. //SetLesions(ImgId, tmpLe);
  1458. ///////////////////////////////////
  1459. SetLesions(ImgId, _allImgInfo[imgIndex].Lesions);
  1460. SetThyroidContour(ImgId, _allImgInfo[imgIndex].ThyroidContour);
  1461. }
  1462. else
  1463. {
  1464. MessageBox.Show("Id未找到:" + ImgId);
  1465. }
  1466. }
  1467. }
  1468. }
  1469. private string ComputeHashCode(byte[] input)
  1470. {
  1471. MD5 md5 = MD5.Create();
  1472. byte[] hash = md5.ComputeHash(input);
  1473. StringBuilder sb = new StringBuilder();
  1474. foreach (var b in hash)
  1475. {
  1476. sb.Append(b.ToString("x2"));
  1477. }
  1478. string hashstr = sb.ToString();
  1479. sb.Clear();
  1480. return hashstr;
  1481. }
  1482. public void AddExistImage(string ImgId)
  1483. {
  1484. SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
  1485. dbCon.Open();
  1486. SQLiteCommand dbCmd;
  1487. SQLiteDataReader dbReader;
  1488. string hashCode = ImgId;///????
  1489. // 查找该图片是否已经存在
  1490. dbCmd = dbCon.CreateCommand();
  1491. dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
  1492. dbReader = dbCmd.ExecuteReader();
  1493. if (dbReader.HasRows)
  1494. {
  1495. dbReader.Close();
  1496. dbCmd.Dispose();
  1497. //continue;
  1498. return;
  1499. }
  1500. // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
  1501. //string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
  1502. //File.Copy(origImagePath, imgdstPath);
  1503. // 将该图相关信息存到数据库里
  1504. List<LesionInfo> lesions = new List<LesionInfo>();
  1505. string strLesions = JsonConvert.SerializeObject(lesions);
  1506. List<MyPoint> thyroidContour = new List<MyPoint>();
  1507. string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
  1508. dbCmd = dbCon.CreateCommand();
  1509. //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
  1510. dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
  1511. dbCmd.ExecuteNonQuery();
  1512. dbCmd.Dispose();
  1513. ///
  1514. dbCon.Close();
  1515. dbCon.Dispose();
  1516. }
  1517. public void AddNewImage(string origImagePath)
  1518. {
  1519. SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
  1520. dbCon.Open();
  1521. SQLiteCommand dbCmd;
  1522. SQLiteDataReader dbReader;
  1523. ///
  1524. Bitmap image = new Bitmap(origImagePath);
  1525. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
  1526. string hashCode = ComputeHashCode(rawImg.DataBuffer);
  1527. image.Dispose();
  1528. rawImg.Dispose();
  1529. // 查找该图片是否已经存在
  1530. dbCmd = dbCon.CreateCommand();
  1531. dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
  1532. dbReader = dbCmd.ExecuteReader();
  1533. if (dbReader.HasRows)
  1534. {
  1535. dbReader.Close();
  1536. dbCmd.Dispose();
  1537. //continue;
  1538. return;
  1539. }
  1540. // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
  1541. //string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
  1542. //File.Copy(origImagePath, imgdstPath);
  1543. // 将该图相关信息存到数据库里
  1544. List<LesionInfo> lesions = new List<LesionInfo>();
  1545. string strLesions = JsonConvert.SerializeObject(lesions);
  1546. List<MyPoint> thyroidContour = new List<MyPoint>();
  1547. string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
  1548. dbCmd = dbCon.CreateCommand();
  1549. //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
  1550. dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
  1551. dbCmd.ExecuteNonQuery();
  1552. dbCmd.Dispose();
  1553. ///
  1554. dbCon.Close();
  1555. dbCon.Dispose();
  1556. }
  1557. /// 添加图像到数据集里
  1558. public void AddNewImages(string origImageFolder)
  1559. {
  1560. SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
  1561. dbCon.Open();
  1562. SQLiteCommand dbCmd;
  1563. SQLiteDataReader dbReader;
  1564. // 遍历该文件夹下所有图片
  1565. DirectoryInfo origImgDir = new DirectoryInfo(origImageFolder);
  1566. FileInfo[] files = origImgDir.GetFiles();
  1567. foreach (var file in files)
  1568. {
  1569. Bitmap image = new Bitmap(file.FullName);
  1570. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
  1571. string hashCode = ComputeHashCode(rawImg.DataBuffer);
  1572. image.Dispose();
  1573. rawImg.Dispose();
  1574. // 查找该图片是否已经存在
  1575. dbCmd = dbCon.CreateCommand();
  1576. dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
  1577. dbReader = dbCmd.ExecuteReader();
  1578. if (dbReader.HasRows)
  1579. {
  1580. dbReader.Close();
  1581. dbCmd.Dispose();
  1582. continue;
  1583. }
  1584. // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
  1585. string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
  1586. File.Copy(file.FullName, imgdstPath);
  1587. // 将该图相关信息存到数据库里
  1588. List<LesionInfo> lesions = new List<LesionInfo>();
  1589. string strLesions = JsonConvert.SerializeObject(lesions);
  1590. List<MyPoint> thyroidContour = new List<MyPoint>();
  1591. string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
  1592. dbCmd = dbCon.CreateCommand();
  1593. //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
  1594. dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
  1595. dbCmd.ExecuteNonQuery();
  1596. dbCmd.Dispose();
  1597. }
  1598. dbCon.Close();
  1599. dbCon.Dispose();
  1600. }
  1601. /// 设置该图像的病灶
  1602. public void SetLesions(string imgId, List<LesionInfo> lesions)
  1603. {
  1604. try
  1605. {
  1606. SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
  1607. dbCon.Open();
  1608. SQLiteCommand dbCmd;
  1609. dbCmd = dbCon.CreateCommand();
  1610. string strLesions = JsonConvert.SerializeObject(lesions);
  1611. dbCmd.CommandText = "update GTDatas set Lesions='" + strLesions + "' where ImageId='" + imgId + "'";
  1612. dbCmd.ExecuteNonQuery();
  1613. dbCmd.Dispose();
  1614. SQLiteDataReader dbreader;
  1615. dbCmd = dbCon.CreateCommand();
  1616. dbCmd.CommandText = "select * from LastModification";
  1617. dbreader = dbCmd.ExecuteReader();
  1618. if (dbreader.HasRows)
  1619. {
  1620. dbreader.Close();
  1621. dbCmd.Dispose();
  1622. // 更新
  1623. dbCmd = dbCon.CreateCommand();
  1624. dbCmd.CommandText = "update LastModification set ImageId='" + imgId + "'";
  1625. dbCmd.ExecuteNonQuery();
  1626. dbCmd.Dispose();
  1627. }
  1628. else
  1629. {
  1630. // 新增
  1631. dbCmd = dbCon.CreateCommand();
  1632. dbCmd.CommandText = "insert into LastModification(ImageId) select '" + imgId + "'";
  1633. dbCmd.ExecuteNonQuery();
  1634. dbCmd.Dispose();
  1635. }
  1636. dbCon.Close();
  1637. dbCon.Dispose();
  1638. }
  1639. catch (Exception excep)
  1640. {
  1641. MessageBox.Show("保存病灶结果时出错!" + excep);
  1642. }
  1643. }
  1644. public void SetThyroidContour(string imgId, List<MyPoint> thyroidContour)
  1645. {
  1646. try
  1647. {
  1648. SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
  1649. dbCon.Open();
  1650. SQLiteCommand dbCmd;
  1651. dbCmd = dbCon.CreateCommand();
  1652. string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
  1653. dbCmd.CommandText = "update GTDatas set ThyroidContour='" + strThyroidCont + "' where ImageId='" + imgId + "'";
  1654. dbCmd.ExecuteNonQuery();
  1655. dbCmd.Dispose();
  1656. SQLiteDataReader dbreader;
  1657. dbCmd = dbCon.CreateCommand();
  1658. dbCmd.CommandText = "select * from LastModification";
  1659. dbreader = dbCmd.ExecuteReader();
  1660. if (dbreader.HasRows)
  1661. {
  1662. dbreader.Close();
  1663. dbCmd.Dispose();
  1664. // 更新
  1665. dbCmd = dbCon.CreateCommand();
  1666. dbCmd.CommandText = "update LastModification set ImageId='" + imgId + "'";
  1667. dbCmd.ExecuteNonQuery();
  1668. dbCmd.Dispose();
  1669. }
  1670. else
  1671. {
  1672. // 新增
  1673. dbCmd = dbCon.CreateCommand();
  1674. dbCmd.CommandText = "insert into LastModification(ImageId) select '" + imgId + "'";
  1675. dbCmd.ExecuteNonQuery();
  1676. dbCmd.Dispose();
  1677. }
  1678. dbCon.Close();
  1679. dbCon.Dispose();
  1680. }
  1681. catch (Exception excep)
  1682. {
  1683. MessageBox.Show("保存甲状腺轮廓时出错!" + excep);
  1684. }
  1685. }
  1686. private void OnLoadOneImagesClick(object sender, RoutedEventArgs e)
  1687. {
  1688. OpenFileDialog openFileDialog = new OpenFileDialog();
  1689. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1690. openFileDialog.Multiselect = true;
  1691. openFileDialog.Title = "选择一幅或多幅图像";
  1692. if (openFileDialog.ShowDialog() ?? false)
  1693. {
  1694. foreach (string filename in openFileDialog.FileNames)
  1695. {
  1696. Bitmap img = new Bitmap(filename);
  1697. _currentImg = img;
  1698. string temp;
  1699. int idx = filename.LastIndexOf("\\");
  1700. temp = filename.Substring(idx);
  1701. string[] strs1 = temp.Split('\\');
  1702. temp = strs1[1];
  1703. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1704. //string ImgId = strs2[0];
  1705. string[] sArray = null;
  1706. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1707. string ImgId = sArray[0];
  1708. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  1709. _currentImgId = ImgId;
  1710. int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
  1711. if (imgIdx < 0)
  1712. {
  1713. //return;
  1714. continue;
  1715. }else
  1716. {
  1717. _currentImgIdex = imgIdx;
  1718. DoDescriAlgorithm(ImgId);
  1719. }
  1720. }
  1721. }
  1722. Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
  1723. Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
  1724. Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
  1725. Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
  1726. Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
  1727. Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
  1728. Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
  1729. Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
  1730. Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
  1731. Console.WriteLine();
  1732. Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
  1733. Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
  1734. Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
  1735. Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
  1736. Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
  1737. Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
  1738. Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
  1739. Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
  1740. Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
  1741. Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
  1742. Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
  1743. Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
  1744. Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
  1745. Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
  1746. Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
  1747. Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
  1748. Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
  1749. Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
  1750. Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
  1751. Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
  1752. Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
  1753. Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
  1754. Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
  1755. Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
  1756. Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
  1757. Console.WriteLine();
  1758. Console.WriteLine("形状: ");
  1759. Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
  1760. Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
  1761. Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
  1762. Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
  1763. Console.WriteLine();
  1764. Console.WriteLine("边缘: ");
  1765. Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
  1766. Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
  1767. Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
  1768. Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
  1769. Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
  1770. Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
  1771. Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
  1772. Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
  1773. Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
  1774. Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
  1775. Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
  1776. Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
  1777. Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
  1778. Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
  1779. Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
  1780. Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
  1781. Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
  1782. Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
  1783. Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
  1784. Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
  1785. Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
  1786. Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
  1787. Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
  1788. Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
  1789. Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
  1790. Console.WriteLine();
  1791. }
  1792. /// <summary>
  1793. /// 将文本写入txt文件中
  1794. /// </summary>
  1795. /// <param name="DirPath">文件路径</param>
  1796. /// <param name="FileName">文件名称</param>
  1797. /// <param name="Strs">字符串</param>
  1798. /// <param name="IsCleanFile">是否先清空文件</param>
  1799. public void WriteTxtToFile(string DirPath, string FileName, string Strs, bool IsCleanFile = false)
  1800. {
  1801. if (string.IsNullOrEmpty(Strs))
  1802. return;
  1803. if (!Directory.Exists(DirPath)) //如果不存在就创建file文件夹
  1804. {
  1805. Directory.CreateDirectory(DirPath);
  1806. }
  1807. FileStream fs = new FileStream((DirPath + FileName), FileMode.OpenOrCreate, FileAccess.Write);
  1808. StreamWriter sw = new StreamWriter(fs);
  1809. fs.Position = fs.Length;
  1810. sw.WriteLine(Strs); //写入字符串
  1811. sw.Close();
  1812. fs.Close();
  1813. }
  1814. /// <summary>
  1815. /// 图像的Id(图像名)在创建db文件时被改变,找到对应的图像,保存新db文件时用旧图像名作为ID
  1816. /// </summary>
  1817. /// <param name="sender"></param>
  1818. /// <param name="e"></param>
  1819. private void OnLoadNameChangeClick(object sender, RoutedEventArgs e)
  1820. {
  1821. string dataFolder = System.Environment.CurrentDirectory;
  1822. _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
  1823. _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_datas.db");
  1824. if (File.Exists(_dbPathChoose))
  1825. {
  1826. MessageBox.Show("数据库已存在");
  1827. return;
  1828. //throw new Exception("数据库已存在,请检查.");
  1829. }
  1830. else
  1831. {
  1832. DataBase db = new DataBase(_dbPathChoose);
  1833. db.CreateDataBase(); //创建一个新的数据库文件
  1834. }
  1835. OpenFileDialog openFileDialog = new OpenFileDialog();
  1836. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  1837. openFileDialog.Multiselect = true;
  1838. openFileDialog.Title = "选择一幅或多幅图像";
  1839. if (openFileDialog.ShowDialog() ?? false)
  1840. {
  1841. foreach (string filename in openFileDialog.FileNames)
  1842. {
  1843. string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
  1844. string temp;
  1845. int idx = filename.LastIndexOf("\\");
  1846. temp = filename.Substring(idx);
  1847. string[] strs1 = temp.Split('\\');
  1848. temp = strs1[1];
  1849. //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  1850. string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  1851. string ImgId = strs2[0];
  1852. int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
  1853. if (imgIndex >= 0)
  1854. {
  1855. //AddExistImage(ImgId);
  1856. //SetLesions(ImgId, _allImgInfo[imgIndex].Lesions);
  1857. //SetThyroidContour(ImgId, _allImgInfo[imgIndex].ThyroidContour);
  1858. MessageBox.Show("Id未改变:"+ ImgId);
  1859. }
  1860. else
  1861. {
  1862. Bitmap image = new Bitmap(filename);
  1863. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
  1864. string hashCode = ComputeHashCode(rawImg.DataBuffer);//生成hashCode,根据hashCode找到对应的描述
  1865. int imgIndexNew = _allImgInfo.FindIndex(x => x.ImageId == hashCode);
  1866. if (imgIndexNew >= 0)
  1867. {
  1868. AddExistImage(ImgId);
  1869. SetLesions(ImgId, _allImgInfo[imgIndexNew].Lesions);
  1870. SetThyroidContour(ImgId, _allImgInfo[imgIndexNew].ThyroidContour);
  1871. }
  1872. image.Dispose();
  1873. rawImg.Dispose();
  1874. }
  1875. }
  1876. }
  1877. }
  1878. /// <summary>
  1879. /// 合并几个db文件,但只保留之前db文件中的甲状腺和病灶的轮廓
  1880. /// 第一个选中的db文件要先生成一个基本版(只有所有数据的名称信息,防止出现新数据)。
  1881. /// 甲状腺和病灶轮廓存储在第一个db文件中
  1882. /// </summary>
  1883. /// <param name="sender"></param>
  1884. /// <param name="e"></param>
  1885. private void OnDBClick(object sender, RoutedEventArgs e)
  1886. {
  1887. string dataFolder = System.Environment.CurrentDirectory;
  1888. //_imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
  1889. //_dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_des_gt_datas.db");
  1890. OpenFileDialog openFileDialog = new OpenFileDialog();
  1891. openFileDialog.Filter = "数据库文件|*.db";
  1892. openFileDialog.Multiselect = false;
  1893. openFileDialog.Title = "选择一个母版数据库文件";
  1894. string dbPath = "";
  1895. if (openFileDialog.ShowDialog() ?? false)
  1896. {
  1897. _dbPathChoose = openFileDialog.FileName;
  1898. }
  1899. DataBase dataBase = new DataBase(_dbPathChoose);
  1900. bool readDb = dataBase.ReadDataBase();
  1901. if (readDb)
  1902. {
  1903. _allImgInfo = dataBase._allImages;
  1904. if (_allImgInfo.Count > 0)
  1905. {
  1906. MessageBox.Show("加载成功!");
  1907. }
  1908. }
  1909. else
  1910. {
  1911. MessageBox.Show("读取失败!");
  1912. }
  1913. List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
  1914. OpenFileDialog openFileDialog2 = new OpenFileDialog();
  1915. openFileDialog2.Filter = "数据库文件|*.db";
  1916. openFileDialog2.Multiselect = false;
  1917. openFileDialog2.Title = "选择一个被复制数据库文件";
  1918. string dbPath2 = "";
  1919. if (openFileDialog2.ShowDialog() ?? false)
  1920. {
  1921. dbPath = openFileDialog2.FileName;
  1922. }
  1923. DataBase dataBase2 = new DataBase(dbPath);
  1924. bool readDb2 = dataBase2.ReadDataBase();
  1925. if (readDb2)
  1926. {
  1927. allImgInfo2 = dataBase2._allImages;
  1928. if (allImgInfo2.Count > 0)
  1929. {
  1930. MessageBox.Show("加载成功!");
  1931. }
  1932. }
  1933. else
  1934. {
  1935. MessageBox.Show("读取失败!");
  1936. }
  1937. int num = allImgInfo2.Count;
  1938. for(int ii = 0;ii < num; ii++)
  1939. {
  1940. string imgID = allImgInfo2[ii].ImageId;
  1941. int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == imgID);
  1942. if (imgIndex >= 0)
  1943. {
  1944. AddExistImage(imgID);
  1945. int lesionsNum = allImgInfo2[ii].Lesions.Count;
  1946. List<LesionInfo> tmpLe = new List<LesionInfo>();
  1947. LesionInfo tmp = new LesionInfo();
  1948. if(lesionsNum >1)
  1949. {
  1950. int a = 0;
  1951. a++;
  1952. }
  1953. tmpLe = allImgInfo2[ii].Lesions;
  1954. for (int jj = 0; jj < lesionsNum; jj++)
  1955. {
  1956. //tmpLe[jj].HorizontalPoint1 = _allImgInfo[imgIndex].Lesions[jj].HorizontalPoint1;
  1957. //tmpLe[jj].HorizontalPoint2 = _allImgInfo[imgIndex].Lesions[jj].HorizontalPoint2; ;
  1958. //tmpLe[jj].VerticalPoint1 = _allImgInfo[imgIndex].Lesions[jj].VerticalPoint1; ;
  1959. //tmpLe[jj].VerticalPoint2 = _allImgInfo[imgIndex].Lesions[jj].VerticalPoint2; ;
  1960. //tmpLe[jj].HorizontalPoint1 = null;
  1961. //tmpLe[jj].HorizontalPoint2 = null;
  1962. //tmpLe[jj].VerticalPoint1 = null;
  1963. //tmpLe[jj].VerticalPoint2 = null;
  1964. //tmpLe[jj].EchoPattern = 0;
  1965. //tmpLe[jj].Shape = 0;
  1966. //tmpLe[jj].Margin = 0;
  1967. //tmpLe[jj].EchogenicFoci = 0;
  1968. }
  1969. ///////////////
  1970. //SetLesions(imgID, tmpLe);
  1971. SetThyroidContour(imgID, allImgInfo2[ii].ThyroidContour);
  1972. //MessageBox.Show("Id未改变:" + ImgId);
  1973. }
  1974. else
  1975. {
  1976. }
  1977. }
  1978. }
  1979. /// <summary>
  1980. /// 三份db文件比较,甲状腺病灶四个属性依次比较,根据实际需求保存数据
  1981. /// </summary>
  1982. /// <param name="sender"></param>
  1983. /// <param name="e"></param>
  1984. private void OnDBCompareClick(object sender, RoutedEventArgs e)
  1985. {
  1986. string dataFolder = System.Environment.CurrentDirectory;
  1987. string imagePath = System.IO.Path.Combine(dataFolder, "result\\all");
  1988. OpenFileDialog openFileDialog = new OpenFileDialog();
  1989. openFileDialog.Filter = "数据库文件|*.db";
  1990. openFileDialog.Multiselect = false;
  1991. openFileDialog.Title = "选择一个母版数据库文件";
  1992. string dbPath = "";
  1993. if (openFileDialog.ShowDialog() ?? false)
  1994. {
  1995. _dbPathChoose = openFileDialog.FileName;
  1996. }
  1997. DataBase dataBase = new DataBase(_dbPathChoose);
  1998. bool readDb = dataBase.ReadDataBase();
  1999. if (readDb)
  2000. {
  2001. _allImgInfo = dataBase._allImages;
  2002. if (_allImgInfo.Count > 0)
  2003. {
  2004. MessageBox.Show("加载成功!");
  2005. }
  2006. }
  2007. else
  2008. {
  2009. MessageBox.Show("读取失败!");
  2010. }
  2011. List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
  2012. OpenFileDialog openFileDialog2 = new OpenFileDialog();
  2013. openFileDialog2.Filter = "数据库文件|*.db";
  2014. openFileDialog2.Multiselect = false;
  2015. openFileDialog2.Title = "选择一个被复制数据库文件";
  2016. string dbPath2 = "";
  2017. if (openFileDialog2.ShowDialog() ?? false)
  2018. {
  2019. dbPath = openFileDialog2.FileName;
  2020. }
  2021. DataBase dataBase2 = new DataBase(dbPath);
  2022. bool readDb2 = dataBase2.ReadDataBase();
  2023. if (readDb2)
  2024. {
  2025. allImgInfo2 = dataBase2._allImages;
  2026. if (allImgInfo2.Count > 0)
  2027. {
  2028. MessageBox.Show("加载成功!");
  2029. }
  2030. }
  2031. else
  2032. {
  2033. MessageBox.Show("读取失败!");
  2034. }
  2035. ///////////////////
  2036. List<GTImgInfo> allImgInfo3 = new List<GTImgInfo>();
  2037. OpenFileDialog openFileDialog3 = new OpenFileDialog();
  2038. openFileDialog3.Filter = "数据库文件|*.db";
  2039. openFileDialog3.Multiselect = false;
  2040. openFileDialog3.Title = "选择一个被复制数据库文件";
  2041. string dbPath3 = "";
  2042. if (openFileDialog3.ShowDialog() ?? false)
  2043. {
  2044. dbPath = openFileDialog3.FileName;
  2045. }
  2046. DataBase dataBase3 = new DataBase(dbPath);
  2047. bool readDb3 = dataBase3.ReadDataBase();
  2048. if (readDb3)
  2049. {
  2050. allImgInfo3 = dataBase3._allImages;
  2051. if (allImgInfo3.Count > 0)
  2052. {
  2053. MessageBox.Show("加载成功!");
  2054. }
  2055. }
  2056. else
  2057. {
  2058. MessageBox.Show("读取失败!");
  2059. }
  2060. ///////////////
  2061. int num = _allImgInfo.Count;
  2062. int num2 = allImgInfo2.Count;
  2063. int num3 = allImgInfo3.Count;
  2064. if (!((num == num2) && (num == num3)))
  2065. {
  2066. MessageBox.Show("数据出错!");
  2067. return;
  2068. }
  2069. int[,] XLecho = new int[6, 6];
  2070. int[,] XYecho = new int[6, 6];
  2071. int[,] LYecho = new int[6, 6];
  2072. int[,] XLShape = new int[6, 6];
  2073. int[,] XYShape = new int[6, 6];
  2074. int[,] LYShape = new int[6, 6];
  2075. int[,] XLmargin = new int[6, 6];
  2076. int[,] XYmargin = new int[6, 6];
  2077. int[,] LYmargin = new int[6, 6];
  2078. int[,] XLechogenic = new int[6, 6];
  2079. int[,] XYechogenic = new int[6, 6];
  2080. int[,] LYechogenic = new int[6, 6];
  2081. for (int ii = 0; ii < num; ii++)
  2082. {
  2083. string imgID = allImgInfo2[ii].ImageId;
  2084. int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == imgID);
  2085. int lesionsNum1 = _allImgInfo[ii].Lesions.Count;
  2086. int lesionsNum2 = allImgInfo2[ii].Lesions.Count;
  2087. int lesionsNum3 = allImgInfo3[ii].Lesions.Count;
  2088. if (!((lesionsNum1 == lesionsNum2) && (lesionsNum1 == lesionsNum3) && (lesionsNum2 == lesionsNum3)))
  2089. {
  2090. WriteTxtToFile("E:\\image\\", "lesionsNum.txt", imgID, false);
  2091. int sum = lesionsNum3 + lesionsNum2 + lesionsNum1;
  2092. if (sum > 0)
  2093. {
  2094. string imageName = imagePath + "\\" + imgID + ".jpg";
  2095. Bitmap bmp = new Bitmap(imageName);
  2096. string savePath = imagePath + "\\have\\" + imgID + ".jpg";
  2097. //bmp.Save(savePath);
  2098. }
  2099. continue;
  2100. }
  2101. else
  2102. {
  2103. }
  2104. int numThy1 = (int)_allImgInfo[ii].ThyroidContour.Count;
  2105. int numThy2 = (int)allImgInfo2[ii].ThyroidContour.Count;
  2106. int numThy3 = (int)allImgInfo3[ii].ThyroidContour.Count;
  2107. if (!((numThy1 == numThy2) && (numThy1 == numThy3) && (numThy2 == numThy3)))
  2108. {
  2109. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2110. //Bitmap bmp = new Bitmap(imageName);
  2111. //string savePath = imagePath + "\\thynum\\" + imgID + ".jpg";
  2112. //bmp.Save(savePath);
  2113. }
  2114. bool becho = true;
  2115. bool bShape = true;
  2116. bool bMargin = true;
  2117. bool bEchogenicFoci = true;
  2118. for (int jj = 0; jj < lesionsNum1; jj++)
  2119. {
  2120. string imageName = imagePath + "\\" + imgID + ".jpg";
  2121. Bitmap bmp = new Bitmap(imageName);
  2122. int numLes1 = (int)_allImgInfo[ii].Lesions[jj].LesionContour.Count;
  2123. int numLes2 = (int)allImgInfo2[ii].Lesions[jj].LesionContour.Count;
  2124. int numLes3 = (int)allImgInfo3[ii].Lesions[jj].LesionContour.Count;
  2125. if (!((numLes1 == numLes2) && (numLes1 == numLes3) && (numLes2 == numLes3)))
  2126. {
  2127. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2128. //Bitmap bmp = new Bitmap(imageName);
  2129. //string savePath = imagePath + "\\lesnum\\" + imgID + ".jpg";
  2130. //bmp.Save(savePath);
  2131. }
  2132. var Echo1 = (int)_allImgInfo[ii].Lesions[jj].EchoPattern;
  2133. var Echo2 = (int)allImgInfo2[ii].Lesions[jj].EchoPattern;
  2134. var Echo3 = (int)allImgInfo3[ii].Lesions[jj].EchoPattern;
  2135. XLecho[Echo3, Echo1] += 1;
  2136. XYecho[Echo3, Echo2] += 1;
  2137. LYecho[Echo1, Echo2] += 1;
  2138. string resultStr = imgID + "," + Echo1.ToString() + "," + Echo2.ToString() + "," + Echo3.ToString();
  2139. if (!((Echo1 == Echo2) && (Echo1 == Echo3) && (Echo2 == Echo3)))
  2140. {
  2141. //WriteTxtToFile("E:\\image\\", "EchoDiff.txt", resultStr, false);
  2142. //becho = false;
  2143. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2144. //Bitmap bmp = new Bitmap(imageName);
  2145. //string savePath = imagePath + "\\echo\\" + imgID + ".jpg";
  2146. //bmp.Save(savePath);
  2147. }
  2148. else
  2149. {
  2150. becho = true;
  2151. string savePath = imagePath + "\\EchoSmae\\" + imgID + ".jpg";
  2152. //bmp.Save(savePath);
  2153. }
  2154. //if(Echo1 == Echo2)
  2155. //{
  2156. // string savePath = imagePath + "\\12\\" + imgID + ".jpg";
  2157. // bmp.Save(savePath);
  2158. //}
  2159. //if (Echo1 == Echo3)
  2160. //{
  2161. // string savePath = imagePath + "\\13\\" + imgID + ".jpg";
  2162. // bmp.Save(savePath);
  2163. //}
  2164. //if (Echo2 == Echo3)
  2165. //{
  2166. // string savePath = imagePath + "\\23\\" + imgID + ".jpg";
  2167. // bmp.Save(savePath);
  2168. //}
  2169. var Shape1 = (int)_allImgInfo[ii].Lesions[jj].Shape;
  2170. var Shape2 = (int)allImgInfo2[ii].Lesions[jj].Shape;
  2171. var Shape3 = (int)allImgInfo3[ii].Lesions[jj].Shape;
  2172. XLShape[Shape3, Shape1] += 1;
  2173. XYShape[Shape3, Shape2] += 1;
  2174. LYShape[Shape1, Shape2] += 1;
  2175. string shapeStr = imgID + "," + Shape1.ToString() + "," + Shape2.ToString() + "," + Shape3.ToString();
  2176. if (!((Shape1 == Shape2) && (Shape1 == Shape3) && (Shape2 == Shape3)))
  2177. {
  2178. //WriteTxtToFile("E:\\image\\", "ShapeDiff.txt", shapeStr, false);
  2179. //bShape = false;
  2180. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2181. //Bitmap bmp = new Bitmap(imageName);
  2182. }
  2183. else
  2184. {
  2185. //string savePath = imagePath + "\\shape\\" + imgID + ".jpg";
  2186. //bmp.Save(savePath);
  2187. bShape = true;
  2188. }
  2189. var margin1 = (int)_allImgInfo[ii].Lesions[jj].Margin;
  2190. var margin2 = (int)allImgInfo2[ii].Lesions[jj].Margin;
  2191. var margin3 = (int)allImgInfo3[ii].Lesions[jj].Margin;
  2192. XLmargin[margin3, margin1] += 1;
  2193. XYmargin[margin3, margin2] += 1;
  2194. LYmargin[margin1, margin2] += 1;
  2195. string marginStr = imgID + "," + margin1.ToString() + "," + margin2.ToString() + "," + margin3.ToString();
  2196. if (!((margin1 == margin2) && (margin1 == margin3) && (margin2 == margin3)))
  2197. {
  2198. //WriteTxtToFile("E:\\image\\", "marginDiff.txt", marginStr, false);
  2199. //bMargin = false;
  2200. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2201. //Bitmap bmp = new Bitmap(imageName);
  2202. //string savePath = imagePath + "\\margin\\" + imgID + ".jpg";
  2203. //bmp.Save(savePath);
  2204. }
  2205. else
  2206. {
  2207. //string savePath = imagePath + "\\margin\\" + imgID + ".jpg";
  2208. //bmp.Save(savePath);
  2209. bMargin = true;
  2210. }
  2211. //边缘两个医生相同数据,分别保存
  2212. //if (margin1 == margin2 && margin1 != margin3)
  2213. //{
  2214. // string savePath = imagePath + "\\12\\" + imgID + ".jpg";
  2215. // bmp.Save(savePath);
  2216. //}
  2217. //if (margin1 == margin3 && margin1 != margin2)
  2218. //{
  2219. // string savePath = imagePath + "\\13\\" + imgID + ".jpg";
  2220. // bmp.Save(savePath);
  2221. //}
  2222. //if (margin2 == margin3 && margin1 != margin2)
  2223. //{
  2224. // string savePath = imagePath + "\\23\\" + imgID + ".jpg";
  2225. // bmp.Save(savePath);
  2226. //}
  2227. var echogenic1 = (int)(_allImgInfo[ii].Lesions[jj].EchogenicFoci);
  2228. var echogenic2 = (int)allImgInfo2[ii].Lesions[jj].EchogenicFoci;
  2229. var echogenic3 = (int)allImgInfo3[ii].Lesions[jj].EchogenicFoci;
  2230. if(echogenic1 <0|| echogenic2<0|| echogenic3<0)
  2231. {
  2232. continue;
  2233. }
  2234. XLechogenic[echogenic3, echogenic1] += 1;
  2235. XYechogenic[echogenic3, echogenic2] += 1;
  2236. LYechogenic[echogenic1, echogenic2] += 1;
  2237. string echogenicStr = imgID + "," + echogenic1.ToString() + "," + echogenic2.ToString() + "," + echogenic3.ToString();
  2238. if (!((echogenic1 == echogenic2) && (echogenic1 == echogenic3) && (echogenic2 == echogenic3)))
  2239. {
  2240. //WriteTxtToFile("E:\\image\\", "echogenicDiff.txt", echogenicStr, false);
  2241. //bEchogenicFoci = false;
  2242. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2243. //Bitmap bmp = new Bitmap(imageName);
  2244. //string savePath = imagePath + "\\echogenic\\" + imgID + ".jpg";
  2245. //bmp.Save(savePath);
  2246. }
  2247. else
  2248. {
  2249. bEchogenicFoci = true;
  2250. //string savePath = imagePath + "\\echogenicSmae\\" + imgID + ".jpg";
  2251. //bmp.Save(savePath);
  2252. }
  2253. //钙化相互之间不同数据,分别保存
  2254. //if (echogenic3 != echogenic1)
  2255. //{
  2256. // string savePath = imagePath + "\\11\\" + imgID + ".jpg";
  2257. // bmp.Save(savePath);
  2258. //}
  2259. //if (echogenic3 != echogenic2)
  2260. //{
  2261. // string savePath = imagePath + "\\22\\" + imgID + ".jpg";
  2262. // bmp.Save(savePath);
  2263. //}
  2264. //if (echogenic1 != echogenic2)
  2265. //{
  2266. // string savePath = imagePath + "\\33\\" + imgID + ".jpg";
  2267. // bmp.Save(savePath);
  2268. //}
  2269. if (becho && bShape && bMargin && bEchogenicFoci)
  2270. {
  2271. //string sameAllStr = imgID + "," + Echo1.ToString() + "," + Shape1.ToString() + "," + margin1.ToString() + "," + echogenic3.ToString();
  2272. //WriteTxtToFile("E:\\image\\", "Same.txt", sameAllStr, false);
  2273. //string imageName = imagePath + "\\" + imgID + ".jpg";
  2274. //Bitmap bmp = new Bitmap(imageName);
  2275. //string savePath = imagePath + "\\same\\" + imgID + ".jpg";
  2276. //bmp.Save(savePath);
  2277. }
  2278. }
  2279. if (imgIndex >= 0)
  2280. {
  2281. //AddExistImage(imgID);
  2282. //List<LesionInfo> tmpLe = new List<LesionInfo>();
  2283. //LesionInfo tmp = new LesionInfo();
  2284. //tmpLe = allImgInfo2[ii].Lesions;
  2285. //SetLesions(imgID, tmpLe);
  2286. //SetThyroidContour(imgID, allImgInfo2[ii].ThyroidContour);
  2287. }
  2288. }
  2289. string echoStr = XLecho[0,0].ToString() + "," + XLecho[0, 1].ToString() + "," + XLecho[0, 2].ToString() + "," + XLecho[0, 3].ToString() + "," + XLecho[0, 4].ToString()+ "," + XLecho[0, 5].ToString();
  2290. WriteTxtToFile("E:\\image\\", "Same.txt", echoStr, false);
  2291. string echoStrXL = "";
  2292. string echoStrXY = "";
  2293. string echoStrLY = "";
  2294. string ShapeStrXL = "";
  2295. string ShapeStrXY = "";
  2296. string ShapeStrLY = "";
  2297. string marginStrXL = "";
  2298. string marginStrXY = "";
  2299. string marginStrLY = "";
  2300. string echogenicStrXL = "";
  2301. string echogenicStrXY = "";
  2302. string echogenicStrLY = "";
  2303. for (int i = 0; i < 6; i++)
  2304. {
  2305. for (int j = 0; j < 6; j++)
  2306. {
  2307. echoStrXL += XLecho[i, j].ToString() + ",";
  2308. echoStrXY += XYecho[i, j].ToString() + ",";
  2309. echoStrLY += LYecho[i, j].ToString() + ",";
  2310. ShapeStrXL += XLShape[i, j].ToString() + ",";
  2311. ShapeStrXY += XYShape[i, j].ToString() + ",";
  2312. ShapeStrLY += LYShape[i, j].ToString() + ",";
  2313. marginStrXL += XLmargin[i, j].ToString() + ",";
  2314. marginStrXY += XYmargin[i, j].ToString() + ",";
  2315. marginStrLY += LYmargin[i, j].ToString() + ",";
  2316. echogenicStrXL += XLechogenic[i, j].ToString() + ",";
  2317. echogenicStrXY += XYechogenic[i, j].ToString() + ",";
  2318. echogenicStrLY += LYechogenic[i, j].ToString() + ",";
  2319. }
  2320. echoStrXL = echoStrXL + "\n";
  2321. echoStrXY = echoStrXY + "\n";
  2322. echoStrLY = echoStrLY + "\n";
  2323. ShapeStrXL = ShapeStrXL + "\n";
  2324. ShapeStrXY = ShapeStrXY + "\n";
  2325. ShapeStrLY = ShapeStrLY + "\n";
  2326. marginStrXL = marginStrXL + "\n";
  2327. marginStrXY = marginStrXY + "\n";
  2328. marginStrLY = marginStrLY + "\n";
  2329. echogenicStrXL = echogenicStrXL + "\n";
  2330. echogenicStrXY = echogenicStrXY + "\n";
  2331. echogenicStrLY = echogenicStrLY + "\n";
  2332. }
  2333. //WriteTxtToFile("E:\\image\\", "echoStrXL.csv", echoStrXL, false);
  2334. //WriteTxtToFile("E:\\image\\", "echoStrXY.csv", echoStrXY, false);
  2335. //WriteTxtToFile("E:\\image\\", "echoStrLY.csv", echoStrLY, false);
  2336. //WriteTxtToFile("E:\\image\\", "ShapeStrXL.csv", ShapeStrXL, false);
  2337. //WriteTxtToFile("E:\\image\\", "ShapeStrXY.csv", ShapeStrXY, false);
  2338. //WriteTxtToFile("E:\\image\\", "ShapeStrLY.csv", ShapeStrLY, false);
  2339. //WriteTxtToFile("E:\\image\\", "marginStrXL.csv", marginStrXL, false);
  2340. //WriteTxtToFile("E:\\image\\", "marginStrXY.csv", marginStrXY, false);
  2341. //WriteTxtToFile("E:\\image\\", "marginStrLY.csv", marginStrLY, false);
  2342. //WriteTxtToFile("E:\\image\\", "echogenicStrXL.csv", echogenicStrXL, false);
  2343. //WriteTxtToFile("E:\\image\\", "echogenicStrXY.csv", echogenicStrXY, false);
  2344. //WriteTxtToFile("E:\\image\\", "echogenicStrLY.csv", echogenicStrLY, false);
  2345. int a = 0;
  2346. a += 1;
  2347. }
  2348. /// <summary>
  2349. /// 发现标注工具中的保存结果和当前工程中的结果不对应,将结果整理好并保存到新的db文件中
  2350. /// </summary>
  2351. /// <param name="sender"></param>
  2352. /// <param name="e"></param>
  2353. private void OnDBClearClick(object sender, RoutedEventArgs e)
  2354. {
  2355. //video2image();
  2356. //return;
  2357. string dataFolder = System.Environment.CurrentDirectory;
  2358. _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
  2359. _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_clear_datas.db");
  2360. if (_allImgInfo.Count <= 0)
  2361. {
  2362. MessageBox.Show("先加载数据库");
  2363. }
  2364. if (File.Exists(_dbPathChoose))
  2365. {
  2366. MessageBox.Show("数据库已存在");
  2367. return;
  2368. //throw new Exception("数据库已存在,请检查.");
  2369. }
  2370. else
  2371. {
  2372. DataBase db = new DataBase(_dbPathChoose);
  2373. db.CreateDataBase(); //创建一个新的数据库文件
  2374. }
  2375. int num = _allImgInfo.Count;
  2376. for (int ii = 0; ii < num; ii++)
  2377. {
  2378. int numLesions = _allImgInfo[ii].Lesions.Count;
  2379. string imgId = _allImgInfo[ii].ImageId;
  2380. List<LesionInfo> lesionsNew = new List<LesionInfo>();
  2381. for (int jj = 0; jj < numLesions; jj++)
  2382. {
  2383. var lesions = _allImgInfo[ii].Lesions[jj];
  2384. int res = (int)lesions.EchogenicFoci;
  2385. var value1 = lesions.EchoPattern;
  2386. var value2 = lesions.EchogenicFoci;
  2387. var value3 = lesions.Margin;
  2388. var value4 = lesions.Shape;
  2389. LesionInfo tmp = new LesionInfo();
  2390. tmp.EchoPattern = (EchoPatternEnum)((int) value1 - 1);
  2391. tmp.EchogenicFoci = (EchogenicFociEnum)((int)value2 - 1);
  2392. tmp.Margin = (MarginEnum)((int)value3 - 1);
  2393. tmp.Shape = (ShapeEnum)((int)value4 - 1);
  2394. tmp.HorizontalPoint1 = lesions.HorizontalPoint1;
  2395. tmp.HorizontalPoint2 = lesions.HorizontalPoint2;
  2396. tmp.VerticalPoint1 = lesions.VerticalPoint1;
  2397. tmp.VerticalPoint2 = lesions.VerticalPoint2;
  2398. tmp.LesionContour = lesions.LesionContour;
  2399. lesionsNew.Add(tmp);
  2400. }
  2401. AddExistImage(imgId);
  2402. SetLesions(imgId, lesionsNew);
  2403. SetThyroidContour(imgId, _allImgInfo[ii].ThyroidContour);
  2404. }
  2405. }
  2406. private void OnDBLoadModel1(object sender, RoutedEventArgs e)
  2407. {
  2408. if(_UseNet != null)
  2409. {
  2410. _UseNet.Dispose();
  2411. _UseNet = null;
  2412. }
  2413. Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
  2414. {
  2415. Filter = "模型文件|*.emd",
  2416. Multiselect = false,
  2417. Title = "选择一个模型"
  2418. };
  2419. if (openFileDialog.ShowDialog() ?? false)
  2420. {
  2421. string fileName = openFileDialog.FileName;
  2422. string modelName = Path.GetFileName(fileName);
  2423. _netsDir = Path.GetDirectoryName(fileName);
  2424. _UseNet = new ProcessData();
  2425. _UseNet.OnLoadModel(_netsDir);
  2426. }
  2427. /////////////
  2428. //if (_inferNet != null)
  2429. //{
  2430. // _inferNet.Dispose();
  2431. // _inferNet = null;
  2432. //}
  2433. //Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
  2434. //{
  2435. // Filter = "模型文件|*.emd",
  2436. // Multiselect = false,_netsDir
  2437. // Title = "选择一个模型"
  2438. //};
  2439. //if (openFileDialog.ShowDialog() ?? false)
  2440. //{
  2441. // string fileName = openFileDialog.FileName;
  2442. // string modelName = Path.GetFileName(fileName);
  2443. // _netsDir = Path.GetDirectoryName(fileName);
  2444. // _inferNet = new DescriptionCoreDeeplearning();//DescriptionCoreDeeplearning DescriptionDeeplearning
  2445. // byte[] fileDataDecrypted = InferenceNetworkUtils.ReadNetworkDataFromFile(_netsDir, _inferNet.NetworkName, _inferNet.HashCode);
  2446. // _inferNet.LoadNetwork(_inferCore, _deviceType, fileDataDecrypted);
  2447. //}
  2448. }
  2449. private void OnDBModelPredict(object sender, RoutedEventArgs e)
  2450. {
  2451. if (_currentImg != null)
  2452. {
  2453. string name = "sos";
  2454. //DoDescriAlgorithm(name);
  2455. DoDescriAlgorithmModel(name);
  2456. }
  2457. else
  2458. {
  2459. MessageBox.Show("请先加载待测图像!");
  2460. }
  2461. }
  2462. //甲状腺描述算法调用接口
  2463. private int DoDescriAlgorithmModel(string name)
  2464. {
  2465. if (_currentImg == null)
  2466. {
  2467. MessageBox.Show("请先加载待测图像!");
  2468. return -1;
  2469. }
  2470. if(_UseNet == null)
  2471. {
  2472. MessageBox.Show("请先加载模型!");
  2473. return -1;
  2474. }
  2475. Bitmap bmp = _currentImg;
  2476. RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
  2477. int channel = BitmapChannel(bmp);
  2478. roiCoor roi;
  2479. roi.x = 0;
  2480. roi.y = 0;
  2481. roi.width = _currentImg.Width;
  2482. roi.height = _currentImg.Height;
  2483. int modelInputW = 320;
  2484. int modelInputH = 320;
  2485. int modelInputC = 4;
  2486. int modelOutputW = 320;
  2487. int modelOutputH = 320;
  2488. int modelOutputC = 2;
  2489. int result = 0;
  2490. int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
  2491. int ThyroidNum = _allImgInfo[_currentImgIdex].ThyroidContour.Count;
  2492. //确定存在病灶
  2493. if (LesionsNum > 0 && ThyroidNum > 0)
  2494. {
  2495. Bitmap dstimage = (Bitmap)_currentImg.Clone();
  2496. int lesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
  2497. string strDescriptionEcho = string.Empty;
  2498. string strDescriptionShape = string.Empty;
  2499. string strDescriptionMargin = string.Empty;
  2500. string strDescriptionEchogenicFoci = string.Empty;
  2501. for (int ii = 0; ii < lesionsNum; ii++)
  2502. {
  2503. //获取病灶轮廓
  2504. int num2 = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour.Count;
  2505. StructPoint[] lesionPts = new StructPoint[num2];
  2506. System.Drawing.PointF[] lesionContour = new PointF[num2];
  2507. for (int i = 0; i < num2; i++)
  2508. {
  2509. lesionPts[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
  2510. lesionPts[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
  2511. lesionContour[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
  2512. lesionContour[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
  2513. }
  2514. //获取甲状腺轮廓
  2515. List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
  2516. int num1 = thyroidCont.Count;
  2517. //if(num1 == 0)
  2518. //{
  2519. // WriteTxtToFile("E:\\image\\", "name.txt", name, false);
  2520. //}
  2521. StructPoint[] thyroidPts = new StructPoint[num1];
  2522. System.Drawing.PointF[] thyroidContour = new PointF[num1];
  2523. for (int i = 0; i < num1; i++)
  2524. {
  2525. thyroidPts[i].X = thyroidCont[i].X;
  2526. thyroidPts[i].Y = thyroidCont[i].Y;
  2527. thyroidContour[i].X = thyroidCont[i].X;
  2528. thyroidContour[i].Y = thyroidCont[i].Y;
  2529. }
  2530. EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
  2531. EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
  2532. ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
  2533. MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
  2534. LesionDescri desCpp = new LesionDescri();
  2535. desCpp.echo = 0;
  2536. desCpp.shape = 0;
  2537. desCpp.margin = 0;
  2538. desCpp.echogenicFoci = 0;
  2539. desCpp.axisPt = new AxisPoint();
  2540. desCpp.axisPt.horizontalPt1 = new StructPoint { X = 0, Y = 0 };
  2541. desCpp.axisPt.horizontalPt2 = new StructPoint { X = 0, Y = 0 };
  2542. desCpp.axisPt.verticalPt1 = new StructPoint { X = 0, Y = 0 };
  2543. desCpp.axisPt.verticalPt2 = new StructPoint { X = 0, Y = 0 };
  2544. System.Drawing.PointF[] axisH = new PointF[2];
  2545. System.Drawing.PointF[] axisV = new PointF[2];
  2546. //WriteTxtToFile("E:\\image\\", "usename.txt", name, false);
  2547. roiCoor roiSeg ;
  2548. roiSeg.x = 0;
  2549. roiSeg.y = 0;
  2550. roiSeg.width = 0;
  2551. roiSeg.height = 0;
  2552. ThyroidDescriptionContour(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
  2553. roi, num2, lesionPts, ref roiSeg);
  2554. int num = roiSeg.width * roiSeg.height;
  2555. StructPoint[] contourPts_tmp = new StructPoint[num];
  2556. //int ptsNum = ContourDetectBLS(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
  2557. ////int ptsNum = ContourDetectBLSForThyroid(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
  2558. //StructPoint[] lesionPtsChange = new StructPoint[ptsNum];
  2559. //for (int i = 0; i < ptsNum; i++)
  2560. //{
  2561. // lesionPtsChange[i].X = contourPts_tmp[i].X;
  2562. // lesionPtsChange[i].Y = contourPts_tmp[i].Y;
  2563. //}
  2564. var starttime = Environment.TickCount;
  2565. byte[] arrInput = new byte[modelInputW * modelInputH * modelInputC];
  2566. roiCoor roiDst;
  2567. roiDst.x = 0;
  2568. roiDst.y = 0;
  2569. roiDst.width = 0;
  2570. roiDst.height = 0;
  2571. ThyroidDescriptionModelProcess(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
  2572. roi, num1, thyroidPts, /*ptsNum, lesionPtsChange,*/num2, lesionPts, modelInputW, modelInputH,
  2573. modelInputC, ref roiDst, arrInput);
  2574. byte[] arrOutput = new byte[modelOutputW * modelOutputH * modelOutputC];
  2575. //_inferNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
  2576. _UseNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
  2577. int maskSize = roiDst.width * roiDst.height;
  2578. int calcificatNum = 0;//钙化点数目
  2579. int MaxLesionCount = 60;//假设最多60钙化点
  2580. int[] contourLen = new int[MaxLesionCount];
  2581. StructPoint[] contourPoints = new StructPoint[maskSize];
  2582. ThyroidDescriptionModelProcessModelImage(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
  2583. ref calcificatNum, contourLen, contourPoints);
  2584. //var starttime = Environment.TickCount;
  2585. ThyroidDescriptionModelAfterProcess(
  2586. rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
  2587. num1, thyroidPts, /*ptsNum, lesionPtsChange,*/ num2, lesionPts,
  2588. calcificatNum, contourLen, contourPoints,
  2589. roiDst, ref desCpp);
  2590. StructPoint pt;
  2591. pt.X = 0;
  2592. pt.Y = 0;
  2593. AxisPoint axis;
  2594. axis.horizontalPt1 = pt;
  2595. axis.horizontalPt2 = pt;
  2596. axis.verticalPt1 = pt;
  2597. axis.verticalPt2 = pt;
  2598. //MyLesionAxisProcess(roiDst, ptsNum, lesionPtsChange, ref axis);
  2599. {
  2600. //int ptsNum = ContourDetectBLS(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
  2601. ////int ptsNum = ContourDetectBLSForThyroid(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
  2602. //StructPoint[] lesionPtsChange = new StructPoint[ptsNum];
  2603. //for (int i = 0; i < ptsNum; i++)
  2604. //{
  2605. // lesionPtsChange[i].X = contourPts_tmp[i].X;
  2606. // lesionPtsChange[i].Y = contourPts_tmp[i].Y;
  2607. //}
  2608. //var starttime = Environment.TickCount;
  2609. //byte[] arrInput = new byte[modelInputW * modelInputH * modelInputC];
  2610. //roiCoor roiDst;
  2611. //roiDst.x = 0;
  2612. //roiDst.y = 0;
  2613. //roiDst.width = 0;
  2614. //roiDst.height = 0;
  2615. //ThyroidDescriptionModelProcess(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
  2616. // roi, num1, thyroidPts, ptsNum, lesionPtsChange, /*num2, lesionPts,*/ modelInputW, modelInputH,
  2617. // modelInputC, ref roiDst, arrInput);
  2618. //byte[] arrOutput = new byte[modelOutputW * modelOutputH * modelOutputC];
  2619. //_UseNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
  2620. //int maskSize = roiDst.width * roiDst.height;
  2621. //int calcificatNum = 0;//钙化点数目
  2622. //int MaxLesionCount = 60;//假设最多60钙化点
  2623. //int[] contourLen = new int[MaxLesionCount];
  2624. //StructPoint[] contourPoints = new StructPoint[maskSize];
  2625. //ThyroidDescriptionModelProcessModelImage(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
  2626. // ref calcificatNum, contourLen, contourPoints);
  2627. //ThyroidDescriptionModelAfterProcess(
  2628. // rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
  2629. // num1, thyroidPts, ptsNum, lesionPtsChange, /*num2, lesionPts,*/
  2630. // calcificatNum, contourLen, contourPoints,
  2631. // roiDst, ref desCpp);
  2632. //StructPoint pt;
  2633. //pt.X = 0;
  2634. //pt.Y = 0;
  2635. //AxisPoint axis;
  2636. //axis.horizontalPt1 = pt;
  2637. //axis.horizontalPt2 = pt;
  2638. //axis.verticalPt1 = pt;
  2639. //axis.verticalPt2 = pt;
  2640. //MyLesionAxisProcess(roiDst, ptsNum, lesionPtsChange, ref axis);
  2641. }
  2642. //ThyroidDescriptionModelAfterProcess_1(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
  2643. // rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
  2644. // roi, num1, thyroidPts, num2, lesionPts, ref desCpp);
  2645. var endtime = Environment.TickCount;
  2646. //WriteTxtToFile("E:\\image\\", "time_all.txt", (endtime - starttime).ToString(), false);
  2647. arrOutput = null;
  2648. arrInput = null;
  2649. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  2650. {
  2651. ElapsedTime.Text = (endtime - starttime).ToString();
  2652. }));
  2653. int echoCpp = desCpp.echo; // 回声
  2654. int shapeCpp = desCpp.shape; // 形状
  2655. int marginCpp = desCpp.margin; // 边缘
  2656. int echogenicFociCpp = desCpp.echogenicFoci; // 局灶性强回声
  2657. EchogenicFociEnum echoFoci = (EchogenicFociEnum)desCpp.echogenicFoci;
  2658. EchoPatternEnum echo = (EchoPatternEnum)desCpp.echo;
  2659. ShapeEnum shape = (ShapeEnum)desCpp.shape;
  2660. MarginEnum margin = (MarginEnum)desCpp.margin;
  2661. AxisPoint axisPoint = desCpp.axisPt; // 纵、横轴端点坐标
  2662. StructPoint pt1 = axisPoint.horizontalPt1; // 横轴
  2663. StructPoint pt2 = axisPoint.horizontalPt2;
  2664. StructPoint pt3 = axisPoint.verticalPt1; // 纵轴
  2665. StructPoint pt4 = axisPoint.verticalPt2;
  2666. axisH[0].X = pt1.X;
  2667. axisH[0].Y = pt1.Y;
  2668. axisH[1].X = pt2.X;
  2669. axisH[1].Y = pt2.Y;
  2670. axisV[0].X = pt3.X;
  2671. axisV[0].Y = pt3.Y;
  2672. axisV[1].X = pt4.X;
  2673. axisV[1].Y = pt4.Y;
  2674. int resCa = 0;
  2675. int resEcho = 0;
  2676. int resShape = -1;
  2677. int resMargin = -1;
  2678. //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  2679. {
  2680. string strEcho = string.Empty;
  2681. if (echo == EchoPatternEnum.Anechoic)
  2682. {
  2683. strEcho = "无回声";
  2684. resEcho = 0;
  2685. }
  2686. else if (echo == EchoPatternEnum.Hyperechoic)
  2687. {
  2688. strEcho = "高回声";
  2689. resEcho = 1;
  2690. }
  2691. else if (echo == EchoPatternEnum.Isoechoic)
  2692. {
  2693. strEcho = "等回声";
  2694. resEcho = 2;
  2695. }
  2696. else if (echo == EchoPatternEnum.Hypoechoic)
  2697. {
  2698. strEcho = "低回声";
  2699. resEcho = 3;
  2700. }
  2701. else if (echo == EchoPatternEnum.HypoechoicLower)
  2702. {
  2703. strEcho = "极低回声";
  2704. resEcho = 4;
  2705. }
  2706. strDescriptionEcho += ii.ToString() + ":" + strEcho + "\r\n";
  2707. string strShape = string.Empty;
  2708. if (shape == ShapeEnum.WiderThanTall)
  2709. {
  2710. strShape = "宽大于高";
  2711. resShape = 0;
  2712. }
  2713. else if (shape == ShapeEnum.TallThanWider)
  2714. {
  2715. strShape = "高大于宽";
  2716. resShape = 1;
  2717. }
  2718. strDescriptionShape += ii.ToString() + ":" + strShape + "\r\n";
  2719. string strMargin = string.Empty;
  2720. if (margin == MarginEnum.Smooth)
  2721. {
  2722. strMargin = "边缘光整";
  2723. resMargin = 0;
  2724. }
  2725. else if (margin == MarginEnum.IllDefined)
  2726. {
  2727. strMargin = "边缘模糊";
  2728. resMargin = 1;
  2729. }
  2730. else if (margin == MarginEnum.Lobulated)
  2731. {
  2732. strMargin = "边缘分叶状";
  2733. resMargin = 2;
  2734. }
  2735. else if (margin == MarginEnum.Irregular)
  2736. {
  2737. strMargin = "边缘不规则";
  2738. resMargin = 3;
  2739. }
  2740. else if (margin == MarginEnum.ExtraThyroidalExtension)
  2741. {
  2742. strMargin = "甲状腺外侵犯";
  2743. resMargin = 4;
  2744. }
  2745. strDescriptionMargin += ii.ToString() + ":" + strMargin + "\r\n";
  2746. string strEchogenicFoci = string.Empty;
  2747. if (echoFoci == EchogenicFociEnum.NoCifications)
  2748. {
  2749. strEchogenicFoci = "无钙化";
  2750. resCa = 0;
  2751. }
  2752. else if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
  2753. {
  2754. strEchogenicFoci = "粗钙化";
  2755. resCa = 1;
  2756. }
  2757. else if (echoFoci == EchogenicFociEnum.Microcalcifications)
  2758. {
  2759. strEchogenicFoci = "微钙化";
  2760. resCa = 2;
  2761. }
  2762. strDescriptionEchogenicFoci += ii.ToString() + ":" + strEchogenicFoci + "\r\n";
  2763. }
  2764. //));
  2765. if (echoFociGT == echoFoci)
  2766. {
  2767. if (echoFoci == EchogenicFociEnum.NoCifications)
  2768. {
  2769. _NoCifications_NoCifications_num++;
  2770. result = 1;
  2771. }
  2772. if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
  2773. {
  2774. _Coarsecalcifications_Coarsecalcifications_num++;
  2775. result = 2;
  2776. }
  2777. if (echoFoci == EchogenicFociEnum.Microcalcifications)
  2778. {
  2779. _Macrocalcifications_Macrocalcifications_num++;
  2780. result = 3;
  2781. }
  2782. }
  2783. else
  2784. {
  2785. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  2786. {
  2787. _NoCifications_Coarsecalcifications_num++;
  2788. result = 4;
  2789. }
  2790. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  2791. {
  2792. _NoCifications_Macrocalcifications_num++;
  2793. result = 5;
  2794. }
  2795. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  2796. {
  2797. _Coarsecalcifications_NoCifications_num++;
  2798. result = 6;
  2799. }
  2800. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  2801. {
  2802. _Coarsecalcifications_Macrocalcifications_num++;
  2803. result = 7;
  2804. }
  2805. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  2806. {
  2807. _Macrocalcifications_NoCifications_num++;
  2808. result = 8;
  2809. }
  2810. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  2811. {
  2812. _Macrocalcifications_Coarsecalcifications_num++;
  2813. result = 9;
  2814. }
  2815. }
  2816. if(echoGT == echo)
  2817. {
  2818. if (echo == EchoPatternEnum.Anechoic)
  2819. {
  2820. _Anechoic_Anechoi_num++;
  2821. }
  2822. if (echo == EchoPatternEnum.Hyperechoic)
  2823. {
  2824. _Hyperechoic_Hyperechoic_num++;
  2825. }
  2826. if (echo == EchoPatternEnum.Isoechoic)
  2827. {
  2828. _Isoechoic_Isoechoic_num++;
  2829. }
  2830. if (echo == EchoPatternEnum.Hypoechoic)
  2831. {
  2832. _Hypoechoic_Hypoechoic_num++;
  2833. }
  2834. if (echo == EchoPatternEnum.HypoechoicLower)
  2835. {
  2836. _HypoechoicLower_HypoechoicLower_num++;
  2837. }
  2838. }
  2839. else
  2840. {
  2841. //把无回声判为其它
  2842. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
  2843. {
  2844. _Anechoic_Hyperechoic_num++;
  2845. }
  2846. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
  2847. {
  2848. _Anechoic_Isoechoic_num++;
  2849. }
  2850. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
  2851. {
  2852. _Anechoic_Hypoechoic_num++;
  2853. }
  2854. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
  2855. {
  2856. _Anechoic_HypoechoicLower_num++;
  2857. }
  2858. //把高回声判为其它
  2859. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
  2860. {
  2861. _Hyperechoic_Anechoic_num++;
  2862. }
  2863. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
  2864. {
  2865. _Hyperechoic_Isoechoic_num++;
  2866. }
  2867. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
  2868. {
  2869. _Hyperechoic_Hypoechoic_num++;
  2870. }
  2871. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
  2872. {
  2873. _Hyperechoic_HypoechoicLower_num++;
  2874. }
  2875. //把等回声判为其它
  2876. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
  2877. {
  2878. _Isoechoic_Anechoic_num++;
  2879. }
  2880. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
  2881. {
  2882. _Isoechoic_Hyperechoic_num++;
  2883. }
  2884. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
  2885. {
  2886. _Isoechoic_Hypoechoic_num++;
  2887. }
  2888. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
  2889. {
  2890. _Isoechoic_HypoechoicLower_num++;
  2891. }
  2892. //低回声判为其它
  2893. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
  2894. {
  2895. _Hypoechoic_Anechoic_num++;
  2896. }
  2897. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
  2898. {
  2899. _Hypoechoic_Hyperechoic_num++;
  2900. }
  2901. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
  2902. {
  2903. _Hypoechoic_Isoechoic_num++;
  2904. }
  2905. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
  2906. {
  2907. _Hypoechoic_HypoechoicLower_num++;
  2908. }
  2909. //极低回声判为其它
  2910. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
  2911. {
  2912. _HypoechoicLower_Anechoicr_num++;
  2913. }
  2914. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
  2915. {
  2916. _HypoechoicLower_Hyperechoic_num++;
  2917. }
  2918. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
  2919. {
  2920. _HypoechoicLower_Isoechoic_num++;
  2921. }
  2922. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
  2923. {
  2924. _HypoechoicLower_Hypoechoic_num++;
  2925. }
  2926. }
  2927. if(shapeCppGT == shape)
  2928. {
  2929. if (shape == ShapeEnum.WiderThanTall)
  2930. {
  2931. _WT_WT_num++;
  2932. }
  2933. if (shape == ShapeEnum.TallThanWider)
  2934. {
  2935. _TW_TW_num++;
  2936. }
  2937. }
  2938. else
  2939. {
  2940. //把 宽大于高 判为 高大于宽
  2941. if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
  2942. {
  2943. _WT_TW_num++;
  2944. //WriteTxtToFile("E:\\image\\", "sssttt.txt", resShape.ToString(), false);
  2945. }
  2946. if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
  2947. {
  2948. _TW_WT_num++;
  2949. }
  2950. }
  2951. if (marginGT == margin)
  2952. {
  2953. if (margin == MarginEnum.Smooth)
  2954. {
  2955. _Smooth_Smooth_num++;
  2956. }
  2957. if (margin == MarginEnum.IllDefined)
  2958. {
  2959. _IllDefined_IllDefined_num++;
  2960. }
  2961. if (margin == MarginEnum.Lobulated)
  2962. {
  2963. _Lobulated_Lobulated_num++;
  2964. }
  2965. if (margin == MarginEnum.Irregular)
  2966. {
  2967. _Irregular_Irregular_num++;
  2968. }
  2969. if (margin == MarginEnum.ExtraThyroidalExtension)
  2970. {
  2971. _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
  2972. }
  2973. }
  2974. else
  2975. {
  2976. //把 边缘光整 判成其它
  2977. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
  2978. {
  2979. _Smooth_IllDefined_num++;
  2980. }
  2981. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
  2982. {
  2983. _Smooth_Lobulated_num++;
  2984. }
  2985. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
  2986. {
  2987. _Smooth_Irregular_num++;
  2988. }
  2989. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
  2990. {
  2991. _Smooth_ExtraThyroidalExtension_num++;
  2992. }
  2993. //把 边缘模糊 判成其它
  2994. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
  2995. {
  2996. _IllDefined_Smooth_num++;
  2997. }
  2998. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
  2999. {
  3000. _IllDefined_Lobulated_num++;
  3001. }
  3002. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
  3003. {
  3004. _IllDefined_Irregular_num++;
  3005. }
  3006. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
  3007. {
  3008. _IllDefined_ExtraThyroidalExtension_num++;
  3009. }
  3010. //把 边缘分叶状 判成其它
  3011. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
  3012. {
  3013. _Lobulated_Smooth_num++;
  3014. }
  3015. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
  3016. {
  3017. _Lobulated_IllDefined_num++;
  3018. }
  3019. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
  3020. {
  3021. _Lobulated_Irregular_num++;
  3022. }
  3023. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
  3024. {
  3025. _Lobulated_ExtraThyroidalExtension_num++;
  3026. }
  3027. //把 边缘不规则 判成其它
  3028. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
  3029. {
  3030. _Irregular_Smooth_num++;
  3031. }
  3032. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
  3033. {
  3034. _Irregular_IllDefined_num++;
  3035. }
  3036. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
  3037. {
  3038. _Irregular_Lobulated_num++;
  3039. }
  3040. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
  3041. {
  3042. _Irregular_ExtraThyroidalExtension_num++;
  3043. }
  3044. //把 甲状腺外侵犯 判成其它
  3045. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
  3046. {
  3047. _ExtraThyroidalExtension_Smooth_num++;
  3048. }
  3049. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
  3050. {
  3051. _ExtraThyroidalExtension_IllDefined_num++;
  3052. }
  3053. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
  3054. {
  3055. _ExtraThyroidalExtension_Lobulated_num++;
  3056. }
  3057. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
  3058. {
  3059. _ExtraThyroidalExtension_Irregular_num++;
  3060. }
  3061. }
  3062. //////////////
  3063. string newPath = System.IO.Path.Combine(_currentBinPath, "result");
  3064. if (resEcho == 0)
  3065. {
  3066. string nameSave = newPath + "\\00\\" + name + ".jpg";
  3067. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3068. //testNUm = testNUm+1;
  3069. }
  3070. else if (resEcho == 1)
  3071. {
  3072. string nameSave = newPath + "\\01\\" + name + ".jpg";
  3073. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3074. }
  3075. else if (resEcho == 2)
  3076. {
  3077. string nameSave = newPath + "\\02\\" + name + ".jpg";
  3078. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3079. }
  3080. else if (resEcho == 3)
  3081. {
  3082. string nameSave = newPath + "\\03\\" + name + ".jpg";
  3083. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3084. }
  3085. else if (resEcho == 4)
  3086. {
  3087. string nameSave = newPath + "\\04\\" + name + ".jpg";
  3088. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3089. }
  3090. if (resCa == 0)
  3091. {
  3092. string nameSave = newPath + "\\00\\" + name + ".jpg";
  3093. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3094. }
  3095. else if (resCa == 1)
  3096. {
  3097. string nameSave = newPath + "\\01\\" + name + ".jpg";
  3098. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3099. }
  3100. else if (resCa == 2)
  3101. {
  3102. string nameSave = newPath + "\\02\\" + name + ".jpg";
  3103. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3104. }
  3105. if (resShape == 0)
  3106. {
  3107. string nameSave = newPath + "\\00\\" + name + ".jpg";
  3108. if (shapeCppGT == ShapeEnum.WiderThanTall)
  3109. {
  3110. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  3111. }
  3112. }
  3113. else if (resShape == 1)
  3114. {
  3115. string nameSave = newPath + "\\01\\" + name + ".jpg";
  3116. if (shapeCppGT == ShapeEnum.WiderThanTall)
  3117. {
  3118. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  3119. //WriteTxtToFile("E:\\image\\", "sss.txt", resShape.ToString(), false);
  3120. }
  3121. // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
  3122. }
  3123. if (resMargin == 0)
  3124. {
  3125. string nameSave = newPath + "\\00\\" + name + ".jpg";
  3126. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3127. }
  3128. else if (resMargin == 1)
  3129. {
  3130. string nameSave = newPath + "\\01\\" + name + ".jpg";
  3131. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3132. }
  3133. else if (resMargin == 2)
  3134. {
  3135. string nameSave = newPath + "\\02\\" + name + ".jpg";
  3136. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3137. }
  3138. else if (resMargin == 3)
  3139. {
  3140. string nameSave = newPath + "\\03\\" + name + ".jpg";
  3141. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3142. }
  3143. else if (resMargin ==4)
  3144. {
  3145. string nameSave = newPath + "\\04\\" + name + ".jpg";
  3146. //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
  3147. }
  3148. using (var g = Graphics.FromImage(dstimage))
  3149. {
  3150. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  3151. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
  3152. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  3153. if (lesionContour.Length > 1)//画直线要超过一个点
  3154. {
  3155. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  3156. g.DrawLines(pen, lesionContour); //画病灶轮廓
  3157. System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
  3158. if (thyroidContour.Length > 0)
  3159. {
  3160. g.DrawLines(pen2, thyroidContour); //画肝脏轮廓
  3161. }
  3162. pen.Dispose();
  3163. }
  3164. Brush brush;
  3165. brush = Brushes.Orange;
  3166. g.DrawString(ii.ToString(), new Font("Arial", 20), brush, axisH[1].X, axisH[1].Y);
  3167. //画轮廓的长短轴
  3168. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  3169. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  3170. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  3171. g.DrawLines(pen_v, axisV); //纵轴,红色
  3172. g.Dispose();
  3173. }
  3174. }
  3175. EchoPatternDescri.Text = strDescriptionEcho;
  3176. ShapeDescri.Text = strDescriptionShape;
  3177. MarginDescri.Text = strDescriptionMargin;
  3178. EchogenicFociDescri.Text = strDescriptionEchogenicFoci;
  3179. _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
  3180. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  3181. {
  3182. DstImage.Source = _dstImg;
  3183. }));
  3184. dstimage.Dispose();
  3185. return result;
  3186. }
  3187. else
  3188. {
  3189. //WriteTxtToFile("E:\\image\\", "namet.txt", name.ToString(), false);
  3190. //MessageBox.Show("未读取到病灶!");
  3191. return -1;
  3192. }
  3193. }
  3194. private void OnDBModelPredictImages(object sender, RoutedEventArgs e)
  3195. {
  3196. if (_UseNet == null)
  3197. {
  3198. MessageBox.Show("请先加载模型!");
  3199. return;
  3200. }
  3201. OpenFileDialog openFileDialog = new OpenFileDialog();
  3202. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  3203. openFileDialog.Multiselect = true;
  3204. openFileDialog.Title = "选择一幅或多幅图像";
  3205. if (openFileDialog.ShowDialog() ?? false)
  3206. {
  3207. foreach (string filename in openFileDialog.FileNames)
  3208. {
  3209. Bitmap img = new Bitmap(filename);
  3210. _currentImg = img;
  3211. string temp;
  3212. int idx = filename.LastIndexOf("\\");
  3213. temp = filename.Substring(idx);
  3214. string[] strs1 = temp.Split('\\');
  3215. temp = strs1[1];
  3216. string[] sArray = null;
  3217. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  3218. string ImgId = sArray[0];
  3219. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  3220. _currentImgId = ImgId;
  3221. int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
  3222. if (imgIdx < 0)
  3223. {
  3224. //return;
  3225. WriteTxtToFile("E:\\image\\", "notname.txt", ImgId, false);
  3226. continue;
  3227. }
  3228. _currentImgIdex = imgIdx;
  3229. int res = DoDescriAlgorithmModel(ImgId);
  3230. }
  3231. }
  3232. Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
  3233. Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
  3234. Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
  3235. Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
  3236. Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
  3237. Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
  3238. Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
  3239. Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
  3240. Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
  3241. Console.WriteLine();
  3242. Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
  3243. Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
  3244. Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
  3245. Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
  3246. Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
  3247. Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
  3248. Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
  3249. Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
  3250. Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
  3251. Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
  3252. Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
  3253. Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
  3254. Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
  3255. Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
  3256. Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
  3257. Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
  3258. Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
  3259. Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
  3260. Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
  3261. Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
  3262. Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
  3263. Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
  3264. Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
  3265. Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
  3266. Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
  3267. Console.WriteLine();
  3268. Console.WriteLine("形状: ");
  3269. Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
  3270. Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
  3271. Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
  3272. Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
  3273. Console.WriteLine();
  3274. Console.WriteLine("边缘: ");
  3275. Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
  3276. Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
  3277. Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
  3278. Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
  3279. Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
  3280. Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
  3281. Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
  3282. Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
  3283. Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
  3284. Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
  3285. Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
  3286. Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
  3287. Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
  3288. Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
  3289. Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
  3290. Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
  3291. Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
  3292. Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
  3293. Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
  3294. Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
  3295. Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
  3296. Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
  3297. Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
  3298. Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
  3299. Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
  3300. Console.WriteLine();
  3301. }
  3302. /// <summary>
  3303. /// 正在使用的db文件中,一些图片缺少轮廓或者其他数据,需要从其他的db文件复制
  3304. /// 第一个db文件为需要添加轮廓数据的文件,添加的轮廓数据保存到当前db文件中
  3305. /// 第二个db文件为被复制的文件
  3306. /// 然后选择需要添加轮廓信息的图像,根据实际需求添加信息
  3307. /// </summary>
  3308. /// <param name="sender"></param>
  3309. /// <param name="e"></param>
  3310. private void OnDBAddClick(object sender, RoutedEventArgs e)
  3311. {
  3312. OpenFileDialog openFileDialogdb = new OpenFileDialog();
  3313. openFileDialogdb.Filter = "数据库文件|*.db";
  3314. openFileDialogdb.Multiselect = false;
  3315. openFileDialogdb.Title = "选择一个数据库文件";
  3316. string dbPath = "";
  3317. if (openFileDialogdb.ShowDialog() ?? false)
  3318. {
  3319. dbPath = openFileDialogdb.FileName;
  3320. }
  3321. DataBase dataBase = new DataBase(dbPath);
  3322. bool readDb = dataBase.ReadDataBase();
  3323. if (readDb)
  3324. {
  3325. _allImgInfo = dataBase._allImages;
  3326. if (_allImgInfo.Count > 0)
  3327. {
  3328. MessageBox.Show("加载成功!");
  3329. }
  3330. }
  3331. else
  3332. {
  3333. MessageBox.Show("读取失败!");
  3334. return;
  3335. }
  3336. _dbPathChoose = dbPath;
  3337. //string dbPath = "";
  3338. List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
  3339. OpenFileDialog openFileDialog2 = new OpenFileDialog();
  3340. openFileDialog2.Filter = "数据库文件|*.db";
  3341. openFileDialog2.Multiselect = false;
  3342. openFileDialog2.Title = "选择一个被复制数据库文件";
  3343. string dbPath2 = "";
  3344. if (openFileDialog2.ShowDialog() ?? false)
  3345. {
  3346. dbPath = openFileDialog2.FileName;
  3347. }
  3348. DataBase dataBase2 = new DataBase(dbPath);
  3349. bool readDb2 = dataBase2.ReadDataBase();
  3350. if (readDb2)
  3351. {
  3352. allImgInfo2 = dataBase2._allImages;
  3353. if (allImgInfo2.Count > 0)
  3354. {
  3355. MessageBox.Show("加载成功!");
  3356. }
  3357. }
  3358. else
  3359. {
  3360. MessageBox.Show("读取失败!");
  3361. return;
  3362. }
  3363. ///////////////////////////////
  3364. OpenFileDialog openFileDialog = new OpenFileDialog();
  3365. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  3366. openFileDialog.Multiselect = true;
  3367. openFileDialog.Title = "选择一幅或多幅图像";
  3368. if (openFileDialog.ShowDialog() ?? false)
  3369. {
  3370. foreach (string filename in openFileDialog.FileNames)
  3371. {
  3372. //Bitmap img = new Bitmap(filename);
  3373. string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
  3374. string temp;
  3375. int idx = filename.LastIndexOf("\\");
  3376. temp = filename.Substring(idx);
  3377. string[] strs1 = temp.Split('\\');
  3378. temp = strs1[1];
  3379. string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
  3380. string ImgId = strs2[0];
  3381. int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
  3382. int numLesions = _allImgInfo[imgIndex].Lesions.Count;
  3383. int imgIndex_2 = allImgInfo2.FindIndex(x => x.ImageId == ImgId);
  3384. int numLesions_2 = allImgInfo2[imgIndex].Lesions.Count;
  3385. if (imgIndex >= 0 && numLesions > 0 && imgIndex_2 >=0 && numLesions_2 > 0)
  3386. {
  3387. //AddExistImage(ImgId);
  3388. //SetLesions(ImgId, allImgInfo2[imgIndex_2].Lesions);//添加病灶信息
  3389. SetThyroidContour(ImgId, allImgInfo2[imgIndex_2].ThyroidContour);//添加甲状腺轮廓
  3390. }
  3391. else
  3392. {
  3393. MessageBox.Show("Id未找到:" + ImgId);
  3394. }
  3395. }
  3396. }
  3397. MessageBox.Show("完成!");
  3398. }
  3399. /// <summary>
  3400. /// 整个检测流程全部使用模型给出的结果
  3401. /// </summary>
  3402. /// <param name="sender"></param>
  3403. /// <param name="e"></param>
  3404. private void OnDBModelResultPredictImages(object sender, RoutedEventArgs e)
  3405. {
  3406. if(_currentImg != null)
  3407. {
  3408. string name = "sos";
  3409. DescriAlgorithmModelAll(name,false);
  3410. //DoDescriAlgorithmModel(name);
  3411. }
  3412. else
  3413. {
  3414. MessageBox.Show("请先加载待测图像!");
  3415. }
  3416. }
  3417. /// <summary>
  3418. ///
  3419. /// </summary>
  3420. /// <param name="name"></param>
  3421. /// <param name="bStatistics"></param> 是否需要统计检测结果。(如果使用全模型,模型检测的病灶可能和医生标注的不同,慎重使用)
  3422. private void DescriAlgorithmModelAll(string name, bool bStatistics)
  3423. {
  3424. if (_currentImg == null)
  3425. {
  3426. MessageBox.Show("请先加载待测图像!");
  3427. return;
  3428. }
  3429. Bitmap bmp = _currentImg;
  3430. AI.Common.Interface.RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
  3431. _caseId = Guid.NewGuid().ToString();
  3432. _dataId = name;
  3433. _readingVideo = false;
  3434. var extendData = new Dictionary<string, object>();
  3435. extendData.Add("CaseId", _caseId);
  3436. extendData.Add("DataId", _dataId);
  3437. extendData.Add("IsVideo", _readingVideo);
  3438. extendData.Add("TimeStamp", (double)_frameIndex);
  3439. _processId = _module.StartProcess();
  3440. var input = new ImageInputData(rawImg, extendData);
  3441. IDetectedObject[] result = _module.PushOnePieceOfData(_processId, input);
  3442. _module.EndProcess(_processId);
  3443. Bitmap dstimage = (Bitmap)_currentImg.Clone();
  3444. int lesionNum = 0;
  3445. string strDescriptionEcho = string.Empty;
  3446. string strDescriptionShape = string.Empty;
  3447. string strDescriptionMargin = string.Empty;
  3448. string strDescriptionEchogenicFoci = string.Empty;
  3449. System.Drawing.PointF[] axisH = new PointF[2];
  3450. System.Drawing.PointF[] axisV = new PointF[2];
  3451. int index = 0;
  3452. foreach (var moduleResult in result)
  3453. {
  3454. var label = moduleResult.Label;
  3455. var nameOrgan = label.GroupName;
  3456. if (nameOrgan != "AI.Vaid.Thyroid.Lesion")
  3457. {
  3458. continue;
  3459. }
  3460. if (moduleResult.Contour == null || moduleResult.Measurements == null || moduleResult.Description == null)
  3461. {
  3462. }
  3463. if (label.Name == "NoObviousLesion" || label.Name == "DiffuseDisease")
  3464. {
  3465. return;
  3466. }
  3467. var resultConversion = AIModuleResultShowUtils.GetObjectStr(moduleResult);
  3468. if (moduleResult.Contour?.Contours.Length > 0)
  3469. {
  3470. //Point2D[] contourCppThyroid = new Point2D[numTotalPtsThyroid];
  3471. //int index = 0;
  3472. //for (int ni = 0; ni < numContourThyroid; ni++)
  3473. //{
  3474. // for (int nj = 0; nj < contourLenThyroid[ni]; nj++)
  3475. // {
  3476. // contourCppThyroid[index] = thyroidContours[ni].OuterContours[0].Points[nj];
  3477. // index += 1;
  3478. // }
  3479. //}
  3480. int count = moduleResult.Contour.Contours.Length;
  3481. for (int i = 0; i < count; i++)
  3482. {
  3483. var organPoints = moduleResult.Contour.OuterContours[i];
  3484. int organPtsCount = organPoints.Points.Length;
  3485. var organCount = new List<System.Windows.Point>();
  3486. System.Drawing.PointF[] organContour = new PointF[organPtsCount];
  3487. //for (int j = 0; j < organPtsCount; j++)
  3488. //{
  3489. // var point = new System.Windows.Point(organPoints.Points[j].X, organPoints.Points[j].Y);
  3490. // organContour[j].X = organPoints.Points[j].X;
  3491. // organContour[j].Y = organPoints.Points[j].Y;
  3492. //}
  3493. var contourPoints = moduleResult.Contour.Contours[i];
  3494. int pointCount = contourPoints.Points.Length;
  3495. var points = new List<System.Windows.Point>();
  3496. System.Drawing.PointF[] lesionContour = new PointF[pointCount];
  3497. for (int j = 0; j < pointCount; j++)
  3498. {
  3499. var point = new System.Windows.Point(contourPoints.Points[j].X, contourPoints.Points[j].Y);
  3500. lesionContour[j].X = contourPoints.Points[j].X;
  3501. lesionContour[j].Y = contourPoints.Points[j].Y;
  3502. }
  3503. var desResult = moduleResult.Description;
  3504. var type = desResult.GetType();
  3505. EchogenicFociEnum echoFoci = new EchogenicFociEnum();
  3506. EchoPatternEnum echo = new EchoPatternEnum();
  3507. ShapeEnum shape = new ShapeEnum();
  3508. MarginEnum margin = new MarginEnum();
  3509. string strDescription = string.Empty;
  3510. {
  3511. foreach (var key in desResult.Descriptions.Keys)
  3512. {
  3513. if (key == "Shape")
  3514. {
  3515. string des = string.Empty;
  3516. switch (desResult.Descriptions[key])
  3517. {
  3518. case "WiderThanTall":
  3519. des = "水平位";
  3520. shape = ShapeEnum.WiderThanTall;
  3521. break;
  3522. case "TallThanWider":
  3523. des = "垂直位";
  3524. shape = ShapeEnum.TallThanWider;
  3525. break;
  3526. }
  3527. strDescription += "形状:" + des + Environment.NewLine;
  3528. }
  3529. if (key == "EchoPattern")
  3530. {
  3531. string des = string.Empty;
  3532. switch (desResult.Descriptions[key])
  3533. {
  3534. case "Anechoic":
  3535. des = "无回声";
  3536. echo = EchoPatternEnum.Anechoic;
  3537. break;
  3538. case "Hyperechoic":
  3539. des = "高回声";
  3540. echo = EchoPatternEnum.Hyperechoic;
  3541. break;
  3542. case "Isoechoic":
  3543. des = "等回声";
  3544. echo = EchoPatternEnum.Isoechoic;
  3545. break;
  3546. case "Hypoechoic":
  3547. des = "低回声";
  3548. echo = EchoPatternEnum.Hypoechoic;
  3549. break;
  3550. case "HypoechoicLower":
  3551. des = "极低回声";
  3552. echo = EchoPatternEnum.HypoechoicLower;
  3553. break;
  3554. }
  3555. strDescription += "回声类型:" + des + Environment.NewLine;
  3556. }
  3557. if (key == "Margin")
  3558. {
  3559. string des = string.Empty;
  3560. switch (desResult.Descriptions[key])
  3561. {
  3562. case "Smooth":
  3563. des = "光滑";
  3564. margin = MarginEnum.Smooth;
  3565. break;
  3566. case "IllDefined":
  3567. des = "不清晰";
  3568. margin = MarginEnum.IllDefined;
  3569. break;
  3570. case "Lobulated":
  3571. des = "分叶";
  3572. margin = MarginEnum.Lobulated;
  3573. break;
  3574. case "Irregular":
  3575. des = "不规则";
  3576. margin = MarginEnum.Irregular;
  3577. break;
  3578. case "ExtraThyroidalExtension":
  3579. des = "甲状腺外扩";
  3580. margin = MarginEnum.ExtraThyroidalExtension;
  3581. break;
  3582. }
  3583. strDescription += "边缘:" + des + Environment.NewLine;
  3584. }
  3585. if (key == "EchogenicFoci")
  3586. {
  3587. string des = string.Empty;
  3588. switch (desResult.Descriptions[key])
  3589. {
  3590. case "NoCifications":
  3591. des = "无钙化";
  3592. echoFoci = EchogenicFociEnum.NoCifications;
  3593. break;
  3594. case "Coarsecalcifications":
  3595. des = "粗钙化";
  3596. echoFoci = EchogenicFociEnum.Coarsecalcifications;
  3597. break;
  3598. case "Microcalcifications":
  3599. des = "微钙化";
  3600. echoFoci = EchogenicFociEnum.Microcalcifications;
  3601. break;
  3602. }
  3603. strDescription += "钙化:" + des + Environment.NewLine;
  3604. }
  3605. }
  3606. }
  3607. var rect = moduleResult.BoundingBox.Contour.BoundingBox();
  3608. var roiBox = moduleResult.BoundingBox;
  3609. var ss = roiBox.Contour.Points;
  3610. var lesionSize = Array.Find(moduleResult.Measurements, x => x.GetType() == typeof(TransverseLongitudinalDiameterMeasurement));
  3611. var size = (TransverseLongitudinalDiameterMeasurement)lesionSize;
  3612. var pointLineH1 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineStart.X, size.TransverseDiameterMarkPosition.LineStart.Y);
  3613. var pointLineH2 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineEnd.X, size.TransverseDiameterMarkPosition.LineEnd.Y);
  3614. var pointLineV1 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineStart.X, size.LongitudinalDiameterMarkPosition.LineStart.Y);
  3615. var pointLineV2 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineEnd.X, size.LongitudinalDiameterMarkPosition.LineEnd.Y);
  3616. axisH[0].X = (int)pointLineH1.X;
  3617. axisH[0].Y = (int)pointLineH1.Y;
  3618. axisH[1].X = (int)pointLineH2.X;
  3619. axisH[1].Y = (int)pointLineH2.Y;
  3620. axisV[0].X = (int)pointLineV1.X;
  3621. axisV[0].Y = (int)pointLineV1.Y;
  3622. axisV[1].X = (int)pointLineV2.X;
  3623. axisV[1].Y = (int)pointLineV2.Y;
  3624. using (var g = Graphics.FromImage(dstimage))
  3625. {
  3626. if(organContour.Length >1)
  3627. {
  3628. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Green, 2);
  3629. g.DrawLines(pen, organContour); //画病灶轮廓
  3630. pen.Dispose();
  3631. }
  3632. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  3633. System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
  3634. g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  3635. pen3.Dispose();
  3636. if (lesionContour.Length > 1)//画直线要超过一个点
  3637. {
  3638. System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
  3639. g.DrawLines(pen, lesionContour); //画病灶轮廓
  3640. pen.Dispose();
  3641. }
  3642. //画轮廓的长短轴
  3643. System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
  3644. g.DrawLines(pen_h, axisH); //横轴,浅绿色
  3645. System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
  3646. g.DrawLines(pen_v, axisV); //纵轴,红色
  3647. SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.GreenYellow);
  3648. g.DrawString(lesionNum.ToString(), new Font("Arial", 20),
  3649. drawBrush, lesionBox.Left, lesionBox.Top);
  3650. g.DrawString(strDescription, new Font("Arial", 20),
  3651. drawBrush, rect.Top + 10, rect.Top + 10);
  3652. g.Dispose();
  3653. }
  3654. if(bStatistics)
  3655. {
  3656. EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[index].EchogenicFoci;
  3657. EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[index].EchoPattern;
  3658. ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[index].Shape;
  3659. MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[index].Margin;
  3660. if (echoFociGT == echoFoci)
  3661. {
  3662. if (echoFoci == EchogenicFociEnum.NoCifications)
  3663. {
  3664. _NoCifications_NoCifications_num++;
  3665. }
  3666. if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
  3667. {
  3668. _Coarsecalcifications_Coarsecalcifications_num++;
  3669. }
  3670. if (echoFoci == EchogenicFociEnum.Microcalcifications)
  3671. {
  3672. _Macrocalcifications_Macrocalcifications_num++;
  3673. }
  3674. }
  3675. else
  3676. {
  3677. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  3678. {
  3679. _NoCifications_Coarsecalcifications_num++;
  3680. }
  3681. if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  3682. {
  3683. _NoCifications_Macrocalcifications_num++;
  3684. }
  3685. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  3686. {
  3687. _Coarsecalcifications_NoCifications_num++;
  3688. }
  3689. if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
  3690. {
  3691. _Coarsecalcifications_Macrocalcifications_num++;
  3692. }
  3693. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
  3694. {
  3695. _Macrocalcifications_NoCifications_num++;
  3696. }
  3697. if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
  3698. {
  3699. _Macrocalcifications_Coarsecalcifications_num++;
  3700. }
  3701. }
  3702. if (echoGT == echo)
  3703. {
  3704. if (echo == EchoPatternEnum.Anechoic)
  3705. {
  3706. _Anechoic_Anechoi_num++;
  3707. }
  3708. if (echo == EchoPatternEnum.Hyperechoic)
  3709. {
  3710. _Hyperechoic_Hyperechoic_num++;
  3711. }
  3712. if (echo == EchoPatternEnum.Isoechoic)
  3713. {
  3714. _Isoechoic_Isoechoic_num++;
  3715. }
  3716. if (echo == EchoPatternEnum.Hypoechoic)
  3717. {
  3718. _Hypoechoic_Hypoechoic_num++;
  3719. }
  3720. if (echo == EchoPatternEnum.HypoechoicLower)
  3721. {
  3722. _HypoechoicLower_HypoechoicLower_num++;
  3723. }
  3724. }
  3725. else
  3726. {
  3727. //把无回声判为其它
  3728. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
  3729. {
  3730. _Anechoic_Hyperechoic_num++;
  3731. }
  3732. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
  3733. {
  3734. _Anechoic_Isoechoic_num++;
  3735. }
  3736. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
  3737. {
  3738. _Anechoic_Hypoechoic_num++;
  3739. }
  3740. if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
  3741. {
  3742. _Anechoic_HypoechoicLower_num++;
  3743. }
  3744. //把高回声判为其它
  3745. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
  3746. {
  3747. _Hyperechoic_Anechoic_num++;
  3748. }
  3749. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
  3750. {
  3751. _Hyperechoic_Isoechoic_num++;
  3752. }
  3753. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
  3754. {
  3755. _Hyperechoic_Hypoechoic_num++;
  3756. }
  3757. if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
  3758. {
  3759. _Hyperechoic_HypoechoicLower_num++;
  3760. }
  3761. //把等回声判为其它
  3762. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
  3763. {
  3764. _Isoechoic_Anechoic_num++;
  3765. }
  3766. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
  3767. {
  3768. _Isoechoic_Hyperechoic_num++;
  3769. }
  3770. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
  3771. {
  3772. _Isoechoic_Hypoechoic_num++;
  3773. }
  3774. if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
  3775. {
  3776. _Isoechoic_HypoechoicLower_num++;
  3777. }
  3778. //低回声判为其它
  3779. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
  3780. {
  3781. _Hypoechoic_Anechoic_num++;
  3782. }
  3783. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
  3784. {
  3785. _Hypoechoic_Hyperechoic_num++;
  3786. }
  3787. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
  3788. {
  3789. _Hypoechoic_Isoechoic_num++;
  3790. }
  3791. if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
  3792. {
  3793. _Hypoechoic_HypoechoicLower_num++;
  3794. }
  3795. //极低回声判为其它
  3796. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
  3797. {
  3798. _HypoechoicLower_Anechoicr_num++;
  3799. }
  3800. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
  3801. {
  3802. _HypoechoicLower_Hyperechoic_num++;
  3803. }
  3804. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
  3805. {
  3806. _HypoechoicLower_Isoechoic_num++;
  3807. }
  3808. if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
  3809. {
  3810. _HypoechoicLower_Hypoechoic_num++;
  3811. }
  3812. }
  3813. if (shapeCppGT == shape)
  3814. {
  3815. if (shape == ShapeEnum.WiderThanTall)
  3816. {
  3817. _WT_WT_num++;
  3818. }
  3819. if (shape == ShapeEnum.TallThanWider)
  3820. {
  3821. _TW_TW_num++;
  3822. }
  3823. }
  3824. else
  3825. {
  3826. //把 宽大于高 判为 高大于宽
  3827. if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
  3828. {
  3829. _WT_TW_num++;
  3830. //WriteTxtToFile("E:\\image\\", "sssttt.txt", resShape.ToString(), false);
  3831. }
  3832. if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
  3833. {
  3834. _TW_WT_num++;
  3835. }
  3836. }
  3837. if (marginGT == margin)
  3838. {
  3839. if (margin == MarginEnum.Smooth)
  3840. {
  3841. _Smooth_Smooth_num++;
  3842. }
  3843. if (margin == MarginEnum.IllDefined)
  3844. {
  3845. _IllDefined_IllDefined_num++;
  3846. }
  3847. if (margin == MarginEnum.Lobulated)
  3848. {
  3849. _Lobulated_Lobulated_num++;
  3850. }
  3851. if (margin == MarginEnum.Irregular)
  3852. {
  3853. _Irregular_Irregular_num++;
  3854. }
  3855. if (margin == MarginEnum.ExtraThyroidalExtension)
  3856. {
  3857. _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
  3858. }
  3859. }
  3860. else
  3861. {
  3862. //把 边缘光整 判成其它
  3863. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
  3864. {
  3865. _Smooth_IllDefined_num++;
  3866. }
  3867. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
  3868. {
  3869. _Smooth_Lobulated_num++;
  3870. }
  3871. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
  3872. {
  3873. _Smooth_Irregular_num++;
  3874. }
  3875. if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
  3876. {
  3877. _Smooth_ExtraThyroidalExtension_num++;
  3878. }
  3879. //把 边缘模糊 判成其它
  3880. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
  3881. {
  3882. _IllDefined_Smooth_num++;
  3883. }
  3884. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
  3885. {
  3886. _IllDefined_Lobulated_num++;
  3887. }
  3888. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
  3889. {
  3890. _IllDefined_Irregular_num++;
  3891. }
  3892. if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
  3893. {
  3894. _IllDefined_ExtraThyroidalExtension_num++;
  3895. }
  3896. //把 边缘分叶状 判成其它
  3897. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
  3898. {
  3899. _Lobulated_Smooth_num++;
  3900. }
  3901. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
  3902. {
  3903. _Lobulated_IllDefined_num++;
  3904. }
  3905. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
  3906. {
  3907. _Lobulated_Irregular_num++;
  3908. }
  3909. if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
  3910. {
  3911. _Lobulated_ExtraThyroidalExtension_num++;
  3912. }
  3913. //把 边缘不规则 判成其它
  3914. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
  3915. {
  3916. _Irregular_Smooth_num++;
  3917. }
  3918. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
  3919. {
  3920. _Irregular_IllDefined_num++;
  3921. }
  3922. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
  3923. {
  3924. _Irregular_Lobulated_num++;
  3925. }
  3926. if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
  3927. {
  3928. _Irregular_ExtraThyroidalExtension_num++;
  3929. }
  3930. //把 甲状腺外侵犯 判成其它
  3931. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
  3932. {
  3933. _ExtraThyroidalExtension_Smooth_num++;
  3934. }
  3935. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
  3936. {
  3937. _ExtraThyroidalExtension_IllDefined_num++;
  3938. }
  3939. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
  3940. {
  3941. _ExtraThyroidalExtension_Lobulated_num++;
  3942. }
  3943. if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
  3944. {
  3945. _ExtraThyroidalExtension_Irregular_num++;
  3946. }
  3947. }
  3948. }
  3949. }
  3950. //string name = newPath + "\\05\\" + imgName + ".png";
  3951. //dstimage.Save(name, System.Drawing.Imaging.ImageFormat.Png);
  3952. }
  3953. index++;
  3954. }
  3955. EchoPatternDescri.Text = strDescriptionEcho;
  3956. ShapeDescri.Text = strDescriptionShape;
  3957. MarginDescri.Text = strDescriptionMargin;
  3958. EchogenicFociDescri.Text = strDescriptionEchogenicFoci;
  3959. _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
  3960. Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
  3961. {
  3962. DstImage.Source = _dstImg;
  3963. }));
  3964. dstimage.Dispose();
  3965. }
  3966. private AI.Common.Interface.Rect CorrectRoi(AI.Common.Interface.Rect imgRoi, AI.Common.Interface.Rect lesionRoi)
  3967. {
  3968. int boundBoxOffset = 25;
  3969. int correctedLesionLeft = Math.Min(Math.Max(lesionRoi.Left - boundBoxOffset, imgRoi.Left), imgRoi.Right);
  3970. int correctedLesionRight = Math.Min(Math.Max(lesionRoi.Right + boundBoxOffset, imgRoi.Left), imgRoi.Right);
  3971. int correctedLesionTop = Math.Min(Math.Max(lesionRoi.Top - boundBoxOffset, imgRoi.Top), imgRoi.Bottom);
  3972. int correctedLesionBottom = Math.Min(Math.Max(lesionRoi.Bottom + boundBoxOffset, imgRoi.Top), imgRoi.Bottom);
  3973. if (correctedLesionRight < correctedLesionLeft)
  3974. {
  3975. correctedLesionRight = correctedLesionLeft;
  3976. }
  3977. if (correctedLesionBottom < correctedLesionTop)
  3978. {
  3979. correctedLesionBottom = correctedLesionTop;
  3980. }
  3981. int correctedLesionWidth = correctedLesionRight - correctedLesionLeft;
  3982. int correctedLesionHeight = correctedLesionBottom - correctedLesionTop;
  3983. return new AI.Common.Interface.Rect(correctedLesionLeft, correctedLesionTop, correctedLesionWidth, correctedLesionHeight);
  3984. }
  3985. private void OnDBAllModelResultPredictImages(object sender, RoutedEventArgs e)
  3986. {
  3987. OpenFileDialog openFileDialog = new OpenFileDialog();
  3988. openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
  3989. openFileDialog.Multiselect = true;
  3990. openFileDialog.Title = "选择一幅或多幅图像";
  3991. if (openFileDialog.ShowDialog() ?? false)
  3992. {
  3993. foreach (string filename in openFileDialog.FileNames)
  3994. {
  3995. Bitmap img = new Bitmap(filename);
  3996. _currentImg = img;
  3997. string temp;
  3998. int idx = filename.LastIndexOf("\\");
  3999. temp = filename.Substring(idx);
  4000. string[] strs1 = temp.Split('\\');
  4001. temp = strs1[1];
  4002. string[] sArray = null;
  4003. sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  4004. string ImgId = sArray[0];
  4005. //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
  4006. _currentImgId = ImgId;
  4007. int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
  4008. if (imgIdx < 0)
  4009. {
  4010. WriteTxtToFile("E:\\image\\", "notname.txt", ImgId, false);
  4011. //continue;
  4012. }
  4013. _currentImgIdex = imgIdx;
  4014. DescriAlgorithmModelAll(ImgId,false);
  4015. }
  4016. }
  4017. Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
  4018. Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
  4019. Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
  4020. Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
  4021. Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
  4022. Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
  4023. Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
  4024. Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
  4025. Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
  4026. Console.WriteLine();
  4027. Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
  4028. Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
  4029. Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
  4030. Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
  4031. Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
  4032. Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
  4033. Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
  4034. Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
  4035. Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
  4036. Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
  4037. Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
  4038. Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
  4039. Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
  4040. Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
  4041. Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
  4042. Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
  4043. Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
  4044. Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
  4045. Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
  4046. Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
  4047. Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
  4048. Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
  4049. Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
  4050. Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
  4051. Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
  4052. Console.WriteLine();
  4053. Console.WriteLine("形状: ");
  4054. Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
  4055. Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
  4056. Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
  4057. Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
  4058. Console.WriteLine();
  4059. Console.WriteLine("边缘: ");
  4060. Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
  4061. Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
  4062. Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
  4063. Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
  4064. Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
  4065. Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
  4066. Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
  4067. Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
  4068. Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
  4069. Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
  4070. Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
  4071. Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
  4072. Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
  4073. Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
  4074. Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
  4075. Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
  4076. Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
  4077. Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
  4078. Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
  4079. Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
  4080. Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
  4081. Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
  4082. Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
  4083. Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
  4084. Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
  4085. Console.WriteLine();
  4086. }
  4087. public void SaveModelResult(Bitmap image, int imageId, string imageName,string descriptionMargin)
  4088. {
  4089. _currentBinPath = System.Environment.CurrentDirectory;
  4090. string newPath = System.IO.Path.Combine(_currentBinPath, "result");
  4091. System.IO.Directory.CreateDirectory(newPath);
  4092. int imgNum = _allImgInfo.Count;
  4093. if (image == null || _allImgInfo.Count <= 0)
  4094. {
  4095. return;
  4096. }
  4097. //List<MyPoint> thyroidCont = _allImgInfo[imageId].ThyroidContour;
  4098. //int num1 = thyroidCont.Count;
  4099. int path = 0;
  4100. if (_allImgInfo[imageId].Lesions.Count <= 0)
  4101. {
  4102. string name = newPath + "\\" + imageName + "_M.png";
  4103. //image.Save(name, System.Drawing.Imaging.ImageFormat.Png);
  4104. }
  4105. else
  4106. {
  4107. Bitmap origImg = image;
  4108. using (var g = Graphics.FromImage(origImg))
  4109. {
  4110. System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
  4111. //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
  4112. //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
  4113. //System.Drawing.PointF[] thyroidContour = new PointF[num1];
  4114. Font drawFont = new Font("黑体", 24);
  4115. SolidBrush drawBrush = new SolidBrush(Color.GreenYellow);
  4116. float x = 10.0f;
  4117. float y = 0.0f + 20;
  4118. string drawText = descriptionMargin;//
  4119. g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * 4);
  4120. //drawText = shape;
  4121. //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 1));
  4122. //drawText = margin;
  4123. //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 2));
  4124. //drawText = echogenicFoci;
  4125. //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 3));
  4126. g.Dispose();
  4127. }
  4128. string name = newPath + "\\" + imageName + "_M.png";
  4129. origImg.Save(name, System.Drawing.Imaging.ImageFormat.Png);
  4130. origImg.Dispose();
  4131. }
  4132. }
  4133. }
  4134. }