12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403 |
- using DescriptionDeeplearn;
- using Microsoft.Win32;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Data.SQLite;
- using System.Drawing;
- using System.Drawing.Imaging;
- ///for DllImport
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Security.Cryptography;
- using System.Text;
- using System.Windows;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
- using System.Xml.Linq;
- using System.Windows.Controls;
- using AI.Common.Interface;
- using System.Xml.Linq;
- using AI.Common.Implements;
- using RawImageShowUtilsLib;
- using AIModuleResultShowUtilsLib;
- using System.Reflection;
- namespace ThyroidDescriptionUI
- {
- /// <summary>
- /// Interaction logic for MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- #region private variables
- private BitmapImage _origImg;
- private BitmapImage _dstImg;
- private Queue<Bitmap> _imagesReadyToDrawBox = new Queue<Bitmap>();
- private Queue<SegDataInput> _testDatas = new Queue<SegDataInput>();
- private System.Windows.Media.Brush _roiColor = System.Windows.Media.Brushes.Orange;
- private System.Drawing.Rectangle _drawingRoi = System.Drawing.Rectangle.Empty;
- private Bitmap _currentImg;
- private Queue<string> _imgNameQueue = new Queue<string>(); // 图像文件名(循环读图)
- private List<string> _imgNameList = new List<string>(); // 图像文件名
- #endregion
- //private AIDiagSystem _aiSeg;
- private List<GTImgInfo> _allImgInfo;
- private string _currentImgId;
- private int _currentImgIdex;
- private string _currentBinPath;
- private Bitmap _showImg;
- private string _dbPathChoose;
- private string _imgPathChoose;
- private ProcessData _UseNet = null;
- private DescriptionCoreDeeplearning _inferNet = null;
- private string _netsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
- private readonly DescriptionDeeplearn.InferenceCore _inferCore = new DescriptionDeeplearn.InferenceCore();
- private readonly DescriptionDeeplearn.EnumDeviceType _deviceType = DescriptionDeeplearn.EnumDeviceType.CPU;
- //
- private IModule _module;
- //private string _currentPath;
- private InferenceConfig _inferConfig = new InferenceConfig();
- private string _netDir = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Networks");
- private volatile string _processId = string.Empty;
- private volatile string _caseId = string.Empty;
- private volatile string _dataId = string.Empty;
- private volatile bool _readingVideo;
- private volatile int _frameIndex;
- //局灶性强回声
- private int _NoCifications_NoCifications_num = 0; //无钙化 判为 无钙化
- private int _NoCifications_Coarsecalcifications_num = 0;
- private int _NoCifications_Macrocalcifications_num = 0;
- private int _Coarsecalcifications_Coarsecalcifications_num = 0; //粗钙化 判为 粗钙化
- private int _Coarsecalcifications_NoCifications_num = 0;
- private int _Coarsecalcifications_Macrocalcifications_num = 0;
- private int _Macrocalcifications_Macrocalcifications_num = 0; //微钙化 判为 微钙化
- private int _Macrocalcifications_NoCifications_num = 0;
- private int _Macrocalcifications_Coarsecalcifications_num = 0;
- //回声
- private int _Anechoic_Anechoi_num = 0; //无回声 判为 无回声 的数目
- private int _Anechoic_Hyperechoic_num = 0; //无回声 判为 高回声 的数目
- private int _Anechoic_Isoechoic_num = 0;
- private int _Anechoic_Hypoechoic_num = 0;
- private int _Anechoic_HypoechoicLower_num = 0;
- private int _Hyperechoic_Hyperechoic_num = 0; //高回声 判为 高回声
- private int _Hyperechoic_Anechoic_num = 0;
- private int _Hyperechoic_Isoechoic_num = 0;
- private int _Hyperechoic_Hypoechoic_num = 0;
- private int _Hyperechoic_HypoechoicLower_num = 0;
- private int _Isoechoic_Isoechoic_num = 0; //等回声 判为 等回声
- private int _Isoechoic_Anechoic_num = 0;
- private int _Isoechoic_Hyperechoic_num = 0;
- private int _Isoechoic_Hypoechoic_num = 0;
- private int _Isoechoic_HypoechoicLower_num = 0;
- private int _Hypoechoic_Hypoechoic_num = 0; //低回声 判为 低回声
- private int _Hypoechoic_Anechoic_num = 0;
- private int _Hypoechoic_Hyperechoic_num = 0;
- private int _Hypoechoic_Isoechoic_num = 0;
- private int _Hypoechoic_HypoechoicLower_num = 0;
- private int _HypoechoicLower_HypoechoicLower_num = 0; //极低回声 判为 极低回声
- private int _HypoechoicLower_Anechoicr_num = 0;
- private int _HypoechoicLower_Hyperechoic_num = 0;
- private int _HypoechoicLower_Isoechoic_num = 0;
- private int _HypoechoicLower_Hypoechoic_num = 0;
- //形状
- private int _WT_WT_num = 0; //宽大于高 判为 宽大于高
- private int _WT_TW_num = 0; //宽大于高 判为 高大于宽
- private int _TW_TW_num = 0; //高大于宽 判为 高大于宽
- private int _TW_WT_num = 0; //高大于宽 判为 宽大于高
- //边缘
- int _Smooth_Smooth_num = 0; //光整 判为 模糊
- int _Smooth_IllDefined_num = 0;
- int _Smooth_Lobulated_num = 0;
- int _Smooth_Irregular_num = 0;
- int _Smooth_ExtraThyroidalExtension_num = 0;
- int _IllDefined_IllDefined_num = 0; //模糊 判为 模糊
- int _IllDefined_Smooth_num = 0;
- int _IllDefined_Lobulated_num = 0;
- int _IllDefined_Irregular_num = 0;
- int _IllDefined_ExtraThyroidalExtension_num = 0;
- int _Lobulated_Lobulated_num = 0; //分叶 判为 分叶
- int _Lobulated_Smooth_num = 0;
- int _Lobulated_IllDefined_num = 0;
- int _Lobulated_Irregular_num = 0;
- int _Lobulated_ExtraThyroidalExtension_num = 0;
- int _Irregular_Irregular_num = 0; //不规则 判为 不规则
- int _Irregular_Smooth_num = 0;
- int _Irregular_IllDefined_num = 0;
- int _Irregular_Lobulated_num = 0;
- int _Irregular_ExtraThyroidalExtension_num = 0;
- int _ExtraThyroidalExtension_ExtraThyroidalExtension_num = 0; //甲状腺外侵犯 判为 甲状腺外侵犯
- int _ExtraThyroidalExtension_Smooth_num = 0;
- int _ExtraThyroidalExtension_IllDefined_num = 0;
- int _ExtraThyroidalExtension_Lobulated_num = 0;
- int _ExtraThyroidalExtension_Irregular_num = 0;
- int testNUm = 0;
- public MainWindow()
- {
- InitializeComponent();
- _origImg = null;
- _dstImg = null;
- OrigImage.Source = _origImg;
- DstImage.Source = _dstImg;
- _showImg = null;
- _currentBinPath = System.Environment.CurrentDirectory;
- //button1.Visibility = Visibility.Collapsed;
- _module = new AI.Vaid.Modules.ThyroidLesionDetect.ThyroidLesionDetect(_netDir, _inferConfig, AI.Common.Interface.EnumDeviceType.CPU);
- }
- private void OnWindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- }
- private void OnErrorOccur(object sender, ErrorEventArgs e)
- {
- MessageBox.Show("接收到task发出的错误:" + e.GetException());
- }
- [DllImport(@"LesionAxis.dll", CallingConvention = CallingConvention.Cdecl)]
- public static unsafe extern void MyLesionAxisProcess(roiCoor roiVec, int ptsNum, StructPoint[] lesionPts, ref AxisPoint axis);
- [DllImport(@"BreastLesionSeg.dll", CallingConvention = CallingConvention.Cdecl)]
- public static unsafe extern int ContourDetectBLS(byte[] img_data, int channels, int img_width, int img_height,
- roiCoor roi_vec, [In, Out] StructPoint[] contour_points);
- [DllImport(@"BreastLesionSeg.dll", CallingConvention = CallingConvention.Cdecl)]
- public static unsafe extern int ContourDetectBLSForThyroid(byte[] img_data, int channels, int img_width, int img_height,
- roiCoor roi_vec, [In, Out] StructPoint[] contour_points);
- [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescription(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
- StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, ref LesionDescri lesionDescr);
- [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescriptionGetLesionPart(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
- StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, int index, char[] imgName);
- [DllImport(@"ThyroidLesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescriptionModelAfterProcess_1(byte[] imgDataModel, int imgWModel, int imgHModel, int channelModel, roiCoor roiVecModel,
- byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
- StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, ref LesionDescri lesionDescr);
- [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
- ///与病灶细分割配合使用
- public static extern void ThyroidDescriptionContour(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1, StructPoint[] lesionPts
- , ref roiCoor roi);
- [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescriptionModelProcess(byte[] imgData, int channels, int imgW, int imgH, roiCoor roiVec, int ptsNum1,
- StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts, int modelW, int modelH, int modelChannel,
- ref roiCoor roiDst, byte[] imgDataDst);
- [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescriptionModelProcessModelImage(byte[] imgModelData, int imgModelW,
- int imgModelH, int channelModel, roiCoor roiModelVec,
- ref int contourNum, int[] contourLen, [In, Out] StructPoint[] calcificationPts);
- [DllImport(@"LesionDescription.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void ThyroidDescriptionModelAfterProcess(byte[] imgData, int channels, int imgW, int imgH, /*roiCoor roiVec,*/ int ptsNum1,
- StructPoint[] thyroidPts, int ptsNum2, StructPoint[] lesionPts,
- int contourNum, int[] contourLen, StructPoint[] calcificationPts, roiCoor roiVecModel, ref LesionDescri lesionDescr);
- [DllImport(@"tools.dll", CallingConvention = CallingConvention.Cdecl)]
- public static extern void video2image();
- /// 更新显示已有的轮廓
- private void ShowContour()
- {
- if (_origImg == null || _allImgInfo.Count <= 0)
- {
- return;
- }
- // 显示甲状腺轮廓
- List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
- int num1 = thyroidCont.Count;
- if (_allImgInfo[_currentImgIdex].Lesions.Count <= 0)
- {
- return;
- }
- // 显示新的病灶
- //LesionInfo lesion = _allImgInfo[_currentImgIdex].Lesions[0];
- //int num2 = lesion.LesionContour.Count;
- Bitmap origImg = (Bitmap)_currentImg.Clone();
- using (var g = Graphics.FromImage(origImg))
- {
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
- //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- System.Drawing.PointF[] thyroidContour = new PointF[num1];
- for (int i = 0; i < num1; i++)
- {
- thyroidContour[i].X = thyroidCont[i].X;
- thyroidContour[i].Y = thyroidCont[i].Y;
- }
- int numLesion = _allImgInfo[_currentImgIdex].Lesions.Count;
- System.Drawing.PointF[][] lesionContours = new PointF[numLesion][];
- for (int ni = 0; ni < numLesion; ni++)
- {
- int num = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour.Count;
- lesionContours[ni] = new PointF[num];
- for (int nj = 0; nj < num; nj++)
- {
- lesionContours[ni][nj].X = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour[nj].X;
- lesionContours[ni][nj].Y = _allImgInfo[_currentImgIdex].Lesions[ni].LesionContour[nj].Y;
- }
- }
- //画点
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
- for (int ni = 0; ni < numLesion; ni++)
- {
- if (lesionContours[ni] != null)
- {
- g.DrawLines(pen, lesionContours[ni]); //画病灶轮廓
- }
- }
- pen.Dispose();
- if (num1 > 0)
- {
- System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
- g.DrawLines(pen2, thyroidContour); //画甲状腺轮廓
- pen2.Dispose();
- }
- for (int ni = 0; ni < numLesion; ni++)
- {
- LesionInfo lesion = _allImgInfo[_currentImgIdex].Lesions[ni];
- System.Drawing.PointF[] axisH = new PointF[2];
- System.Drawing.PointF[] axisV = new PointF[2];
- axisH[0].X = lesion.HorizontalPoint1.X;
- axisH[0].Y = lesion.HorizontalPoint1.Y;
- axisH[1].X = lesion.HorizontalPoint2.X;
- axisH[1].Y = lesion.HorizontalPoint2.Y;
- axisV[0].X = lesion.VerticalPoint1.X;
- axisV[0].Y = lesion.VerticalPoint1.Y;
- axisV[1].X = lesion.VerticalPoint2.X;
- axisV[1].Y = lesion.VerticalPoint2.Y;
- //画轮廓的长短轴
- System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
- g.DrawLines(pen_h, axisH); //横轴,浅绿色
- System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
- g.DrawLines(pen_v, axisV); //纵轴,红色
- }
- g.Dispose();
- }
- //origImg.Save("E:\\SVN\\Trunk\\SourceCode\\OnGoingTasks\\ThyroidLesionDetect\\SourceCode\\ThyroidDescriptionCore\\Bin\\1.jpg");
- _showImg = origImg;
- _origImg = ImageUtility.BitmapToBitmapImage(origImg);
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- OrigImage.Source = _origImg;
- }));
- origImg.Dispose();
- }
- private void OnLoadDataBaseClick(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "数据库文件|*.db";
- openFileDialog.Multiselect = false;
- openFileDialog.Title = "选择一个数据库文件";
- string dbPath = "";
- if (openFileDialog.ShowDialog() ?? false)
- {
- dbPath = openFileDialog.FileName;
- }
- DataBase dataBase = new DataBase(dbPath);
- bool readDb = dataBase.ReadDataBase();
- if (readDb)
- {
- _allImgInfo = dataBase._allImages;
- if (_allImgInfo.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- }
- // 加载1张图像
- private void OnLoadOneImageClick(object sender, RoutedEventArgs e)
- {
- if (DstImage.Source != null)
- {
- DstImage.Source = null;
- }
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = false;
- openFileDialog.Title = "选择一幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- Bitmap img = new Bitmap(openFileDialog.FileName);
- string temp = openFileDialog.FileName;
- int idx = temp.LastIndexOf("\\");
- temp = temp.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- //string[] strs2 = temp.Split(new char[4] { '.','j','p','g'}, 2);
- string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- _currentImgId = strs2[0];
- _currentImg = img;
- }
- _origImg = ImageUtility.BitmapToBitmapImage(_currentImg);
- OrigImage.Source = _origImg.Clone();
- int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
- if (imgIdx < 0)
- {
- return;
- }
- _currentImgIdex = imgIdx;
- DstImage.Source = _origImg.Clone();
- ShowContour();
- int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
- if (LesionsNum > 0)
- {
- int lesionNum = 0;
- string strDescriptionEcho = string.Empty;
- string strDescriptionShape = string.Empty;
- string strDescriptionMargin = string.Empty;
- string strDescriptionEchogenicFoci = string.Empty;
- for (int ii = 0; ii < LesionsNum; ii++)
- {
- EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
- ShapeEnum shapeGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
- MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
- EchogenicFociEnum echogenicFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
- string strEcho = string.Empty;
- if (echoGT == EchoPatternEnum.Anechoic)
- {
- strEcho = "无回声";
- }
- else if (echoGT == EchoPatternEnum.Hyperechoic)
- {
- strEcho = "高回声";
- }
- else if (echoGT == EchoPatternEnum.Isoechoic)
- {
- strEcho = "等回声";
- }
- else if (echoGT == EchoPatternEnum.Hypoechoic)
- {
- strEcho = "低回声";
- }
- else if (echoGT == EchoPatternEnum.HypoechoicLower)
- {
- strEcho = "极低回声";
- }
- strDescriptionEcho += lesionNum.ToString() + ":" + strEcho + "\r\n";
- string strShape = string.Empty;
- if (shapeGT == ShapeEnum.WiderThanTall)
- {
- strShape = "宽大于高";
- }
- else if (shapeGT == ShapeEnum.TallThanWider)
- {
- strShape = "高大于宽";
- }
- strDescriptionShape += lesionNum.ToString() + ":" + strShape + "\r\n";
- string strMargin = string.Empty;
- if (marginGT == MarginEnum.Smooth)
- {
- strMargin = "边缘光整";
- }
- else if (marginGT == MarginEnum.IllDefined)
- {
- strMargin = "边缘模糊";
- }
- else if (marginGT == MarginEnum.Lobulated)
- {
- strMargin = "边缘分叶状";
- }
- else if (marginGT == MarginEnum.Irregular)
- {
- strMargin = "边缘不规则";
- }
- else if (marginGT == MarginEnum.ExtraThyroidalExtension)
- {
- strMargin = "甲状腺外侵犯";
- }
- strDescriptionMargin += lesionNum.ToString() + ":" + strMargin + "\r\n";
- string strEchogenicFoci = string.Empty;
- if (echogenicFociGT == EchogenicFociEnum.NoCifications)
- {
- strEchogenicFoci = "无钙化";
- }
- else if (echogenicFociGT == EchogenicFociEnum.Coarsecalcifications)
- {
- strEchogenicFoci = "粗钙化";
- }
- else if (echogenicFociGT == EchogenicFociEnum.Microcalcifications)
- {
- strEchogenicFoci = "微钙化";
- }
- strDescriptionEchogenicFoci += lesionNum.ToString() + ":" + strEchogenicFoci + "\r\n";
- lesionNum++;
- }
- EchoPatternDescriGT.Text = strDescriptionEcho;
- ShapeDescriGT.Text = strDescriptionShape;
- MarginDescriGT.Text = strDescriptionMargin;
- EchogenicFociDescriGT.Text = strDescriptionEchogenicFoci;
- }
- else
- {
- MessageBox.Show("请先加载待测图像!");
- }
- }
- private void OnThyroidDescriClick(object sender, RoutedEventArgs e)
- {
- if (_currentImg != null)
- {
- string name = "sos";
- DoDescriAlgorithm(name);
- }
- else
- {
- MessageBox.Show("请先加载待测图像!");
- }
- }
- //甲状腺描述算法调用接口
- private void DoDescriAlgorithm(string name)
- {
- if (_currentImg == null)
- {
- MessageBox.Show("请先加载待测图像!");
- return;
- }
- Bitmap bmp = _currentImg;
- RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
- int channel = BitmapChannel(bmp);
- roiCoor roi;
- roi.x = 0;
- roi.y = 0;
- roi.width = _currentImg.Width;
- roi.height = _currentImg.Height;
- int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
- int ThyroidNum = _allImgInfo[_currentImgIdex].ThyroidContour.Count;
- //确定存在病灶
- if (LesionsNum > 0 && ThyroidNum > 0)
- {
- Bitmap dstimage = (Bitmap)_currentImg.Clone();
- int lesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
- for (int ii = 0; ii < lesionsNum; ii++)
- {
- //获取病灶轮廓
- int num2 = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour.Count;
- StructPoint[] lesionPts = new StructPoint[num2];
- System.Drawing.PointF[] lesionContour = new PointF[num2];
- for (int i = 0; i < num2; i++)
- {
- lesionPts[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
- lesionPts[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
- lesionContour[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
- lesionContour[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
- }
- //获取甲状腺轮廓
- List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
- int num1 = thyroidCont.Count;
- StructPoint[] thyroidPts = new StructPoint[num1];
- System.Drawing.PointF[] thyroidContour = new PointF[num1];
- for (int i = 0; i < num1; i++)
- {
- thyroidPts[i].X = thyroidCont[i].X;
- thyroidPts[i].Y = thyroidCont[i].Y;
- thyroidContour[i].X = thyroidCont[i].X;
- thyroidContour[i].Y = thyroidCont[i].Y;
- }
- EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
- EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
- ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
- MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
- LesionDescri desCpp = new LesionDescri();
- desCpp.echo = 0;
- desCpp.shape = 0;
- desCpp.margin = 0;
- desCpp.echogenicFoci = 0;
- desCpp.axisPt = new AxisPoint();
- desCpp.axisPt.horizontalPt1 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.horizontalPt2 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.verticalPt1 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.verticalPt2 = new StructPoint { X = 0, Y = 0 };
- System.Drawing.PointF[] axisH = new PointF[2];
- System.Drawing.PointF[] axisV = new PointF[2];
- //WriteTxtToFile("E:\\image\\", "usename.txt", name, false);
- var starttime = Environment.TickCount;
- ThyroidDescription(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
- roi, num1, thyroidPts, num2, lesionPts, ref desCpp);
- ThyroidDescriptionGetLesionPart(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
- roi, num1, thyroidPts, num2, lesionPts, ii, name.ToCharArray());
- var endtime = Environment.TickCount;
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- ElapsedTime.Text = (endtime - starttime).ToString();
- }));
- int echoCpp = desCpp.echo; // 回声
- int shapeCpp = desCpp.shape; // 形状
- int marginCpp = desCpp.margin; // 边缘
- int echogenicFociCpp = desCpp.echogenicFoci; // 局灶性强回声
- EchogenicFociEnum echoFoci = (EchogenicFociEnum)desCpp.echogenicFoci;
- EchoPatternEnum echo = (EchoPatternEnum)desCpp.echo;
- ShapeEnum shape = (ShapeEnum)desCpp.shape;
- MarginEnum margin = (MarginEnum)desCpp.margin;
- AxisPoint axisPoint = desCpp.axisPt; // 纵、横轴端点坐标
- StructPoint pt1 = axisPoint.horizontalPt1; // 横轴
- StructPoint pt2 = axisPoint.horizontalPt2;
- StructPoint pt3 = axisPoint.verticalPt1; // 纵轴
- StructPoint pt4 = axisPoint.verticalPt2;
- axisH[0].X = pt1.X;
- axisH[0].Y = pt1.Y;
- axisH[1].X = pt2.X;
- axisH[1].Y = pt2.Y;
- axisV[0].X = pt3.X;
- axisV[0].Y = pt3.Y;
- axisV[1].X = pt4.X;
- axisV[1].Y = pt4.Y;
- int resCa = -1;
- int resEcho = -1;
- int resShape = -1;
- //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- if (echoCpp == (int)EchoPatternEnum.Anechoic)
- {
- EchoPatternDescri.Text = "无回声";
- resEcho = 0;
- }
- else if (echoCpp == (int)EchoPatternEnum.Hyperechoic)
- {
- EchoPatternDescri.Text = "高回声";
- resEcho = 1;
- }
- else if (echoCpp == (int)EchoPatternEnum.Isoechoic)
- {
- EchoPatternDescri.Text = "等回声";
- resEcho = 2;
- }
- else if (echoCpp == (int)EchoPatternEnum.Hypoechoic)
- {
- EchoPatternDescri.Text = "低回声";
- resEcho = 3;
- }
- else if (echoCpp == (int)EchoPatternEnum.HypoechoicLower)
- {
- EchoPatternDescri.Text = "极低回声";
- resEcho = 4;
- }
- if (shapeCpp == (int)ShapeEnum.WiderThanTall)
- {
- ShapeDescri.Text = "宽大于高";
- resShape = 0;
- }
- else if (shapeCpp == (int)ShapeEnum.TallThanWider)
- {
- ShapeDescri.Text = "高大于宽";
- resShape = 1;
- }
- if (marginCpp == (int)MarginEnum.Smooth)
- {
- MarginDescri.Text = "边缘光整";
- }
- else if (marginCpp == (int)MarginEnum.IllDefined)
- {
- MarginDescri.Text = "边缘模糊";
- }
- else if (marginCpp == (int)MarginEnum.Lobulated)
- {
- MarginDescri.Text = "边缘分叶状";
- }
- else if (marginCpp == (int)MarginEnum.Irregular)
- {
- MarginDescri.Text = "边缘不规则";
- }
- else if (marginCpp == (int)MarginEnum.ExtraThyroidalExtension)
- {
- MarginDescri.Text = "甲状腺外侵犯";
- }
- if (echogenicFociCpp == (int)EchogenicFociEnum.NoCifications)
- {
- EchogenicFociDescri.Text = "无钙化";
- resCa = 0;
- }
- else if (echogenicFociCpp == (int)EchogenicFociEnum.Coarsecalcifications)
- {
- EchogenicFociDescri.Text = "粗钙化";
- resCa = 1;
- }
- else if (echogenicFociCpp == (int)EchogenicFociEnum.Microcalcifications)
- {
- EchogenicFociDescri.Text = "微钙化";
- resCa = 2;
- }
- }
- //));
- //////////////
- string newPath = System.IO.Path.Combine(_currentBinPath, "result");
- //if (resCa == 0)
- //{
- // string nameSave = newPath + "\\00\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resCa == 1)
- //{
- // string nameSave = newPath + "\\01\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resCa == 2)
- //{
- // string nameSave = newPath + "\\02\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //if (resEcho == 0)
- //{
- // string nameSave = newPath + "\\00\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resEcho == 1)
- //{
- // string nameSave = newPath + "\\01\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resEcho == 2)
- //{
- // string nameSave = newPath + "\\02\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resEcho == 3)
- //{
- // string nameSave = newPath + "\\03\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- //else if (resEcho == 4)
- //{
- // string nameSave = newPath + "\\04\\" + name + ".jpg";
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //}
- if (resShape == 0)
- {
- string nameSave = newPath + "\\00\\" + name + ".jpg";
- if (shapeCppGT == ShapeEnum.WiderThanTall)
- {
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- else if (resShape == 1)
- {
- string nameSave = newPath + "\\01\\" + name + ".jpg";
- if (shapeCppGT == ShapeEnum.WiderThanTall)
- {
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- if (echoFociGT == echoFoci)
- {
- if (echoFoci == EchogenicFociEnum.NoCifications)
- {
- _NoCifications_NoCifications_num++;
- //result = 1;
- }
- if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Coarsecalcifications_Coarsecalcifications_num++;
- //result = 2;
- }
- if (echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Macrocalcifications_Macrocalcifications_num++;
- //result = 3;
- }
- }
- else
- {
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _NoCifications_Coarsecalcifications_num++;
- //result = 4;
- }
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _NoCifications_Macrocalcifications_num++;
- //result = 5;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Coarsecalcifications_NoCifications_num++;
- //result = 6;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Coarsecalcifications_Macrocalcifications_num++;
- //result = 7;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Macrocalcifications_NoCifications_num++;
- //result = 8;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Macrocalcifications_Coarsecalcifications_num++;
- //result = 9;
- }
- }
- if (echoGT == echo)
- {
- if (echo == EchoPatternEnum.Anechoic)
- {
- _Anechoic_Anechoi_num++;
- }
- if (echo == EchoPatternEnum.Hyperechoic)
- {
- _Hyperechoic_Hyperechoic_num++;
- }
- if (echo == EchoPatternEnum.Isoechoic)
- {
- _Isoechoic_Isoechoic_num++;
- }
- if (echo == EchoPatternEnum.Hypoechoic)
- {
- _Hypoechoic_Hypoechoic_num++;
- }
- if (echo == EchoPatternEnum.HypoechoicLower)
- {
- _HypoechoicLower_HypoechoicLower_num++;
- }
- }
- else
- {
- //把无回声判为其它
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Anechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Anechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Anechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Anechoic_HypoechoicLower_num++;
- }
- //把高回声判为其它
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hyperechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hyperechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Hyperechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hyperechoic_HypoechoicLower_num++;
- }
- //把等回声判为其它
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Isoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Isoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Isoechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Isoechoic_HypoechoicLower_num++;
- }
- //低回声判为其它
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hypoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Hypoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hypoechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hypoechoic_HypoechoicLower_num++;
- }
- //极低回声判为其它
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
- {
- _HypoechoicLower_Anechoicr_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
- {
- _HypoechoicLower_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
- {
- _HypoechoicLower_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
- {
- _HypoechoicLower_Hypoechoic_num++;
- }
- }
- if (shapeCppGT == shape)
- {
- if (shape == ShapeEnum.WiderThanTall)
- {
- _WT_WT_num++;
- }
- if (shape == ShapeEnum.TallThanWider)
- {
- _TW_TW_num++;
- }
- }
- else
- {
- //把 宽大于高 判为 高大于宽
- if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
- {
- _WT_TW_num++;
- }
- if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
- {
- _TW_WT_num++;
- }
- }
- if (marginGT == margin)
- {
- if (margin == MarginEnum.Smooth)
- {
- _Smooth_Smooth_num++;
- }
- if (margin == MarginEnum.IllDefined)
- {
- _IllDefined_IllDefined_num++;
- }
- if (margin == MarginEnum.Lobulated)
- {
- _Lobulated_Lobulated_num++;
- }
- if (margin == MarginEnum.Irregular)
- {
- _Irregular_Irregular_num++;
- }
- if (margin == MarginEnum.ExtraThyroidalExtension)
- {
- _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
- }
- }
- else
- {
- //把 边缘光整 判成其它
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
- {
- _Smooth_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
- {
- _Smooth_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
- {
- _Smooth_Irregular_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Smooth_ExtraThyroidalExtension_num++;
- }
- //把 边缘模糊 判成其它
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
- {
- _IllDefined_Smooth_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
- {
- _IllDefined_Lobulated_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
- {
- _IllDefined_Irregular_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _IllDefined_ExtraThyroidalExtension_num++;
- }
- //把 边缘分叶状 判成其它
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
- {
- _Lobulated_Smooth_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
- {
- _Lobulated_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
- {
- _Lobulated_Irregular_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Lobulated_ExtraThyroidalExtension_num++;
- }
- //把 边缘不规则 判成其它
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
- {
- _Irregular_Smooth_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
- {
- _Irregular_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
- {
- _Irregular_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Irregular_ExtraThyroidalExtension_num++;
- }
- //把 甲状腺外侵犯 判成其它
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
- {
- _ExtraThyroidalExtension_Smooth_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
- {
- _ExtraThyroidalExtension_IllDefined_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
- {
- _ExtraThyroidalExtension_Lobulated_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
- {
- _ExtraThyroidalExtension_Irregular_num++;
- }
- }
- using (var g = Graphics.FromImage(dstimage))
- {
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
- g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- if (lesionContour.Length > 0)
- {
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
- g.DrawLines(pen, lesionContour); //画病灶轮廓
- System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
- if (thyroidContour.Length > 0)
- {
- g.DrawLines(pen2, thyroidContour); //画肝脏轮廓
- }
- pen.Dispose();
- }
- //画轮廓的长短轴
- System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
- g.DrawLines(pen_h, axisH); //横轴,浅绿色
- System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
- g.DrawLines(pen_v, axisV); //纵轴,红色
- g.Dispose();
- }
- }
- _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- DstImage.Source = _dstImg;
- }));
- dstimage.Dispose();
- }
- else
- {
- MessageBox.Show("未读取到病灶!");
- }
- }
- public static int BitmapChannel(Bitmap image, bool keepChannel = false)
- {
- int width = image.Width;
- int height = image.Height;
- PixelFormat pixelFormat = image.PixelFormat;
- if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
- pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
- pixelFormat != PixelFormat.Format8bppIndexed)
- {
- throw new Exception("Unexpected image pixel format:" + pixelFormat);
- }
- int origChannel = 3;
- if (pixelFormat == PixelFormat.Format24bppRgb)
- {
- origChannel = 3;
- }
- else if (pixelFormat == PixelFormat.Format8bppIndexed)
- {
- origChannel = 1;
- }
- else
- {
- origChannel = 4;
- }
- int dstChannel = 3;
- //if (keepChannel)
- //{
- // dstChannel = origChannel;
- //}
- dstChannel = origChannel;
- return dstChannel;
- }
- /// <summary>
- /// 将System.Drawimg.Bitmap转为RawImage
- /// </summary>
- /// <param name="image"></param>
- /// <param name="keepChannel"></param>
- /// <returns></returns>
- public static RawImage BitmapToRawImage(Bitmap image, bool keepChannel = false)
- {
- int width = image.Width;
- int height = image.Height;
- PixelFormat pixelFormat = image.PixelFormat;
- if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
- pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
- pixelFormat != PixelFormat.Format8bppIndexed)
- {
- throw new Exception("Unexpected image pixel format:" + pixelFormat);
- }
- int origChannel = 3;
- if (pixelFormat == PixelFormat.Format24bppRgb)
- {
- origChannel = 3;
- }
- else if (pixelFormat == PixelFormat.Format8bppIndexed)
- {
- origChannel = 1;
- }
- else
- {
- origChannel = 4;
- }
- int dstChannel = 3;
- if (keepChannel)
- {
- dstChannel = origChannel;
- }
- var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, pixelFormat);
- byte[] dstDataArray = new byte[width * height * dstChannel];
- unsafe
- {
- int stride = bmData.Stride;
- int dstStride = width * dstChannel;
- IntPtr ptr = bmData.Scan0;
- IntPtr ptrH, ptrW;
- for (int nh = 0; nh < height; nh++)
- {
- ptrH = IntPtr.Add(ptr, nh * stride);
- if (origChannel == dstChannel)
- {
- Marshal.Copy(ptrH, dstDataArray, nh * dstStride, dstStride);
- }
- else if (origChannel > dstChannel)
- {
- for (int nw = 0; nw < width; nw++)
- {
- ptrW = IntPtr.Add(ptrH, nw * origChannel);
- Marshal.Copy(ptrW, dstDataArray, nh * dstStride + nw * dstChannel, dstChannel);
- }
- }
- else
- {
- for (int nw = 0; nw < width; nw++)
- {
- ptrW = IntPtr.Add(ptrH, nw * origChannel);
- for (int nc = 0; nc < dstChannel; nc++)
- {
- Marshal.Copy(ptrW, dstDataArray, nh * dstStride + nw * dstChannel + nc, 1);
- }
- }
- }
- }
- }
- image.UnlockBits(bmData);
- //return new RawImage(dstDataArray, width, height, dstChannel);
- return new RawImage(dstDataArray, width, height, EnumColorType.Gray8);
- }
- //private RawImage AIBitmapToRawImage(Bitmap image)
- //{
- // int width = image.Width;
- // int height = image.Height;
- // AI.Common.Interface.EnumColorType ColorType = AI.Common.Interface.EnumColorType.Bgr;
- // int channel = 3;
- // PixelFormat pixelFormat = image.PixelFormat;
- // if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
- // pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
- // pixelFormat != PixelFormat.Format8bppIndexed)
- // {
- // throw new Exception("Unexpected image pixel format:" + pixelFormat);
- // }
- // if (pixelFormat == PixelFormat.Format24bppRgb)
- // {
- // channel = 3;
- // ColorType = AI.Common.Interface.EnumColorType.Bgr;
- // }
- // else if (pixelFormat == PixelFormat.Format8bppIndexed)
- // {
- // channel = 1;
- // ColorType = AI.Common.Interface.EnumColorType.Gray8;
- // }
- // else
- // {
- // channel = 4;
- // ColorType = AI.Common.Interface.EnumColorType.Bgra;
- // }
- // var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, pixelFormat);
- // byte[] srcDataArray = new byte[bmData.Stride * height];
- // byte[] dstDataArray = new byte[width * height * channel];
- // System.Runtime.InteropServices.Marshal.Copy(bmData.Scan0, srcDataArray, 0, bmData.Stride * height);
- // for (int nh = 0; nh < height; nh++)
- // {
- // Array.Copy(srcDataArray, nh * bmData.Stride, dstDataArray, nh * width * channel, width * channel);
- // }
- // image.UnlockBits(bmData);
- // return RawImage(dstDataArray, width, height, ColorType);
- //}
- //private RawImage BitmapToRawImage(Bitmap image)
- //{
- // int width = image.Width;
- // int height = image.Height;
- // int channel = 3;
- // PixelFormat pixelFormat = image.PixelFormat;
- // if (pixelFormat != PixelFormat.Format24bppRgb && pixelFormat != PixelFormat.Format32bppArgb &&
- // pixelFormat != PixelFormat.Format32bppPArgb && pixelFormat != PixelFormat.Format32bppRgb &&
- // pixelFormat != PixelFormat.Format8bppIndexed)
- // {
- // throw new Exception("Unexpected image pixel format:" + pixelFormat);
- // }
- // if (pixelFormat == PixelFormat.Format24bppRgb)
- // {
- // channel = 3;
- // }
- // else if (pixelFormat == PixelFormat.Format8bppIndexed)
- // {
- // channel = 1;
- // }
- // else
- // {
- // channel = 4;
- // }
- // var bmData = image.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, pixelFormat);
- // byte[] srcDataArray = new byte[bmData.Stride * height];
- // byte[] dstDataArray = new byte[width * height * channel];
- // System.Runtime.InteropServices.Marshal.Copy(bmData.Scan0, srcDataArray, 0, bmData.Stride * height);
- // for (int nh = 0; nh < height; nh++)
- // {
- // Array.Copy(srcDataArray, nh * bmData.Stride, dstDataArray, nh * width * channel, width * channel);
- // }
- // image.UnlockBits(bmData);
- // return new RawImage(dstDataArray, width, height, channel);
- //}
- public void Save(Bitmap image, int imageId,string imageName)
- {
- _currentBinPath = System.Environment.CurrentDirectory;
- string newPath = System.IO.Path.Combine(_currentBinPath, "result");
- System.IO.Directory.CreateDirectory(newPath);
- int imgNum = _allImgInfo.Count;
- if (image == null || _allImgInfo.Count <= 0)
- {
- return;
- }
- // 显示甲状腺轮廓
- List<MyPoint> thyroidCont = _allImgInfo[imageId].ThyroidContour;
- int num1 = thyroidCont.Count;
- int path = 0;
- if (_allImgInfo[imageId].Lesions.Count <= 0)
- {
- string name = newPath + "\\" + imageName + ".png";
- //image.Save(name, System.Drawing.Imaging.ImageFormat.Png);
- }
- else
- {
- int numLesions = _allImgInfo[imageId].Lesions.Count;
- Bitmap origImg = image;
- //int numLesions = _allImgInfo[imageId].Lesions.Count;
- for (int jj = 0; jj < numLesions; jj++)
- {
- EchoPatternEnum echoGT = _allImgInfo[imageId].Lesions[jj].EchoPattern;
- ShapeEnum shapeGT = _allImgInfo[imageId].Lesions[jj].Shape;
- MarginEnum marginGT = _allImgInfo[imageId].Lesions[jj].Margin;
- EchogenicFociEnum echogenicFociGT = _allImgInfo[imageId].Lesions[jj].EchogenicFoci;
- string echo = null, shape = null, margin = null, echogenicFoci = null;
- if (echoGT == EchoPatternEnum.Anechoic)
- {
- echo = "无回声";
- path = 0;
- }
- else if (echoGT == EchoPatternEnum.Hyperechoic)
- {
- echo = "高回声";
- path = 1;
- }
- else if (echoGT == EchoPatternEnum.Isoechoic)
- {
- echo = "等回声";
- path = 2;
- }
- else if (echoGT == EchoPatternEnum.Hypoechoic)
- {
- echo = "低回声";
- path = 3;
- }
- else if (echoGT == EchoPatternEnum.HypoechoicLower)
- {
- echo = "极低回声";
- path = 4;
- }
- if (shapeGT == ShapeEnum.WiderThanTall)
- {
- shape = "宽大于高";
- }
- else if (shapeGT == ShapeEnum.TallThanWider)
- {
- shape = "高大于宽";
- }
- if (marginGT == MarginEnum.Smooth)
- {
- margin = "边缘光整";
- }
- else if (marginGT == MarginEnum.IllDefined)
- {
- margin = "边缘模糊";
- }
- else if (marginGT == MarginEnum.Lobulated)
- {
- margin = "边缘分叶状";
- }
- else if (marginGT == MarginEnum.Irregular)
- {
- margin = "边缘不规则";
- }
- else if (marginGT == MarginEnum.ExtraThyroidalExtension)
- {
- margin = "甲状腺外侵犯";
- }
- if (echogenicFociGT == EchogenicFociEnum.NoCifications)
- {
- echogenicFoci = "无钙化";
- //path = 0;
- }
- else if (echogenicFociGT == EchogenicFociEnum.Coarsecalcifications)
- {
- echogenicFoci = "粗钙化";
- //path = 1;
- }
- else if (echogenicFociGT == EchogenicFociEnum.Microcalcifications)
- {
- echogenicFoci = "微钙化";
- //path = 2;
- }
- // 显示新的病灶
- LesionInfo lesion = _allImgInfo[imageId].Lesions[jj];
- int num2 = lesion.LesionContour.Count;
- using (var g = Graphics.FromImage(origImg))
- {
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
- //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- System.Drawing.PointF[] thyroidContour = new PointF[num1];
- for (int i = 0; i < num1; i++)
- {
- thyroidContour[i].X = thyroidCont[i].X;
- thyroidContour[i].Y = thyroidCont[i].Y;
- }
- System.Drawing.PointF[] lesionContour = new PointF[num2];
- for (int i = 0; i < num2; i++)
- {
- lesionContour[i].X = _allImgInfo[imageId].Lesions[jj].LesionContour[i].X;
- lesionContour[i].Y = _allImgInfo[imageId].Lesions[jj].LesionContour[i].Y;
- }
- if (num2 > 0)
- {
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
- g.DrawLines(pen, lesionContour); //画病灶轮廓
- pen.Dispose();
- }
- if (num1 > 0)
- {
- System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
- g.DrawLines(pen2, thyroidContour); //画甲状腺轮廓
- pen2.Dispose();
- }
- System.Drawing.PointF[] axisH = new PointF[2];
- System.Drawing.PointF[] axisV = new PointF[2];
- axisH[0].X = lesion.HorizontalPoint1.X;
- axisH[0].Y = lesion.HorizontalPoint1.Y;
- axisH[1].X = lesion.HorizontalPoint2.X;
- axisH[1].Y = lesion.HorizontalPoint2.Y;
- axisV[0].X = lesion.VerticalPoint1.X;
- axisV[0].Y = lesion.VerticalPoint1.Y;
- axisV[1].X = lesion.VerticalPoint2.X;
- axisV[1].Y = lesion.VerticalPoint2.Y;
- //画轮廓的长短轴
- System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
- g.DrawLines(pen_h, axisH); //横轴,浅绿色
- System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
- g.DrawLines(pen_v, axisV); //纵轴,红色
- //写汉字
- Font drawFont = new Font("黑体", 24);
- SolidBrush drawBrush = new SolidBrush(Color.GreenYellow);
- float x = 10.0f;
- float y = 0.0f + 20;
- string drawText = echo;//
- g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * 4 * jj);
- drawText = shape;
- g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 1));
- drawText = margin;
- g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 2));
- drawText = echogenicFoci;
- g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 3));
- //
- drawText = jj.ToString();
- g.DrawString(drawText, drawFont, drawBrush, axisH[0].X, axisH[0].Y);
- g.Dispose();
- }
- }
- string name = newPath + "\\" + imageName + ".png";
- origImg.Save(name, System.Drawing.Imaging.ImageFormat.Png);
- origImg.Dispose();
- }
- }
- /// <summary>
- /// 将医生的标注结果保存
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnLoadImageClick(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- Bitmap img = new Bitmap(filename);
- string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
- string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- string ImgId = strs2[0];
-
- int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
- int imageId = imgIdx;
- //_showImg = img;
- if(imageId >=0)
- {
- Save(img, imageId, ImgId);
- }
- }
- }
- }
- /// <summary>
- /// 将不同db文件复制到一个文件中(每个db文件中的图像可以选择,不需要db文件中全部图像)
- /// 最后获得的db文件不用先生成,由当前函数生成
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnCreatDbClick(object sender, RoutedEventArgs e)
- {
- string dataFolder = System.Environment.CurrentDirectory;
- _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
- _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_datas.db");
- if (_allImgInfo.Count <= 0)
- {
- MessageBox.Show("先加载数据库");
- }
- if (File.Exists(_dbPathChoose))
- {
- MessageBox.Show("数据库已存在");
- return;
- //throw new Exception("数据库已存在,请检查.");
- }
- else
- {
- DataBase db = new DataBase(_dbPathChoose);
- db.CreateDataBase(); //创建一个新的数据库文件
- }
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- //Bitmap img = new Bitmap(filename);
- string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
- string ImgId = strs2[0];
- int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
- int numLesions= _allImgInfo[imgIndex].Lesions.Count;
- if (imgIndex >= 0 && numLesions > 0)
- {
- AddExistImage(ImgId);
- ////AddNewImage(filename);
- //////////////////
- //int lesionsNum = _allImgInfo[imgIndex].Lesions.Count;
- //List<LesionInfo> tmpLe = new List<LesionInfo>();
- //LesionInfo tmp = new LesionInfo();
- //tmpLe = _allImgInfo[imgIndex].Lesions;
- //for (int jj = 0; jj < lesionsNum; jj++)
- //{
- // tmpLe[jj].HorizontalPoint1 = null;
- // tmpLe[jj].HorizontalPoint2 = null;
- // tmpLe[jj].VerticalPoint1 = null;
- // tmpLe[jj].VerticalPoint2 = null;
- // tmpLe[jj].EchoPattern = 0;
- // tmpLe[jj].Shape = 0;
- // tmpLe[jj].Margin = 0;
- // tmpLe[jj].EchogenicFoci = 0;
- //}
- //SetLesions(ImgId, tmpLe);
- ///////////////////////////////////
- SetLesions(ImgId, _allImgInfo[imgIndex].Lesions);
- SetThyroidContour(ImgId, _allImgInfo[imgIndex].ThyroidContour);
- }
- else
- {
- MessageBox.Show("Id未找到:" + ImgId);
- }
- }
- }
- }
- private string ComputeHashCode(byte[] input)
- {
- MD5 md5 = MD5.Create();
- byte[] hash = md5.ComputeHash(input);
- StringBuilder sb = new StringBuilder();
- foreach (var b in hash)
- {
- sb.Append(b.ToString("x2"));
- }
- string hashstr = sb.ToString();
- sb.Clear();
- return hashstr;
- }
- public void AddExistImage(string ImgId)
- {
- SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
- dbCon.Open();
- SQLiteCommand dbCmd;
- SQLiteDataReader dbReader;
- string hashCode = ImgId;///????
- // 查找该图片是否已经存在
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
- dbReader = dbCmd.ExecuteReader();
- if (dbReader.HasRows)
- {
- dbReader.Close();
- dbCmd.Dispose();
- //continue;
- return;
- }
- // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
- //string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
- //File.Copy(origImagePath, imgdstPath);
- // 将该图相关信息存到数据库里
- List<LesionInfo> lesions = new List<LesionInfo>();
- string strLesions = JsonConvert.SerializeObject(lesions);
- List<MyPoint> thyroidContour = new List<MyPoint>();
- string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
- dbCmd = dbCon.CreateCommand();
- //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
- dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- ///
- dbCon.Close();
- dbCon.Dispose();
- }
- public void AddNewImage(string origImagePath)
- {
- SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
- dbCon.Open();
- SQLiteCommand dbCmd;
- SQLiteDataReader dbReader;
- ///
- Bitmap image = new Bitmap(origImagePath);
- RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
- string hashCode = ComputeHashCode(rawImg.DataBuffer);
- image.Dispose();
- rawImg.Dispose();
- // 查找该图片是否已经存在
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
- dbReader = dbCmd.ExecuteReader();
- if (dbReader.HasRows)
- {
- dbReader.Close();
- dbCmd.Dispose();
- //continue;
- return;
- }
- // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
- //string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
- //File.Copy(origImagePath, imgdstPath);
- // 将该图相关信息存到数据库里
- List<LesionInfo> lesions = new List<LesionInfo>();
- string strLesions = JsonConvert.SerializeObject(lesions);
- List<MyPoint> thyroidContour = new List<MyPoint>();
- string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
- dbCmd = dbCon.CreateCommand();
- //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
- dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- ///
- dbCon.Close();
- dbCon.Dispose();
- }
- /// 添加图像到数据集里
- public void AddNewImages(string origImageFolder)
- {
- SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
- dbCon.Open();
- SQLiteCommand dbCmd;
- SQLiteDataReader dbReader;
- // 遍历该文件夹下所有图片
- DirectoryInfo origImgDir = new DirectoryInfo(origImageFolder);
- FileInfo[] files = origImgDir.GetFiles();
- foreach (var file in files)
- {
- Bitmap image = new Bitmap(file.FullName);
- RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
- string hashCode = ComputeHashCode(rawImg.DataBuffer);
- image.Dispose();
- rawImg.Dispose();
- // 查找该图片是否已经存在
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "select * from GTDatas where ImageId='" + hashCode + "'";
- dbReader = dbCmd.ExecuteReader();
- if (dbReader.HasRows)
- {
- dbReader.Close();
- dbCmd.Dispose();
- continue;
- }
- // 以哈希值作为该图片的id,同时也作为图像名,复制原始图像到指定目录下
- string imgdstPath = System.IO.Path.Combine(_imgPathChoose, hashCode + ".jpg");
- File.Copy(file.FullName, imgdstPath);
- // 将该图相关信息存到数据库里
- List<LesionInfo> lesions = new List<LesionInfo>();
- string strLesions = JsonConvert.SerializeObject(lesions);
- List<MyPoint> thyroidContour = new List<MyPoint>();
- string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
- dbCmd = dbCon.CreateCommand();
- //dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions) select '" + hashCode + "','" + strLesions + "'";
- dbCmd.CommandText = "insert into GTDatas(ImageId,Lesions,ThyroidContour) select '" + hashCode + "','" + strLesions + "','" + strThyroidCont + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- }
- dbCon.Close();
- dbCon.Dispose();
- }
- /// 设置该图像的病灶
- public void SetLesions(string imgId, List<LesionInfo> lesions)
- {
- try
- {
- SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
- dbCon.Open();
- SQLiteCommand dbCmd;
- dbCmd = dbCon.CreateCommand();
- string strLesions = JsonConvert.SerializeObject(lesions);
- dbCmd.CommandText = "update GTDatas set Lesions='" + strLesions + "' where ImageId='" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- SQLiteDataReader dbreader;
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "select * from LastModification";
- dbreader = dbCmd.ExecuteReader();
- if (dbreader.HasRows)
- {
- dbreader.Close();
- dbCmd.Dispose();
- // 更新
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "update LastModification set ImageId='" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- }
- else
- {
- // 新增
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "insert into LastModification(ImageId) select '" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- }
- dbCon.Close();
- dbCon.Dispose();
- }
- catch (Exception excep)
- {
- MessageBox.Show("保存病灶结果时出错!" + excep);
- }
- }
- public void SetThyroidContour(string imgId, List<MyPoint> thyroidContour)
- {
- try
- {
- SQLiteConnection dbCon = new SQLiteConnection("Data Source=" + _dbPathChoose);
- dbCon.Open();
- SQLiteCommand dbCmd;
- dbCmd = dbCon.CreateCommand();
- string strThyroidCont = JsonConvert.SerializeObject(thyroidContour);
- dbCmd.CommandText = "update GTDatas set ThyroidContour='" + strThyroidCont + "' where ImageId='" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- SQLiteDataReader dbreader;
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "select * from LastModification";
- dbreader = dbCmd.ExecuteReader();
- if (dbreader.HasRows)
- {
- dbreader.Close();
- dbCmd.Dispose();
- // 更新
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "update LastModification set ImageId='" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- }
- else
- {
- // 新增
- dbCmd = dbCon.CreateCommand();
- dbCmd.CommandText = "insert into LastModification(ImageId) select '" + imgId + "'";
- dbCmd.ExecuteNonQuery();
- dbCmd.Dispose();
- }
- dbCon.Close();
- dbCon.Dispose();
- }
- catch (Exception excep)
- {
- MessageBox.Show("保存甲状腺轮廓时出错!" + excep);
- }
- }
-
- private void OnLoadOneImagesClick(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- Bitmap img = new Bitmap(filename);
- _currentImg = img;
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
- //string ImgId = strs2[0];
- string[] sArray = null;
- sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- string ImgId = sArray[0];
- //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
- _currentImgId = ImgId;
- int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
- if (imgIdx < 0)
- {
- //return;
- continue;
- }else
- {
- _currentImgIdex = imgIdx;
- DoDescriAlgorithm(ImgId);
- }
-
- }
- }
- Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
- Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
- Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
- Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
- Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
- Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
- Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
- Console.WriteLine();
- Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
- Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
- Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
- Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
- Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
- Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
- Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
- Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
- Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
- Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
- Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
- Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
- Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
- Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
- Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
- Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
- Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
- Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
- Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
- Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
- Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
- Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
- Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
- Console.WriteLine();
- Console.WriteLine("形状: ");
- Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
- Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
- Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
- Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
- Console.WriteLine();
- Console.WriteLine("边缘: ");
- Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
- Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
- Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
- Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
- Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
- Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
- Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
- Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
- Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
- Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
- Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
- Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
- Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
- Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
- Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
- Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
- Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
- Console.WriteLine();
- }
- /// <summary>
- /// 将文本写入txt文件中
- /// </summary>
- /// <param name="DirPath">文件路径</param>
- /// <param name="FileName">文件名称</param>
- /// <param name="Strs">字符串</param>
- /// <param name="IsCleanFile">是否先清空文件</param>
- public void WriteTxtToFile(string DirPath, string FileName, string Strs, bool IsCleanFile = false)
- {
- if (string.IsNullOrEmpty(Strs))
- return;
- if (!Directory.Exists(DirPath)) //如果不存在就创建file文件夹
- {
- Directory.CreateDirectory(DirPath);
- }
- FileStream fs = new FileStream((DirPath + FileName), FileMode.OpenOrCreate, FileAccess.Write);
- StreamWriter sw = new StreamWriter(fs);
- fs.Position = fs.Length;
- sw.WriteLine(Strs); //写入字符串
- sw.Close();
- fs.Close();
- }
- /// <summary>
- /// 图像的Id(图像名)在创建db文件时被改变,找到对应的图像,保存新db文件时用旧图像名作为ID
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnLoadNameChangeClick(object sender, RoutedEventArgs e)
- {
- string dataFolder = System.Environment.CurrentDirectory;
- _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
- _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_datas.db");
- if (File.Exists(_dbPathChoose))
- {
- MessageBox.Show("数据库已存在");
- return;
- //throw new Exception("数据库已存在,请检查.");
- }
- else
- {
- DataBase db = new DataBase(_dbPathChoose);
- db.CreateDataBase(); //创建一个新的数据库文件
- }
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- //string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
- string[] strs2 = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- string ImgId = strs2[0];
- int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
- if (imgIndex >= 0)
- {
- //AddExistImage(ImgId);
- //SetLesions(ImgId, _allImgInfo[imgIndex].Lesions);
- //SetThyroidContour(ImgId, _allImgInfo[imgIndex].ThyroidContour);
- MessageBox.Show("Id未改变:"+ ImgId);
- }
- else
- {
- Bitmap image = new Bitmap(filename);
- RawImage rawImg = RawImageShowUtils.BitmapToRawImage(image);
- string hashCode = ComputeHashCode(rawImg.DataBuffer);//生成hashCode,根据hashCode找到对应的描述
- int imgIndexNew = _allImgInfo.FindIndex(x => x.ImageId == hashCode);
- if (imgIndexNew >= 0)
- {
- AddExistImage(ImgId);
- SetLesions(ImgId, _allImgInfo[imgIndexNew].Lesions);
- SetThyroidContour(ImgId, _allImgInfo[imgIndexNew].ThyroidContour);
- }
- image.Dispose();
- rawImg.Dispose();
- }
- }
- }
- }
- /// <summary>
- /// 合并几个db文件,但只保留之前db文件中的甲状腺和病灶的轮廓
- /// 第一个选中的db文件要先生成一个基本版(只有所有数据的名称信息,防止出现新数据)。
- /// 甲状腺和病灶轮廓存储在第一个db文件中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnDBClick(object sender, RoutedEventArgs e)
- {
- string dataFolder = System.Environment.CurrentDirectory;
- //_imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
- //_dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_des_gt_datas.db");
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "数据库文件|*.db";
- openFileDialog.Multiselect = false;
- openFileDialog.Title = "选择一个母版数据库文件";
- string dbPath = "";
- if (openFileDialog.ShowDialog() ?? false)
- {
- _dbPathChoose = openFileDialog.FileName;
- }
- DataBase dataBase = new DataBase(_dbPathChoose);
- bool readDb = dataBase.ReadDataBase();
- if (readDb)
- {
- _allImgInfo = dataBase._allImages;
- if (_allImgInfo.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
- OpenFileDialog openFileDialog2 = new OpenFileDialog();
- openFileDialog2.Filter = "数据库文件|*.db";
- openFileDialog2.Multiselect = false;
- openFileDialog2.Title = "选择一个被复制数据库文件";
- string dbPath2 = "";
- if (openFileDialog2.ShowDialog() ?? false)
- {
- dbPath = openFileDialog2.FileName;
- }
- DataBase dataBase2 = new DataBase(dbPath);
- bool readDb2 = dataBase2.ReadDataBase();
- if (readDb2)
- {
- allImgInfo2 = dataBase2._allImages;
- if (allImgInfo2.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- int num = allImgInfo2.Count;
- for(int ii = 0;ii < num; ii++)
- {
- string imgID = allImgInfo2[ii].ImageId;
- int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == imgID);
- if (imgIndex >= 0)
- {
- AddExistImage(imgID);
- int lesionsNum = allImgInfo2[ii].Lesions.Count;
- List<LesionInfo> tmpLe = new List<LesionInfo>();
- LesionInfo tmp = new LesionInfo();
- if(lesionsNum >1)
- {
- int a = 0;
- a++;
- }
-
- tmpLe = allImgInfo2[ii].Lesions;
- for (int jj = 0; jj < lesionsNum; jj++)
- {
- //tmpLe[jj].HorizontalPoint1 = _allImgInfo[imgIndex].Lesions[jj].HorizontalPoint1;
- //tmpLe[jj].HorizontalPoint2 = _allImgInfo[imgIndex].Lesions[jj].HorizontalPoint2; ;
- //tmpLe[jj].VerticalPoint1 = _allImgInfo[imgIndex].Lesions[jj].VerticalPoint1; ;
- //tmpLe[jj].VerticalPoint2 = _allImgInfo[imgIndex].Lesions[jj].VerticalPoint2; ;
- //tmpLe[jj].HorizontalPoint1 = null;
- //tmpLe[jj].HorizontalPoint2 = null;
- //tmpLe[jj].VerticalPoint1 = null;
- //tmpLe[jj].VerticalPoint2 = null;
- //tmpLe[jj].EchoPattern = 0;
- //tmpLe[jj].Shape = 0;
- //tmpLe[jj].Margin = 0;
- //tmpLe[jj].EchogenicFoci = 0;
- }
- ///////////////
- //SetLesions(imgID, tmpLe);
- SetThyroidContour(imgID, allImgInfo2[ii].ThyroidContour);
- //MessageBox.Show("Id未改变:" + ImgId);
- }
- else
- {
- }
- }
- }
- /// <summary>
- /// 三份db文件比较,甲状腺病灶四个属性依次比较,根据实际需求保存数据
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnDBCompareClick(object sender, RoutedEventArgs e)
- {
- string dataFolder = System.Environment.CurrentDirectory;
- string imagePath = System.IO.Path.Combine(dataFolder, "result\\all");
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "数据库文件|*.db";
- openFileDialog.Multiselect = false;
- openFileDialog.Title = "选择一个母版数据库文件";
- string dbPath = "";
- if (openFileDialog.ShowDialog() ?? false)
- {
- _dbPathChoose = openFileDialog.FileName;
- }
- DataBase dataBase = new DataBase(_dbPathChoose);
- bool readDb = dataBase.ReadDataBase();
- if (readDb)
- {
- _allImgInfo = dataBase._allImages;
- if (_allImgInfo.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
- OpenFileDialog openFileDialog2 = new OpenFileDialog();
- openFileDialog2.Filter = "数据库文件|*.db";
- openFileDialog2.Multiselect = false;
- openFileDialog2.Title = "选择一个被复制数据库文件";
- string dbPath2 = "";
- if (openFileDialog2.ShowDialog() ?? false)
- {
- dbPath = openFileDialog2.FileName;
- }
- DataBase dataBase2 = new DataBase(dbPath);
- bool readDb2 = dataBase2.ReadDataBase();
- if (readDb2)
- {
- allImgInfo2 = dataBase2._allImages;
- if (allImgInfo2.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- ///////////////////
- List<GTImgInfo> allImgInfo3 = new List<GTImgInfo>();
- OpenFileDialog openFileDialog3 = new OpenFileDialog();
- openFileDialog3.Filter = "数据库文件|*.db";
- openFileDialog3.Multiselect = false;
- openFileDialog3.Title = "选择一个被复制数据库文件";
- string dbPath3 = "";
- if (openFileDialog3.ShowDialog() ?? false)
- {
- dbPath = openFileDialog3.FileName;
- }
- DataBase dataBase3 = new DataBase(dbPath);
- bool readDb3 = dataBase3.ReadDataBase();
- if (readDb3)
- {
- allImgInfo3 = dataBase3._allImages;
- if (allImgInfo3.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- }
- ///////////////
- int num = _allImgInfo.Count;
- int num2 = allImgInfo2.Count;
- int num3 = allImgInfo3.Count;
- if (!((num == num2) && (num == num3)))
- {
- MessageBox.Show("数据出错!");
- return;
- }
- int[,] XLecho = new int[6, 6];
- int[,] XYecho = new int[6, 6];
- int[,] LYecho = new int[6, 6];
- int[,] XLShape = new int[6, 6];
- int[,] XYShape = new int[6, 6];
- int[,] LYShape = new int[6, 6];
- int[,] XLmargin = new int[6, 6];
- int[,] XYmargin = new int[6, 6];
- int[,] LYmargin = new int[6, 6];
- int[,] XLechogenic = new int[6, 6];
- int[,] XYechogenic = new int[6, 6];
- int[,] LYechogenic = new int[6, 6];
- for (int ii = 0; ii < num; ii++)
- {
- string imgID = allImgInfo2[ii].ImageId;
- int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == imgID);
-
- int lesionsNum1 = _allImgInfo[ii].Lesions.Count;
- int lesionsNum2 = allImgInfo2[ii].Lesions.Count;
- int lesionsNum3 = allImgInfo3[ii].Lesions.Count;
- if (!((lesionsNum1 == lesionsNum2) && (lesionsNum1 == lesionsNum3) && (lesionsNum2 == lesionsNum3)))
- {
- WriteTxtToFile("E:\\image\\", "lesionsNum.txt", imgID, false);
- int sum = lesionsNum3 + lesionsNum2 + lesionsNum1;
- if (sum > 0)
- {
- string imageName = imagePath + "\\" + imgID + ".jpg";
- Bitmap bmp = new Bitmap(imageName);
- string savePath = imagePath + "\\have\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- continue;
- }
- else
- {
- }
- int numThy1 = (int)_allImgInfo[ii].ThyroidContour.Count;
- int numThy2 = (int)allImgInfo2[ii].ThyroidContour.Count;
- int numThy3 = (int)allImgInfo3[ii].ThyroidContour.Count;
- if (!((numThy1 == numThy2) && (numThy1 == numThy3) && (numThy2 == numThy3)))
- {
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\thynum\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- bool becho = true;
- bool bShape = true;
- bool bMargin = true;
- bool bEchogenicFoci = true;
- for (int jj = 0; jj < lesionsNum1; jj++)
- {
- string imageName = imagePath + "\\" + imgID + ".jpg";
- Bitmap bmp = new Bitmap(imageName);
- int numLes1 = (int)_allImgInfo[ii].Lesions[jj].LesionContour.Count;
- int numLes2 = (int)allImgInfo2[ii].Lesions[jj].LesionContour.Count;
- int numLes3 = (int)allImgInfo3[ii].Lesions[jj].LesionContour.Count;
- if (!((numLes1 == numLes2) && (numLes1 == numLes3) && (numLes2 == numLes3)))
- {
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\lesnum\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
-
- var Echo1 = (int)_allImgInfo[ii].Lesions[jj].EchoPattern;
- var Echo2 = (int)allImgInfo2[ii].Lesions[jj].EchoPattern;
- var Echo3 = (int)allImgInfo3[ii].Lesions[jj].EchoPattern;
- XLecho[Echo3, Echo1] += 1;
- XYecho[Echo3, Echo2] += 1;
- LYecho[Echo1, Echo2] += 1;
- string resultStr = imgID + "," + Echo1.ToString() + "," + Echo2.ToString() + "," + Echo3.ToString();
- if (!((Echo1 == Echo2) && (Echo1 == Echo3) && (Echo2 == Echo3)))
- {
- //WriteTxtToFile("E:\\image\\", "EchoDiff.txt", resultStr, false);
- //becho = false;
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\echo\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- else
- {
- becho = true;
- string savePath = imagePath + "\\EchoSmae\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- //if(Echo1 == Echo2)
- //{
- // string savePath = imagePath + "\\12\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (Echo1 == Echo3)
- //{
- // string savePath = imagePath + "\\13\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (Echo2 == Echo3)
- //{
- // string savePath = imagePath + "\\23\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- var Shape1 = (int)_allImgInfo[ii].Lesions[jj].Shape;
- var Shape2 = (int)allImgInfo2[ii].Lesions[jj].Shape;
- var Shape3 = (int)allImgInfo3[ii].Lesions[jj].Shape;
- XLShape[Shape3, Shape1] += 1;
- XYShape[Shape3, Shape2] += 1;
- LYShape[Shape1, Shape2] += 1;
- string shapeStr = imgID + "," + Shape1.ToString() + "," + Shape2.ToString() + "," + Shape3.ToString();
- if (!((Shape1 == Shape2) && (Shape1 == Shape3) && (Shape2 == Shape3)))
- {
- //WriteTxtToFile("E:\\image\\", "ShapeDiff.txt", shapeStr, false);
- //bShape = false;
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
-
- }
- else
- {
- //string savePath = imagePath + "\\shape\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- bShape = true;
- }
- var margin1 = (int)_allImgInfo[ii].Lesions[jj].Margin;
- var margin2 = (int)allImgInfo2[ii].Lesions[jj].Margin;
- var margin3 = (int)allImgInfo3[ii].Lesions[jj].Margin;
- XLmargin[margin3, margin1] += 1;
- XYmargin[margin3, margin2] += 1;
- LYmargin[margin1, margin2] += 1;
- string marginStr = imgID + "," + margin1.ToString() + "," + margin2.ToString() + "," + margin3.ToString();
- if (!((margin1 == margin2) && (margin1 == margin3) && (margin2 == margin3)))
- {
- //WriteTxtToFile("E:\\image\\", "marginDiff.txt", marginStr, false);
- //bMargin = false;
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\margin\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- else
- {
- //string savePath = imagePath + "\\margin\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- bMargin = true;
- }
- //边缘两个医生相同数据,分别保存
- //if (margin1 == margin2 && margin1 != margin3)
- //{
- // string savePath = imagePath + "\\12\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (margin1 == margin3 && margin1 != margin2)
- //{
- // string savePath = imagePath + "\\13\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (margin2 == margin3 && margin1 != margin2)
- //{
- // string savePath = imagePath + "\\23\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- var echogenic1 = (int)(_allImgInfo[ii].Lesions[jj].EchogenicFoci);
- var echogenic2 = (int)allImgInfo2[ii].Lesions[jj].EchogenicFoci;
- var echogenic3 = (int)allImgInfo3[ii].Lesions[jj].EchogenicFoci;
- if(echogenic1 <0|| echogenic2<0|| echogenic3<0)
- {
- continue;
- }
- XLechogenic[echogenic3, echogenic1] += 1;
- XYechogenic[echogenic3, echogenic2] += 1;
- LYechogenic[echogenic1, echogenic2] += 1;
-
- string echogenicStr = imgID + "," + echogenic1.ToString() + "," + echogenic2.ToString() + "," + echogenic3.ToString();
- if (!((echogenic1 == echogenic2) && (echogenic1 == echogenic3) && (echogenic2 == echogenic3)))
- {
- //WriteTxtToFile("E:\\image\\", "echogenicDiff.txt", echogenicStr, false);
- //bEchogenicFoci = false;
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\echogenic\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- else
- {
- bEchogenicFoci = true;
- //string savePath = imagePath + "\\echogenicSmae\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
- //钙化相互之间不同数据,分别保存
-
- //if (echogenic3 != echogenic1)
- //{
- // string savePath = imagePath + "\\11\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (echogenic3 != echogenic2)
- //{
- // string savePath = imagePath + "\\22\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- //if (echogenic1 != echogenic2)
- //{
- // string savePath = imagePath + "\\33\\" + imgID + ".jpg";
- // bmp.Save(savePath);
- //}
- if (becho && bShape && bMargin && bEchogenicFoci)
- {
- //string sameAllStr = imgID + "," + Echo1.ToString() + "," + Shape1.ToString() + "," + margin1.ToString() + "," + echogenic3.ToString();
- //WriteTxtToFile("E:\\image\\", "Same.txt", sameAllStr, false);
- //string imageName = imagePath + "\\" + imgID + ".jpg";
- //Bitmap bmp = new Bitmap(imageName);
- //string savePath = imagePath + "\\same\\" + imgID + ".jpg";
- //bmp.Save(savePath);
- }
-
- }
- if (imgIndex >= 0)
- {
- //AddExistImage(imgID);
- //List<LesionInfo> tmpLe = new List<LesionInfo>();
- //LesionInfo tmp = new LesionInfo();
- //tmpLe = allImgInfo2[ii].Lesions;
- //SetLesions(imgID, tmpLe);
- //SetThyroidContour(imgID, allImgInfo2[ii].ThyroidContour);
- }
- }
- 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();
- WriteTxtToFile("E:\\image\\", "Same.txt", echoStr, false);
- string echoStrXL = "";
- string echoStrXY = "";
- string echoStrLY = "";
- string ShapeStrXL = "";
- string ShapeStrXY = "";
- string ShapeStrLY = "";
- string marginStrXL = "";
- string marginStrXY = "";
- string marginStrLY = "";
- string echogenicStrXL = "";
- string echogenicStrXY = "";
- string echogenicStrLY = "";
- for (int i = 0; i < 6; i++)
- {
- for (int j = 0; j < 6; j++)
- {
- echoStrXL += XLecho[i, j].ToString() + ",";
- echoStrXY += XYecho[i, j].ToString() + ",";
- echoStrLY += LYecho[i, j].ToString() + ",";
- ShapeStrXL += XLShape[i, j].ToString() + ",";
- ShapeStrXY += XYShape[i, j].ToString() + ",";
- ShapeStrLY += LYShape[i, j].ToString() + ",";
- marginStrXL += XLmargin[i, j].ToString() + ",";
- marginStrXY += XYmargin[i, j].ToString() + ",";
- marginStrLY += LYmargin[i, j].ToString() + ",";
- echogenicStrXL += XLechogenic[i, j].ToString() + ",";
- echogenicStrXY += XYechogenic[i, j].ToString() + ",";
- echogenicStrLY += LYechogenic[i, j].ToString() + ",";
- }
- echoStrXL = echoStrXL + "\n";
- echoStrXY = echoStrXY + "\n";
- echoStrLY = echoStrLY + "\n";
- ShapeStrXL = ShapeStrXL + "\n";
- ShapeStrXY = ShapeStrXY + "\n";
- ShapeStrLY = ShapeStrLY + "\n";
- marginStrXL = marginStrXL + "\n";
- marginStrXY = marginStrXY + "\n";
- marginStrLY = marginStrLY + "\n";
- echogenicStrXL = echogenicStrXL + "\n";
- echogenicStrXY = echogenicStrXY + "\n";
- echogenicStrLY = echogenicStrLY + "\n";
- }
- //WriteTxtToFile("E:\\image\\", "echoStrXL.csv", echoStrXL, false);
- //WriteTxtToFile("E:\\image\\", "echoStrXY.csv", echoStrXY, false);
- //WriteTxtToFile("E:\\image\\", "echoStrLY.csv", echoStrLY, false);
- //WriteTxtToFile("E:\\image\\", "ShapeStrXL.csv", ShapeStrXL, false);
- //WriteTxtToFile("E:\\image\\", "ShapeStrXY.csv", ShapeStrXY, false);
- //WriteTxtToFile("E:\\image\\", "ShapeStrLY.csv", ShapeStrLY, false);
- //WriteTxtToFile("E:\\image\\", "marginStrXL.csv", marginStrXL, false);
- //WriteTxtToFile("E:\\image\\", "marginStrXY.csv", marginStrXY, false);
- //WriteTxtToFile("E:\\image\\", "marginStrLY.csv", marginStrLY, false);
- //WriteTxtToFile("E:\\image\\", "echogenicStrXL.csv", echogenicStrXL, false);
- //WriteTxtToFile("E:\\image\\", "echogenicStrXY.csv", echogenicStrXY, false);
- //WriteTxtToFile("E:\\image\\", "echogenicStrLY.csv", echogenicStrLY, false);
- int a = 0;
- a += 1;
- }
- /// <summary>
- /// 发现标注工具中的保存结果和当前工程中的结果不对应,将结果整理好并保存到新的db文件中
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnDBClearClick(object sender, RoutedEventArgs e)
- {
- //video2image();
- //return;
- string dataFolder = System.Environment.CurrentDirectory;
- _imgPathChoose = System.IO.Path.Combine(dataFolder, "result");
- _dbPathChoose = System.IO.Path.Combine(dataFolder, "thyroid_gt_clear_datas.db");
- if (_allImgInfo.Count <= 0)
- {
- MessageBox.Show("先加载数据库");
- }
- if (File.Exists(_dbPathChoose))
- {
- MessageBox.Show("数据库已存在");
- return;
- //throw new Exception("数据库已存在,请检查.");
- }
- else
- {
- DataBase db = new DataBase(_dbPathChoose);
- db.CreateDataBase(); //创建一个新的数据库文件
- }
- int num = _allImgInfo.Count;
- for (int ii = 0; ii < num; ii++)
- {
- int numLesions = _allImgInfo[ii].Lesions.Count;
- string imgId = _allImgInfo[ii].ImageId;
- List<LesionInfo> lesionsNew = new List<LesionInfo>();
- for (int jj = 0; jj < numLesions; jj++)
- {
- var lesions = _allImgInfo[ii].Lesions[jj];
- int res = (int)lesions.EchogenicFoci;
-
- var value1 = lesions.EchoPattern;
- var value2 = lesions.EchogenicFoci;
- var value3 = lesions.Margin;
- var value4 = lesions.Shape;
- LesionInfo tmp = new LesionInfo();
- tmp.EchoPattern = (EchoPatternEnum)((int) value1 - 1);
- tmp.EchogenicFoci = (EchogenicFociEnum)((int)value2 - 1);
- tmp.Margin = (MarginEnum)((int)value3 - 1);
- tmp.Shape = (ShapeEnum)((int)value4 - 1);
- tmp.HorizontalPoint1 = lesions.HorizontalPoint1;
- tmp.HorizontalPoint2 = lesions.HorizontalPoint2;
- tmp.VerticalPoint1 = lesions.VerticalPoint1;
- tmp.VerticalPoint2 = lesions.VerticalPoint2;
- tmp.LesionContour = lesions.LesionContour;
- lesionsNew.Add(tmp);
- }
- AddExistImage(imgId);
- SetLesions(imgId, lesionsNew);
- SetThyroidContour(imgId, _allImgInfo[ii].ThyroidContour);
- }
- }
- private void OnDBLoadModel1(object sender, RoutedEventArgs e)
- {
- if(_UseNet != null)
- {
- _UseNet.Dispose();
- _UseNet = null;
- }
- Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
- {
- Filter = "模型文件|*.emd",
- Multiselect = false,
- Title = "选择一个模型"
- };
- if (openFileDialog.ShowDialog() ?? false)
- {
- string fileName = openFileDialog.FileName;
- string modelName = Path.GetFileName(fileName);
- _netsDir = Path.GetDirectoryName(fileName);
- _UseNet = new ProcessData();
- _UseNet.OnLoadModel(_netsDir);
- }
- /////////////
- //if (_inferNet != null)
- //{
- // _inferNet.Dispose();
- // _inferNet = null;
- //}
- //Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog
- //{
- // Filter = "模型文件|*.emd",
- // Multiselect = false,_netsDir
- // Title = "选择一个模型"
- //};
- //if (openFileDialog.ShowDialog() ?? false)
- //{
- // string fileName = openFileDialog.FileName;
- // string modelName = Path.GetFileName(fileName);
- // _netsDir = Path.GetDirectoryName(fileName);
- // _inferNet = new DescriptionCoreDeeplearning();//DescriptionCoreDeeplearning DescriptionDeeplearning
- // byte[] fileDataDecrypted = InferenceNetworkUtils.ReadNetworkDataFromFile(_netsDir, _inferNet.NetworkName, _inferNet.HashCode);
- // _inferNet.LoadNetwork(_inferCore, _deviceType, fileDataDecrypted);
- //}
- }
- private void OnDBModelPredict(object sender, RoutedEventArgs e)
- {
- if (_currentImg != null)
- {
- string name = "sos";
- //DoDescriAlgorithm(name);
- DoDescriAlgorithmModel(name);
- }
- else
- {
- MessageBox.Show("请先加载待测图像!");
- }
- }
- //甲状腺描述算法调用接口
- private int DoDescriAlgorithmModel(string name)
- {
- if (_currentImg == null)
- {
- MessageBox.Show("请先加载待测图像!");
- return -1;
- }
- if(_UseNet == null)
- {
- MessageBox.Show("请先加载模型!");
- return -1;
- }
- Bitmap bmp = _currentImg;
- RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
- int channel = BitmapChannel(bmp);
- roiCoor roi;
- roi.x = 0;
- roi.y = 0;
- roi.width = _currentImg.Width;
- roi.height = _currentImg.Height;
- int modelInputW = 320;
- int modelInputH = 320;
- int modelInputC = 4;
- int modelOutputW = 320;
- int modelOutputH = 320;
- int modelOutputC = 2;
- int result = 0;
- int LesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
- int ThyroidNum = _allImgInfo[_currentImgIdex].ThyroidContour.Count;
- //确定存在病灶
- if (LesionsNum > 0 && ThyroidNum > 0)
- {
- Bitmap dstimage = (Bitmap)_currentImg.Clone();
- int lesionsNum = _allImgInfo[_currentImgIdex].Lesions.Count;
- string strDescriptionEcho = string.Empty;
- string strDescriptionShape = string.Empty;
- string strDescriptionMargin = string.Empty;
- string strDescriptionEchogenicFoci = string.Empty;
- for (int ii = 0; ii < lesionsNum; ii++)
- {
- //获取病灶轮廓
- int num2 = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour.Count;
- StructPoint[] lesionPts = new StructPoint[num2];
- System.Drawing.PointF[] lesionContour = new PointF[num2];
- for (int i = 0; i < num2; i++)
- {
- lesionPts[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
- lesionPts[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
- lesionContour[i].X = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].X;
- lesionContour[i].Y = _allImgInfo[_currentImgIdex].Lesions[ii].LesionContour[i].Y;
- }
- //获取甲状腺轮廓
- List<MyPoint> thyroidCont = _allImgInfo[_currentImgIdex].ThyroidContour;
- int num1 = thyroidCont.Count;
- //if(num1 == 0)
- //{
- // WriteTxtToFile("E:\\image\\", "name.txt", name, false);
- //}
- StructPoint[] thyroidPts = new StructPoint[num1];
- System.Drawing.PointF[] thyroidContour = new PointF[num1];
- for (int i = 0; i < num1; i++)
- {
- thyroidPts[i].X = thyroidCont[i].X;
- thyroidPts[i].Y = thyroidCont[i].Y;
- thyroidContour[i].X = thyroidCont[i].X;
- thyroidContour[i].Y = thyroidCont[i].Y;
- }
- EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchogenicFoci;
- EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[ii].EchoPattern;
- ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[ii].Shape;
- MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[ii].Margin;
- LesionDescri desCpp = new LesionDescri();
- desCpp.echo = 0;
- desCpp.shape = 0;
- desCpp.margin = 0;
- desCpp.echogenicFoci = 0;
- desCpp.axisPt = new AxisPoint();
- desCpp.axisPt.horizontalPt1 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.horizontalPt2 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.verticalPt1 = new StructPoint { X = 0, Y = 0 };
- desCpp.axisPt.verticalPt2 = new StructPoint { X = 0, Y = 0 };
- System.Drawing.PointF[] axisH = new PointF[2];
- System.Drawing.PointF[] axisV = new PointF[2];
- //WriteTxtToFile("E:\\image\\", "usename.txt", name, false);
- roiCoor roiSeg ;
- roiSeg.x = 0;
- roiSeg.y = 0;
- roiSeg.width = 0;
- roiSeg.height = 0;
- ThyroidDescriptionContour(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
- roi, num2, lesionPts, ref roiSeg);
- int num = roiSeg.width * roiSeg.height;
- StructPoint[] contourPts_tmp = new StructPoint[num];
- //int ptsNum = ContourDetectBLS(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
- ////int ptsNum = ContourDetectBLSForThyroid(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
- //StructPoint[] lesionPtsChange = new StructPoint[ptsNum];
- //for (int i = 0; i < ptsNum; i++)
- //{
- // lesionPtsChange[i].X = contourPts_tmp[i].X;
- // lesionPtsChange[i].Y = contourPts_tmp[i].Y;
- //}
- var starttime = Environment.TickCount;
- byte[] arrInput = new byte[modelInputW * modelInputH * modelInputC];
- roiCoor roiDst;
- roiDst.x = 0;
- roiDst.y = 0;
- roiDst.width = 0;
- roiDst.height = 0;
- ThyroidDescriptionModelProcess(rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
- roi, num1, thyroidPts, /*ptsNum, lesionPtsChange,*/num2, lesionPts, modelInputW, modelInputH,
- modelInputC, ref roiDst, arrInput);
- byte[] arrOutput = new byte[modelOutputW * modelOutputH * modelOutputC];
- //_inferNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
- _UseNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
- int maskSize = roiDst.width * roiDst.height;
- int calcificatNum = 0;//钙化点数目
- int MaxLesionCount = 60;//假设最多60钙化点
- int[] contourLen = new int[MaxLesionCount];
- StructPoint[] contourPoints = new StructPoint[maskSize];
- ThyroidDescriptionModelProcessModelImage(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
- ref calcificatNum, contourLen, contourPoints);
- //var starttime = Environment.TickCount;
- ThyroidDescriptionModelAfterProcess(
- rawImg.DataBuffer, channel, rawImg.Width, rawImg.Height,
- num1, thyroidPts, /*ptsNum, lesionPtsChange,*/ num2, lesionPts,
- calcificatNum, contourLen, contourPoints,
- roiDst, ref desCpp);
- StructPoint pt;
- pt.X = 0;
- pt.Y = 0;
- AxisPoint axis;
- axis.horizontalPt1 = pt;
- axis.horizontalPt2 = pt;
- axis.verticalPt1 = pt;
- axis.verticalPt2 = pt;
- //MyLesionAxisProcess(roiDst, ptsNum, lesionPtsChange, ref axis);
-
- {
- //int ptsNum = ContourDetectBLS(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
- ////int ptsNum = ContourDetectBLSForThyroid(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height, roiSeg, contourPts_tmp);
- //StructPoint[] lesionPtsChange = new StructPoint[ptsNum];
- //for (int i = 0; i < ptsNum; i++)
- //{
- // lesionPtsChange[i].X = contourPts_tmp[i].X;
- // lesionPtsChange[i].Y = contourPts_tmp[i].Y;
- //}
- //var starttime = Environment.TickCount;
- //byte[] arrInput = new byte[modelInputW * modelInputH * modelInputC];
- //roiCoor roiDst;
- //roiDst.x = 0;
- //roiDst.y = 0;
- //roiDst.width = 0;
- //roiDst.height = 0;
- //ThyroidDescriptionModelProcess(rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
- // roi, num1, thyroidPts, ptsNum, lesionPtsChange, /*num2, lesionPts,*/ modelInputW, modelInputH,
- // modelInputC, ref roiDst, arrInput);
- //byte[] arrOutput = new byte[modelOutputW * modelOutputH * modelOutputC];
- //_UseNet.Process(arrInput, modelInputW, modelInputH, modelInputC, arrOutput);
- //int maskSize = roiDst.width * roiDst.height;
- //int calcificatNum = 0;//钙化点数目
- //int MaxLesionCount = 60;//假设最多60钙化点
- //int[] contourLen = new int[MaxLesionCount];
- //StructPoint[] contourPoints = new StructPoint[maskSize];
- //ThyroidDescriptionModelProcessModelImage(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
- // ref calcificatNum, contourLen, contourPoints);
- //ThyroidDescriptionModelAfterProcess(
- // rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
- // num1, thyroidPts, ptsNum, lesionPtsChange, /*num2, lesionPts,*/
- // calcificatNum, contourLen, contourPoints,
- // roiDst, ref desCpp);
- //StructPoint pt;
- //pt.X = 0;
- //pt.Y = 0;
- //AxisPoint axis;
- //axis.horizontalPt1 = pt;
- //axis.horizontalPt2 = pt;
- //axis.verticalPt1 = pt;
- //axis.verticalPt2 = pt;
- //MyLesionAxisProcess(roiDst, ptsNum, lesionPtsChange, ref axis);
- }
- //ThyroidDescriptionModelAfterProcess_1(arrOutput, modelOutputW, modelOutputH, modelOutputC, roiDst,
- // rawImg.DataBuffer, rawImg.Channel, rawImg.Width, rawImg.Height,
- // roi, num1, thyroidPts, num2, lesionPts, ref desCpp);
- var endtime = Environment.TickCount;
- //WriteTxtToFile("E:\\image\\", "time_all.txt", (endtime - starttime).ToString(), false);
- arrOutput = null;
- arrInput = null;
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- ElapsedTime.Text = (endtime - starttime).ToString();
- }));
- int echoCpp = desCpp.echo; // 回声
- int shapeCpp = desCpp.shape; // 形状
- int marginCpp = desCpp.margin; // 边缘
- int echogenicFociCpp = desCpp.echogenicFoci; // 局灶性强回声
- EchogenicFociEnum echoFoci = (EchogenicFociEnum)desCpp.echogenicFoci;
- EchoPatternEnum echo = (EchoPatternEnum)desCpp.echo;
- ShapeEnum shape = (ShapeEnum)desCpp.shape;
- MarginEnum margin = (MarginEnum)desCpp.margin;
- AxisPoint axisPoint = desCpp.axisPt; // 纵、横轴端点坐标
- StructPoint pt1 = axisPoint.horizontalPt1; // 横轴
- StructPoint pt2 = axisPoint.horizontalPt2;
- StructPoint pt3 = axisPoint.verticalPt1; // 纵轴
- StructPoint pt4 = axisPoint.verticalPt2;
- axisH[0].X = pt1.X;
- axisH[0].Y = pt1.Y;
- axisH[1].X = pt2.X;
- axisH[1].Y = pt2.Y;
- axisV[0].X = pt3.X;
- axisV[0].Y = pt3.Y;
- axisV[1].X = pt4.X;
- axisV[1].Y = pt4.Y;
- int resCa = 0;
- int resEcho = 0;
- int resShape = -1;
- int resMargin = -1;
- //Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- string strEcho = string.Empty;
- if (echo == EchoPatternEnum.Anechoic)
- {
- strEcho = "无回声";
- resEcho = 0;
- }
- else if (echo == EchoPatternEnum.Hyperechoic)
- {
- strEcho = "高回声";
- resEcho = 1;
- }
- else if (echo == EchoPatternEnum.Isoechoic)
- {
- strEcho = "等回声";
- resEcho = 2;
- }
- else if (echo == EchoPatternEnum.Hypoechoic)
- {
- strEcho = "低回声";
- resEcho = 3;
- }
- else if (echo == EchoPatternEnum.HypoechoicLower)
- {
- strEcho = "极低回声";
- resEcho = 4;
- }
- strDescriptionEcho += ii.ToString() + ":" + strEcho + "\r\n";
- string strShape = string.Empty;
- if (shape == ShapeEnum.WiderThanTall)
- {
- strShape = "宽大于高";
- resShape = 0;
- }
- else if (shape == ShapeEnum.TallThanWider)
- {
- strShape = "高大于宽";
- resShape = 1;
- }
- strDescriptionShape += ii.ToString() + ":" + strShape + "\r\n";
- string strMargin = string.Empty;
- if (margin == MarginEnum.Smooth)
- {
- strMargin = "边缘光整";
- resMargin = 0;
- }
- else if (margin == MarginEnum.IllDefined)
- {
- strMargin = "边缘模糊";
- resMargin = 1;
- }
- else if (margin == MarginEnum.Lobulated)
- {
- strMargin = "边缘分叶状";
- resMargin = 2;
- }
- else if (margin == MarginEnum.Irregular)
- {
- strMargin = "边缘不规则";
- resMargin = 3;
- }
- else if (margin == MarginEnum.ExtraThyroidalExtension)
- {
- strMargin = "甲状腺外侵犯";
- resMargin = 4;
- }
- strDescriptionMargin += ii.ToString() + ":" + strMargin + "\r\n";
- string strEchogenicFoci = string.Empty;
- if (echoFoci == EchogenicFociEnum.NoCifications)
- {
- strEchogenicFoci = "无钙化";
- resCa = 0;
- }
- else if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- strEchogenicFoci = "粗钙化";
- resCa = 1;
- }
- else if (echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- strEchogenicFoci = "微钙化";
- resCa = 2;
- }
- strDescriptionEchogenicFoci += ii.ToString() + ":" + strEchogenicFoci + "\r\n";
-
- }
- //));
-
- if (echoFociGT == echoFoci)
- {
- if (echoFoci == EchogenicFociEnum.NoCifications)
- {
- _NoCifications_NoCifications_num++;
- result = 1;
- }
- if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Coarsecalcifications_Coarsecalcifications_num++;
- result = 2;
- }
- if (echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Macrocalcifications_Macrocalcifications_num++;
- result = 3;
- }
- }
- else
- {
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _NoCifications_Coarsecalcifications_num++;
- result = 4;
- }
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _NoCifications_Macrocalcifications_num++;
- result = 5;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Coarsecalcifications_NoCifications_num++;
- result = 6;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Coarsecalcifications_Macrocalcifications_num++;
- result = 7;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Macrocalcifications_NoCifications_num++;
- result = 8;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Macrocalcifications_Coarsecalcifications_num++;
- result = 9;
- }
- }
- if(echoGT == echo)
- {
- if (echo == EchoPatternEnum.Anechoic)
- {
- _Anechoic_Anechoi_num++;
- }
- if (echo == EchoPatternEnum.Hyperechoic)
- {
- _Hyperechoic_Hyperechoic_num++;
- }
- if (echo == EchoPatternEnum.Isoechoic)
- {
- _Isoechoic_Isoechoic_num++;
- }
- if (echo == EchoPatternEnum.Hypoechoic)
- {
- _Hypoechoic_Hypoechoic_num++;
- }
- if (echo == EchoPatternEnum.HypoechoicLower)
- {
- _HypoechoicLower_HypoechoicLower_num++;
- }
- }
- else
- {
- //把无回声判为其它
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Anechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Anechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Anechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Anechoic_HypoechoicLower_num++;
- }
- //把高回声判为其它
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hyperechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hyperechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Hyperechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hyperechoic_HypoechoicLower_num++;
- }
- //把等回声判为其它
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Isoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Isoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Isoechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Isoechoic_HypoechoicLower_num++;
- }
- //低回声判为其它
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hypoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Hypoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hypoechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hypoechoic_HypoechoicLower_num++;
- }
- //极低回声判为其它
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
- {
- _HypoechoicLower_Anechoicr_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
- {
- _HypoechoicLower_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
- {
- _HypoechoicLower_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
- {
- _HypoechoicLower_Hypoechoic_num++;
- }
- }
- if(shapeCppGT == shape)
- {
- if (shape == ShapeEnum.WiderThanTall)
- {
- _WT_WT_num++;
- }
- if (shape == ShapeEnum.TallThanWider)
- {
- _TW_TW_num++;
- }
- }
- else
- {
- //把 宽大于高 判为 高大于宽
- if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
- {
- _WT_TW_num++;
- //WriteTxtToFile("E:\\image\\", "sssttt.txt", resShape.ToString(), false);
- }
- if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
- {
- _TW_WT_num++;
- }
- }
- if (marginGT == margin)
- {
- if (margin == MarginEnum.Smooth)
- {
- _Smooth_Smooth_num++;
- }
- if (margin == MarginEnum.IllDefined)
- {
- _IllDefined_IllDefined_num++;
- }
- if (margin == MarginEnum.Lobulated)
- {
- _Lobulated_Lobulated_num++;
- }
- if (margin == MarginEnum.Irregular)
- {
- _Irregular_Irregular_num++;
- }
- if (margin == MarginEnum.ExtraThyroidalExtension)
- {
- _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
- }
- }
- else
- {
- //把 边缘光整 判成其它
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
- {
- _Smooth_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
- {
- _Smooth_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
- {
- _Smooth_Irregular_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Smooth_ExtraThyroidalExtension_num++;
- }
- //把 边缘模糊 判成其它
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
- {
- _IllDefined_Smooth_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
- {
- _IllDefined_Lobulated_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
- {
- _IllDefined_Irregular_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _IllDefined_ExtraThyroidalExtension_num++;
- }
- //把 边缘分叶状 判成其它
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
- {
- _Lobulated_Smooth_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
- {
- _Lobulated_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
- {
- _Lobulated_Irregular_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Lobulated_ExtraThyroidalExtension_num++;
- }
- //把 边缘不规则 判成其它
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
- {
- _Irregular_Smooth_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
- {
- _Irregular_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
- {
- _Irregular_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Irregular_ExtraThyroidalExtension_num++;
- }
- //把 甲状腺外侵犯 判成其它
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
- {
- _ExtraThyroidalExtension_Smooth_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
- {
- _ExtraThyroidalExtension_IllDefined_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
- {
- _ExtraThyroidalExtension_Lobulated_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
- {
- _ExtraThyroidalExtension_Irregular_num++;
- }
- }
- //////////////
- string newPath = System.IO.Path.Combine(_currentBinPath, "result");
- if (resEcho == 0)
- {
- string nameSave = newPath + "\\00\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- //testNUm = testNUm+1;
- }
- else if (resEcho == 1)
- {
- string nameSave = newPath + "\\01\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resEcho == 2)
- {
- string nameSave = newPath + "\\02\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resEcho == 3)
- {
- string nameSave = newPath + "\\03\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resEcho == 4)
- {
- string nameSave = newPath + "\\04\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- if (resCa == 0)
- {
- string nameSave = newPath + "\\00\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resCa == 1)
- {
- string nameSave = newPath + "\\01\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resCa == 2)
- {
- string nameSave = newPath + "\\02\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- if (resShape == 0)
- {
- string nameSave = newPath + "\\00\\" + name + ".jpg";
- if (shapeCppGT == ShapeEnum.WiderThanTall)
- {
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- else if (resShape == 1)
- {
- string nameSave = newPath + "\\01\\" + name + ".jpg";
- if (shapeCppGT == ShapeEnum.WiderThanTall)
- {
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- //WriteTxtToFile("E:\\image\\", "sss.txt", resShape.ToString(), false);
- }
- // _currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- if (resMargin == 0)
- {
- string nameSave = newPath + "\\00\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resMargin == 1)
- {
- string nameSave = newPath + "\\01\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resMargin == 2)
- {
- string nameSave = newPath + "\\02\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resMargin == 3)
- {
- string nameSave = newPath + "\\03\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- else if (resMargin ==4)
- {
- string nameSave = newPath + "\\04\\" + name + ".jpg";
- //_currentImg.Save(nameSave, System.Drawing.Imaging.ImageFormat.Png);
- }
- using (var g = Graphics.FromImage(dstimage))
- {
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(roi.x, roi.y, roi.width, roi.height);
- g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- if (lesionContour.Length > 1)//画直线要超过一个点
- {
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
- g.DrawLines(pen, lesionContour); //画病灶轮廓
- System.Drawing.Pen pen2 = new System.Drawing.Pen(System.Drawing.Brushes.SeaGreen, 2);
- if (thyroidContour.Length > 0)
- {
- g.DrawLines(pen2, thyroidContour); //画肝脏轮廓
- }
- pen.Dispose();
- }
- Brush brush;
- brush = Brushes.Orange;
- g.DrawString(ii.ToString(), new Font("Arial", 20), brush, axisH[1].X, axisH[1].Y);
- //画轮廓的长短轴
- System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
- g.DrawLines(pen_h, axisH); //横轴,浅绿色
- System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
- g.DrawLines(pen_v, axisV); //纵轴,红色
- g.Dispose();
- }
- }
- EchoPatternDescri.Text = strDescriptionEcho;
- ShapeDescri.Text = strDescriptionShape;
- MarginDescri.Text = strDescriptionMargin;
- EchogenicFociDescri.Text = strDescriptionEchogenicFoci;
- _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- DstImage.Source = _dstImg;
- }));
- dstimage.Dispose();
- return result;
- }
- else
- {
- //WriteTxtToFile("E:\\image\\", "namet.txt", name.ToString(), false);
- //MessageBox.Show("未读取到病灶!");
- return -1;
- }
- }
- private void OnDBModelPredictImages(object sender, RoutedEventArgs e)
- {
- if (_UseNet == null)
- {
- MessageBox.Show("请先加载模型!");
- return;
- }
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- Bitmap img = new Bitmap(filename);
- _currentImg = img;
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- string[] sArray = null;
- sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- string ImgId = sArray[0];
- //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
- _currentImgId = ImgId;
- int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
- if (imgIdx < 0)
- {
- //return;
- WriteTxtToFile("E:\\image\\", "notname.txt", ImgId, false);
- continue;
- }
- _currentImgIdex = imgIdx;
- int res = DoDescriAlgorithmModel(ImgId);
- }
- }
- Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
- Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
- Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
- Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
- Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
- Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
- Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
- Console.WriteLine();
- Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
- Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
- Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
- Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
- Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
- Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
- Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
- Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
- Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
- Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
- Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
- Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
- Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
- Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
- Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
- Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
- Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
- Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
- Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
- Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
- Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
- Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
- Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
- Console.WriteLine();
- Console.WriteLine("形状: ");
- Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
- Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
- Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
- Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
- Console.WriteLine();
- Console.WriteLine("边缘: ");
- Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
- Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
- Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
- Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
- Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
- Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
- Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
- Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
- Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
- Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
- Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
- Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
- Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
- Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
- Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
- Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
- Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
- Console.WriteLine();
- }
- /// <summary>
- /// 正在使用的db文件中,一些图片缺少轮廓或者其他数据,需要从其他的db文件复制
- /// 第一个db文件为需要添加轮廓数据的文件,添加的轮廓数据保存到当前db文件中
- /// 第二个db文件为被复制的文件
- /// 然后选择需要添加轮廓信息的图像,根据实际需求添加信息
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnDBAddClick(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialogdb = new OpenFileDialog();
- openFileDialogdb.Filter = "数据库文件|*.db";
- openFileDialogdb.Multiselect = false;
- openFileDialogdb.Title = "选择一个数据库文件";
- string dbPath = "";
- if (openFileDialogdb.ShowDialog() ?? false)
- {
- dbPath = openFileDialogdb.FileName;
- }
- DataBase dataBase = new DataBase(dbPath);
- bool readDb = dataBase.ReadDataBase();
- if (readDb)
- {
- _allImgInfo = dataBase._allImages;
- if (_allImgInfo.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- return;
- }
- _dbPathChoose = dbPath;
- //string dbPath = "";
- List<GTImgInfo> allImgInfo2 = new List<GTImgInfo>();
- OpenFileDialog openFileDialog2 = new OpenFileDialog();
- openFileDialog2.Filter = "数据库文件|*.db";
- openFileDialog2.Multiselect = false;
- openFileDialog2.Title = "选择一个被复制数据库文件";
- string dbPath2 = "";
- if (openFileDialog2.ShowDialog() ?? false)
- {
- dbPath = openFileDialog2.FileName;
- }
- DataBase dataBase2 = new DataBase(dbPath);
- bool readDb2 = dataBase2.ReadDataBase();
- if (readDb2)
- {
- allImgInfo2 = dataBase2._allImages;
- if (allImgInfo2.Count > 0)
- {
- MessageBox.Show("加载成功!");
- }
- }
- else
- {
- MessageBox.Show("读取失败!");
- return;
- }
- ///////////////////////////////
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- //Bitmap img = new Bitmap(filename);
- string imgName = System.IO.Path.GetFileNameWithoutExtension(filename);
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- string[] strs2 = temp.Split(new char[4] { '.', 'j', 'p', 'g' }, 2);
- string ImgId = strs2[0];
- int imgIndex = _allImgInfo.FindIndex(x => x.ImageId == ImgId);
- int numLesions = _allImgInfo[imgIndex].Lesions.Count;
- int imgIndex_2 = allImgInfo2.FindIndex(x => x.ImageId == ImgId);
- int numLesions_2 = allImgInfo2[imgIndex].Lesions.Count;
- if (imgIndex >= 0 && numLesions > 0 && imgIndex_2 >=0 && numLesions_2 > 0)
- {
- //AddExistImage(ImgId);
- //SetLesions(ImgId, allImgInfo2[imgIndex_2].Lesions);//添加病灶信息
- SetThyroidContour(ImgId, allImgInfo2[imgIndex_2].ThyroidContour);//添加甲状腺轮廓
- }
- else
- {
- MessageBox.Show("Id未找到:" + ImgId);
- }
- }
- }
- MessageBox.Show("完成!");
- }
- /// <summary>
- /// 整个检测流程全部使用模型给出的结果
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnDBModelResultPredictImages(object sender, RoutedEventArgs e)
- {
- if(_currentImg != null)
- {
- string name = "sos";
- DescriAlgorithmModelAll(name,false);
- //DoDescriAlgorithmModel(name);
- }
- else
- {
- MessageBox.Show("请先加载待测图像!");
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="name"></param>
- /// <param name="bStatistics"></param> 是否需要统计检测结果。(如果使用全模型,模型检测的病灶可能和医生标注的不同,慎重使用)
- private void DescriAlgorithmModelAll(string name, bool bStatistics)
- {
- if (_currentImg == null)
- {
- MessageBox.Show("请先加载待测图像!");
- return;
- }
- Bitmap bmp = _currentImg;
- AI.Common.Interface.RawImage rawImg = RawImageShowUtils.BitmapToRawImage(bmp);
- _caseId = Guid.NewGuid().ToString();
- _dataId = name;
- _readingVideo = false;
- var extendData = new Dictionary<string, object>();
- extendData.Add("CaseId", _caseId);
- extendData.Add("DataId", _dataId);
- extendData.Add("IsVideo", _readingVideo);
- extendData.Add("TimeStamp", (double)_frameIndex);
- _processId = _module.StartProcess();
- var input = new ImageInputData(rawImg, extendData);
- IDetectedObject[] result = _module.PushOnePieceOfData(_processId, input);
- _module.EndProcess(_processId);
- Bitmap dstimage = (Bitmap)_currentImg.Clone();
- int lesionNum = 0;
- string strDescriptionEcho = string.Empty;
- string strDescriptionShape = string.Empty;
- string strDescriptionMargin = string.Empty;
- string strDescriptionEchogenicFoci = string.Empty;
- System.Drawing.PointF[] axisH = new PointF[2];
- System.Drawing.PointF[] axisV = new PointF[2];
- int index = 0;
- foreach (var moduleResult in result)
- {
- var label = moduleResult.Label;
- var nameOrgan = label.GroupName;
- if (nameOrgan != "AI.Vaid.Thyroid.Lesion")
- {
- continue;
- }
- if (moduleResult.Contour == null || moduleResult.Measurements == null || moduleResult.Description == null)
- {
- }
- if (label.Name == "NoObviousLesion" || label.Name == "DiffuseDisease")
- {
- return;
- }
- var resultConversion = AIModuleResultShowUtils.GetObjectStr(moduleResult);
- if (moduleResult.Contour?.Contours.Length > 0)
- {
- //Point2D[] contourCppThyroid = new Point2D[numTotalPtsThyroid];
- //int index = 0;
- //for (int ni = 0; ni < numContourThyroid; ni++)
- //{
- // for (int nj = 0; nj < contourLenThyroid[ni]; nj++)
- // {
- // contourCppThyroid[index] = thyroidContours[ni].OuterContours[0].Points[nj];
- // index += 1;
- // }
- //}
- int count = moduleResult.Contour.Contours.Length;
- for (int i = 0; i < count; i++)
- {
- var organPoints = moduleResult.Contour.OuterContours[i];
- int organPtsCount = organPoints.Points.Length;
- var organCount = new List<System.Windows.Point>();
- System.Drawing.PointF[] organContour = new PointF[organPtsCount];
- //for (int j = 0; j < organPtsCount; j++)
- //{
- // var point = new System.Windows.Point(organPoints.Points[j].X, organPoints.Points[j].Y);
- // organContour[j].X = organPoints.Points[j].X;
- // organContour[j].Y = organPoints.Points[j].Y;
- //}
- var contourPoints = moduleResult.Contour.Contours[i];
- int pointCount = contourPoints.Points.Length;
- var points = new List<System.Windows.Point>();
- System.Drawing.PointF[] lesionContour = new PointF[pointCount];
- for (int j = 0; j < pointCount; j++)
- {
- var point = new System.Windows.Point(contourPoints.Points[j].X, contourPoints.Points[j].Y);
- lesionContour[j].X = contourPoints.Points[j].X;
- lesionContour[j].Y = contourPoints.Points[j].Y;
- }
- var desResult = moduleResult.Description;
- var type = desResult.GetType();
- EchogenicFociEnum echoFoci = new EchogenicFociEnum();
- EchoPatternEnum echo = new EchoPatternEnum();
- ShapeEnum shape = new ShapeEnum();
- MarginEnum margin = new MarginEnum();
- string strDescription = string.Empty;
- {
- foreach (var key in desResult.Descriptions.Keys)
- {
- if (key == "Shape")
- {
- string des = string.Empty;
- switch (desResult.Descriptions[key])
- {
- case "WiderThanTall":
- des = "水平位";
- shape = ShapeEnum.WiderThanTall;
- break;
- case "TallThanWider":
- des = "垂直位";
- shape = ShapeEnum.TallThanWider;
- break;
- }
- strDescription += "形状:" + des + Environment.NewLine;
- }
- if (key == "EchoPattern")
- {
- string des = string.Empty;
- switch (desResult.Descriptions[key])
- {
- case "Anechoic":
- des = "无回声";
- echo = EchoPatternEnum.Anechoic;
- break;
- case "Hyperechoic":
- des = "高回声";
- echo = EchoPatternEnum.Hyperechoic;
- break;
- case "Isoechoic":
- des = "等回声";
- echo = EchoPatternEnum.Isoechoic;
- break;
- case "Hypoechoic":
- des = "低回声";
- echo = EchoPatternEnum.Hypoechoic;
- break;
- case "HypoechoicLower":
- des = "极低回声";
- echo = EchoPatternEnum.HypoechoicLower;
- break;
- }
- strDescription += "回声类型:" + des + Environment.NewLine;
- }
- if (key == "Margin")
- {
- string des = string.Empty;
- switch (desResult.Descriptions[key])
- {
- case "Smooth":
- des = "光滑";
- margin = MarginEnum.Smooth;
- break;
- case "IllDefined":
- des = "不清晰";
- margin = MarginEnum.IllDefined;
- break;
- case "Lobulated":
- des = "分叶";
- margin = MarginEnum.Lobulated;
- break;
- case "Irregular":
- des = "不规则";
- margin = MarginEnum.Irregular;
- break;
- case "ExtraThyroidalExtension":
- des = "甲状腺外扩";
- margin = MarginEnum.ExtraThyroidalExtension;
- break;
- }
- strDescription += "边缘:" + des + Environment.NewLine;
- }
- if (key == "EchogenicFoci")
- {
- string des = string.Empty;
- switch (desResult.Descriptions[key])
- {
- case "NoCifications":
- des = "无钙化";
- echoFoci = EchogenicFociEnum.NoCifications;
- break;
- case "Coarsecalcifications":
- des = "粗钙化";
- echoFoci = EchogenicFociEnum.Coarsecalcifications;
- break;
- case "Microcalcifications":
- des = "微钙化";
- echoFoci = EchogenicFociEnum.Microcalcifications;
- break;
- }
- strDescription += "钙化:" + des + Environment.NewLine;
- }
- }
- }
- var rect = moduleResult.BoundingBox.Contour.BoundingBox();
- var roiBox = moduleResult.BoundingBox;
- var ss = roiBox.Contour.Points;
- var lesionSize = Array.Find(moduleResult.Measurements, x => x.GetType() == typeof(TransverseLongitudinalDiameterMeasurement));
- var size = (TransverseLongitudinalDiameterMeasurement)lesionSize;
- var pointLineH1 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineStart.X, size.TransverseDiameterMarkPosition.LineStart.Y);
- var pointLineH2 = new System.Windows.Point(size.TransverseDiameterMarkPosition.LineEnd.X, size.TransverseDiameterMarkPosition.LineEnd.Y);
- var pointLineV1 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineStart.X, size.LongitudinalDiameterMarkPosition.LineStart.Y);
- var pointLineV2 = new System.Windows.Point(size.LongitudinalDiameterMarkPosition.LineEnd.X, size.LongitudinalDiameterMarkPosition.LineEnd.Y);
- axisH[0].X = (int)pointLineH1.X;
- axisH[0].Y = (int)pointLineH1.Y;
- axisH[1].X = (int)pointLineH2.X;
- axisH[1].Y = (int)pointLineH2.Y;
- axisV[0].X = (int)pointLineV1.X;
- axisV[0].Y = (int)pointLineV1.Y;
- axisV[1].X = (int)pointLineV2.X;
- axisV[1].Y = (int)pointLineV2.Y;
- using (var g = Graphics.FromImage(dstimage))
- {
- if(organContour.Length >1)
- {
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Green, 2);
- g.DrawLines(pen, organContour); //画病灶轮廓
- pen.Dispose();
- }
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- System.Drawing.Rectangle lesionBox = new System.Drawing.Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top);
- g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- pen3.Dispose();
- if (lesionContour.Length > 1)//画直线要超过一个点
- {
- System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Brushes.Orange, 2);
- g.DrawLines(pen, lesionContour); //画病灶轮廓
- pen.Dispose();
- }
- //画轮廓的长短轴
- System.Drawing.Pen pen_h = new System.Drawing.Pen(System.Drawing.Brushes.PaleGreen, 2);
- g.DrawLines(pen_h, axisH); //横轴,浅绿色
- System.Drawing.Pen pen_v = new System.Drawing.Pen(System.Drawing.Brushes.Red, 1);
- g.DrawLines(pen_v, axisV); //纵轴,红色
- SolidBrush drawBrush = new SolidBrush(System.Drawing.Color.GreenYellow);
- g.DrawString(lesionNum.ToString(), new Font("Arial", 20),
- drawBrush, lesionBox.Left, lesionBox.Top);
- g.DrawString(strDescription, new Font("Arial", 20),
- drawBrush, rect.Top + 10, rect.Top + 10);
- g.Dispose();
- }
- if(bStatistics)
- {
- EchogenicFociEnum echoFociGT = _allImgInfo[_currentImgIdex].Lesions[index].EchogenicFoci;
- EchoPatternEnum echoGT = _allImgInfo[_currentImgIdex].Lesions[index].EchoPattern;
- ShapeEnum shapeCppGT = _allImgInfo[_currentImgIdex].Lesions[index].Shape;
- MarginEnum marginGT = _allImgInfo[_currentImgIdex].Lesions[index].Margin;
- if (echoFociGT == echoFoci)
- {
- if (echoFoci == EchogenicFociEnum.NoCifications)
- {
- _NoCifications_NoCifications_num++;
- }
- if (echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Coarsecalcifications_Coarsecalcifications_num++;
- }
- if (echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Macrocalcifications_Macrocalcifications_num++;
- }
- }
- else
- {
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _NoCifications_Coarsecalcifications_num++;
- }
- if (echoFociGT == EchogenicFociEnum.NoCifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _NoCifications_Macrocalcifications_num++;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Coarsecalcifications_NoCifications_num++;
- }
- if (echoFociGT == EchogenicFociEnum.Coarsecalcifications && echoFoci == EchogenicFociEnum.Microcalcifications)
- {
- _Coarsecalcifications_Macrocalcifications_num++;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.NoCifications)
- {
- _Macrocalcifications_NoCifications_num++;
- }
- if (echoFociGT == EchogenicFociEnum.Microcalcifications && echoFoci == EchogenicFociEnum.Coarsecalcifications)
- {
- _Macrocalcifications_Coarsecalcifications_num++;
- }
- }
- if (echoGT == echo)
- {
- if (echo == EchoPatternEnum.Anechoic)
- {
- _Anechoic_Anechoi_num++;
- }
- if (echo == EchoPatternEnum.Hyperechoic)
- {
- _Hyperechoic_Hyperechoic_num++;
- }
- if (echo == EchoPatternEnum.Isoechoic)
- {
- _Isoechoic_Isoechoic_num++;
- }
- if (echo == EchoPatternEnum.Hypoechoic)
- {
- _Hypoechoic_Hypoechoic_num++;
- }
- if (echo == EchoPatternEnum.HypoechoicLower)
- {
- _HypoechoicLower_HypoechoicLower_num++;
- }
- }
- else
- {
- //把无回声判为其它
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Anechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Anechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Anechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Anechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Anechoic_HypoechoicLower_num++;
- }
- //把高回声判为其它
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hyperechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hyperechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Hyperechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hyperechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hyperechoic_HypoechoicLower_num++;
- }
- //把等回声判为其它
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Isoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Isoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.Hypoechoic)
- {
- _Isoechoic_Hypoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Isoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Isoechoic_HypoechoicLower_num++;
- }
- //低回声判为其它
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Anechoic)
- {
- _Hypoechoic_Anechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Hyperechoic)
- {
- _Hypoechoic_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.Isoechoic)
- {
- _Hypoechoic_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.Hypoechoic && echo == EchoPatternEnum.HypoechoicLower)
- {
- _Hypoechoic_HypoechoicLower_num++;
- }
- //极低回声判为其它
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Anechoic)
- {
- _HypoechoicLower_Anechoicr_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hyperechoic)
- {
- _HypoechoicLower_Hyperechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Isoechoic)
- {
- _HypoechoicLower_Isoechoic_num++;
- }
- if (echoGT == EchoPatternEnum.HypoechoicLower && echo == EchoPatternEnum.Hypoechoic)
- {
- _HypoechoicLower_Hypoechoic_num++;
- }
- }
- if (shapeCppGT == shape)
- {
- if (shape == ShapeEnum.WiderThanTall)
- {
- _WT_WT_num++;
- }
- if (shape == ShapeEnum.TallThanWider)
- {
- _TW_TW_num++;
- }
- }
- else
- {
- //把 宽大于高 判为 高大于宽
- if (shapeCppGT == ShapeEnum.WiderThanTall && shape == ShapeEnum.TallThanWider)
- {
- _WT_TW_num++;
- //WriteTxtToFile("E:\\image\\", "sssttt.txt", resShape.ToString(), false);
- }
- if (shapeCppGT == ShapeEnum.TallThanWider && shape == ShapeEnum.WiderThanTall)
- {
- _TW_WT_num++;
- }
- }
- if (marginGT == margin)
- {
- if (margin == MarginEnum.Smooth)
- {
- _Smooth_Smooth_num++;
- }
- if (margin == MarginEnum.IllDefined)
- {
- _IllDefined_IllDefined_num++;
- }
- if (margin == MarginEnum.Lobulated)
- {
- _Lobulated_Lobulated_num++;
- }
- if (margin == MarginEnum.Irregular)
- {
- _Irregular_Irregular_num++;
- }
- if (margin == MarginEnum.ExtraThyroidalExtension)
- {
- _ExtraThyroidalExtension_ExtraThyroidalExtension_num++;
- }
- }
- else
- {
- //把 边缘光整 判成其它
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.IllDefined)
- {
- _Smooth_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Lobulated)
- {
- _Smooth_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.Irregular)
- {
- _Smooth_Irregular_num++;
- }
- if (marginGT == MarginEnum.Smooth && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Smooth_ExtraThyroidalExtension_num++;
- }
- //把 边缘模糊 判成其它
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Smooth)
- {
- _IllDefined_Smooth_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Lobulated)
- {
- _IllDefined_Lobulated_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.Irregular)
- {
- _IllDefined_Irregular_num++;
- }
- if (marginGT == MarginEnum.IllDefined && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _IllDefined_ExtraThyroidalExtension_num++;
- }
- //把 边缘分叶状 判成其它
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Smooth)
- {
- _Lobulated_Smooth_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.IllDefined)
- {
- _Lobulated_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.Irregular)
- {
- _Lobulated_Irregular_num++;
- }
- if (marginGT == MarginEnum.Lobulated && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Lobulated_ExtraThyroidalExtension_num++;
- }
- //把 边缘不规则 判成其它
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Smooth)
- {
- _Irregular_Smooth_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.IllDefined)
- {
- _Irregular_IllDefined_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.Lobulated)
- {
- _Irregular_Lobulated_num++;
- }
- if (marginGT == MarginEnum.Irregular && margin == MarginEnum.ExtraThyroidalExtension)
- {
- _Irregular_ExtraThyroidalExtension_num++;
- }
- //把 甲状腺外侵犯 判成其它
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Smooth)
- {
- _ExtraThyroidalExtension_Smooth_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.IllDefined)
- {
- _ExtraThyroidalExtension_IllDefined_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Lobulated)
- {
- _ExtraThyroidalExtension_Lobulated_num++;
- }
- if (marginGT == MarginEnum.ExtraThyroidalExtension && margin == MarginEnum.Irregular)
- {
- _ExtraThyroidalExtension_Irregular_num++;
- }
- }
- }
- }
- //string name = newPath + "\\05\\" + imgName + ".png";
- //dstimage.Save(name, System.Drawing.Imaging.ImageFormat.Png);
- }
- index++;
- }
-
- EchoPatternDescri.Text = strDescriptionEcho;
- ShapeDescri.Text = strDescriptionShape;
- MarginDescri.Text = strDescriptionMargin;
- EchogenicFociDescri.Text = strDescriptionEchogenicFoci;
- _dstImg = ImageUtility.BitmapToBitmapImage(dstimage);
- Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
- {
- DstImage.Source = _dstImg;
- }));
- dstimage.Dispose();
- }
- private AI.Common.Interface.Rect CorrectRoi(AI.Common.Interface.Rect imgRoi, AI.Common.Interface.Rect lesionRoi)
- {
- int boundBoxOffset = 25;
- int correctedLesionLeft = Math.Min(Math.Max(lesionRoi.Left - boundBoxOffset, imgRoi.Left), imgRoi.Right);
- int correctedLesionRight = Math.Min(Math.Max(lesionRoi.Right + boundBoxOffset, imgRoi.Left), imgRoi.Right);
- int correctedLesionTop = Math.Min(Math.Max(lesionRoi.Top - boundBoxOffset, imgRoi.Top), imgRoi.Bottom);
- int correctedLesionBottom = Math.Min(Math.Max(lesionRoi.Bottom + boundBoxOffset, imgRoi.Top), imgRoi.Bottom);
- if (correctedLesionRight < correctedLesionLeft)
- {
- correctedLesionRight = correctedLesionLeft;
- }
- if (correctedLesionBottom < correctedLesionTop)
- {
- correctedLesionBottom = correctedLesionTop;
- }
- int correctedLesionWidth = correctedLesionRight - correctedLesionLeft;
- int correctedLesionHeight = correctedLesionBottom - correctedLesionTop;
- return new AI.Common.Interface.Rect(correctedLesionLeft, correctedLesionTop, correctedLesionWidth, correctedLesionHeight);
- }
- private void OnDBAllModelResultPredictImages(object sender, RoutedEventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "图片文件|*.png;*.bmp;*.jpg;*.jpeg";
- openFileDialog.Multiselect = true;
- openFileDialog.Title = "选择一幅或多幅图像";
- if (openFileDialog.ShowDialog() ?? false)
- {
- foreach (string filename in openFileDialog.FileNames)
- {
- Bitmap img = new Bitmap(filename);
- _currentImg = img;
- string temp;
- int idx = filename.LastIndexOf("\\");
- temp = filename.Substring(idx);
- string[] strs1 = temp.Split('\\');
- temp = strs1[1];
- string[] sArray = null;
- sArray = System.Text.RegularExpressions.Regex.Split(temp, ".jpg", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
- string ImgId = sArray[0];
- //WriteTxtToFile("E:\\image\\", "name.txt", ImgId, false);
- _currentImgId = ImgId;
- int imgIdx = _allImgInfo.FindIndex(x => x.ImageId == _currentImgId);
- if (imgIdx < 0)
- {
- WriteTxtToFile("E:\\image\\", "notname.txt", ImgId, false);
- //continue;
- }
- _currentImgIdex = imgIdx;
- DescriAlgorithmModelAll(ImgId,false);
- }
- }
- Console.WriteLine("无钙化 -> 无钙化: " + _NoCifications_NoCifications_num);
- Console.WriteLine("无钙化 -> 粗钙化: " + _NoCifications_Coarsecalcifications_num);
- Console.WriteLine("无钙化 -> 微钙化: " + _NoCifications_Macrocalcifications_num);
- Console.WriteLine("粗钙化 -> 粗钙化: " + _Coarsecalcifications_Coarsecalcifications_num);
- Console.WriteLine("粗钙化 -> 无钙化: " + _Coarsecalcifications_NoCifications_num);
- Console.WriteLine("粗钙化 -> 微钙化: " + _Coarsecalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 微钙化: " + _Macrocalcifications_Macrocalcifications_num);
- Console.WriteLine("微钙化 -> 无钙化: " + _Macrocalcifications_NoCifications_num);
- Console.WriteLine("微钙化 -> 粗钙化: " + _Macrocalcifications_Coarsecalcifications_num);
- Console.WriteLine();
- Console.WriteLine("无回声 -> 无回声: " + _Anechoic_Anechoi_num);
- Console.WriteLine("无回声 -> 高回声: " + _Anechoic_Hyperechoic_num);
- Console.WriteLine("无回声 -> 等回声: " + _Anechoic_Isoechoic_num);
- Console.WriteLine("无回声 -> 低回声: " + _Anechoic_Hypoechoic_num);
- Console.WriteLine("无回声 -> 极低回声: " + _Anechoic_HypoechoicLower_num);
- Console.WriteLine("高回声 -> 高回声: " + _Hyperechoic_Hyperechoic_num);
- Console.WriteLine("高回声 -> 无回声: " + _Hyperechoic_Anechoic_num);
- Console.WriteLine("高回声 -> 等回声: " + _Hyperechoic_Isoechoic_num);
- Console.WriteLine("高回声 -> 低回声: " + _Hyperechoic_Hypoechoic_num);
- Console.WriteLine("高回声 -> 极低回声: " + _Hyperechoic_HypoechoicLower_num);
- Console.WriteLine("等回声 -> 等回声: " + _Isoechoic_Isoechoic_num);
- Console.WriteLine("等回声 -> 无回声: " + _Isoechoic_Anechoic_num);
- Console.WriteLine("等回声 -> 高回声: " + _Isoechoic_Hyperechoic_num);
- Console.WriteLine("等回声 -> 低回声: " + _Isoechoic_Hypoechoic_num);
- Console.WriteLine("等回声 -> 极低回声: " + _Isoechoic_HypoechoicLower_num);
- Console.WriteLine("低回声 -> 低回声: " + _Hypoechoic_Hypoechoic_num);
- Console.WriteLine("低回声 -> 无回声: " + _Hypoechoic_Anechoic_num);
- Console.WriteLine("低回声 -> 高回声: " + _Hypoechoic_Hyperechoic_num);
- Console.WriteLine("低回声 -> 等回声: " + _Hypoechoic_Isoechoic_num);
- Console.WriteLine("低回声 -> 极低回声: " + _Hypoechoic_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 极低回声: " + _HypoechoicLower_HypoechoicLower_num);
- Console.WriteLine("极低回声 -> 无回声: " + _HypoechoicLower_Anechoicr_num);
- Console.WriteLine("极低回声 -> 高回声: " + _HypoechoicLower_Hyperechoic_num);
- Console.WriteLine("极低回声 -> 等回声: " + _HypoechoicLower_Isoechoic_num);
- Console.WriteLine("极低回声 -> 低回声: " + _HypoechoicLower_Hypoechoic_num);
- Console.WriteLine();
- Console.WriteLine("形状: ");
- Console.WriteLine("宽大于高 -> 宽大于高: " + _WT_WT_num);
- Console.WriteLine("宽大于高 -> 高大于宽: " + _WT_TW_num);
- Console.WriteLine("高大于宽 -> 高大于宽: " + _TW_TW_num);
- Console.WriteLine("高大于宽 -> 宽大于高: " + _TW_WT_num);
- Console.WriteLine();
- Console.WriteLine("边缘: ");
- Console.WriteLine("边缘光整 -> 边缘光整: " + _Smooth_Smooth_num);
- Console.WriteLine("边缘光整 -> 边缘模糊: " + _Smooth_IllDefined_num);
- Console.WriteLine("边缘光整 -> 边缘分叶状: " + _Smooth_Lobulated_num);
- Console.WriteLine("边缘光整 -> 边缘不规则: " + _Smooth_Irregular_num);
- Console.WriteLine("边缘光整 -> : 甲状腺外侵犯" + _Smooth_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘模糊 -> 边缘模糊: " + _IllDefined_IllDefined_num);
- Console.WriteLine("边缘模糊 -> 边缘光整: " + _IllDefined_Smooth_num);
- Console.WriteLine("边缘模糊 -> 边缘分叶状: " + _IllDefined_Lobulated_num);
- Console.WriteLine("边缘模糊 -> 边缘不规则: " + _IllDefined_Irregular_num);
- Console.WriteLine("边缘模糊 -> 甲状腺外侵犯: " + _IllDefined_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘分叶状 -> 边缘分叶状: " + _Lobulated_Lobulated_num);
- Console.WriteLine("边缘分叶状 -> 边缘光整: " + _Lobulated_Smooth_num);
- Console.WriteLine("边缘分叶状 -> 边缘模糊: " + _Lobulated_IllDefined_num);
- Console.WriteLine("边缘分叶状 -> 边缘不规则: " + _Lobulated_Irregular_num);
- Console.WriteLine("边缘分叶状 -> 甲状腺外侵犯: " + _Lobulated_ExtraThyroidalExtension_num);
- Console.WriteLine("边缘不规则 -> 边缘不规则: " + _Irregular_Irregular_num);
- Console.WriteLine("边缘不规则 -> 边缘光整: " + _Irregular_Smooth_num);
- Console.WriteLine("边缘不规则 -> 边缘模糊: " + _Irregular_IllDefined_num);
- Console.WriteLine("边缘不规则 -> 边缘分叶状: " + _Irregular_Lobulated_num);
- Console.WriteLine("边缘不规则 -> 甲状腺外侵犯: " + _Irregular_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 甲状腺外侵犯: " + _ExtraThyroidalExtension_ExtraThyroidalExtension_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘光整: " + _ExtraThyroidalExtension_Smooth_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘模糊: " + _ExtraThyroidalExtension_IllDefined_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘分叶状: " + _ExtraThyroidalExtension_Lobulated_num);
- Console.WriteLine("甲状腺外侵犯 -> 边缘不规则: " + _ExtraThyroidalExtension_Irregular_num);
- Console.WriteLine();
- }
- public void SaveModelResult(Bitmap image, int imageId, string imageName,string descriptionMargin)
- {
- _currentBinPath = System.Environment.CurrentDirectory;
- string newPath = System.IO.Path.Combine(_currentBinPath, "result");
- System.IO.Directory.CreateDirectory(newPath);
- int imgNum = _allImgInfo.Count;
- if (image == null || _allImgInfo.Count <= 0)
- {
- return;
- }
-
- //List<MyPoint> thyroidCont = _allImgInfo[imageId].ThyroidContour;
- //int num1 = thyroidCont.Count;
- int path = 0;
- if (_allImgInfo[imageId].Lesions.Count <= 0)
- {
- string name = newPath + "\\" + imageName + "_M.png";
- //image.Save(name, System.Drawing.Imaging.ImageFormat.Png);
- }
- else
- {
- Bitmap origImg = image;
- using (var g = Graphics.FromImage(origImg))
- {
- System.Drawing.Pen pen3 = new System.Drawing.Pen(System.Drawing.Brushes.Navy, 2);
- //Rectangle lesionBox = new Rectangle(roi.x, roi.y, roi.width, roi.height);
- //g.DrawRectangle(pen3, lesionBox); //画病灶矩形框
- //System.Drawing.PointF[] thyroidContour = new PointF[num1];
- Font drawFont = new Font("黑体", 24);
- SolidBrush drawBrush = new SolidBrush(Color.GreenYellow);
- float x = 10.0f;
- float y = 0.0f + 20;
- string drawText = descriptionMargin;//
- g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * 4);
- //drawText = shape;
- //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 1));
- //drawText = margin;
- //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 2));
- //drawText = echogenicFoci;
- //g.DrawString(drawText, drawFont, drawBrush, x, y + 30 * (4 * jj + 3));
- g.Dispose();
- }
- string name = newPath + "\\" + imageName + "_M.png";
- origImg.Save(name, System.Drawing.Imaging.ImageFormat.Png);
- origImg.Dispose();
- }
- }
- }
- }
|