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
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
#region private variables
private BitmapImage _origImg;
private BitmapImage _dstImg;
private Queue _imagesReadyToDrawBox = new Queue();
private Queue _testDatas = new Queue();
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 _imgNameQueue = new Queue(); // 图像文件名(循环读图)
private List _imgNameList = new List(); // 图像文件名
#endregion
//private AIDiagSystem _aiSeg;
private List _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 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 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;
}
///
/// 将System.Drawimg.Bitmap转为RawImage
///
///
///
///
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 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();
}
}
///
/// 将医生的标注结果保存
///
///
///
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);
}
}
}
}
///
/// 将不同db文件复制到一个文件中(每个db文件中的图像可以选择,不需要db文件中全部图像)
/// 最后获得的db文件不用先生成,由当前函数生成
///
///
///
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 tmpLe = new List();
//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 lesions = new List();
string strLesions = JsonConvert.SerializeObject(lesions);
List thyroidContour = new List();
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 lesions = new List();
string strLesions = JsonConvert.SerializeObject(lesions);
List thyroidContour = new List();
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 lesions = new List();
string strLesions = JsonConvert.SerializeObject(lesions);
List thyroidContour = new List();
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 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 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();
}
///
/// 将文本写入txt文件中
///
/// 文件路径
/// 文件名称
/// 字符串
/// 是否先清空文件
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();
}
///
/// 图像的Id(图像名)在创建db文件时被改变,找到对应的图像,保存新db文件时用旧图像名作为ID
///
///
///
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();
}
}
}
}
///
/// 合并几个db文件,但只保留之前db文件中的甲状腺和病灶的轮廓
/// 第一个选中的db文件要先生成一个基本版(只有所有数据的名称信息,防止出现新数据)。
/// 甲状腺和病灶轮廓存储在第一个db文件中
///
///
///
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 allImgInfo2 = new List();
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 tmpLe = new List();
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
{
}
}
}
///
/// 三份db文件比较,甲状腺病灶四个属性依次比较,根据实际需求保存数据
///
///
///
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 allImgInfo2 = new List();
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 allImgInfo3 = new List();
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 tmpLe = new List();
//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;
}
///
/// 发现标注工具中的保存结果和当前工程中的结果不对应,将结果整理好并保存到新的db文件中
///
///
///
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 lesionsNew = new List();
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 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();
}
///
/// 正在使用的db文件中,一些图片缺少轮廓或者其他数据,需要从其他的db文件复制
/// 第一个db文件为需要添加轮廓数据的文件,添加的轮廓数据保存到当前db文件中
/// 第二个db文件为被复制的文件
/// 然后选择需要添加轮廓信息的图像,根据实际需求添加信息
///
///
///
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 allImgInfo2 = new List();
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("完成!");
}
///
/// 整个检测流程全部使用模型给出的结果
///
///
///
private void OnDBModelResultPredictImages(object sender, RoutedEventArgs e)
{
if(_currentImg != null)
{
string name = "sos";
DescriAlgorithmModelAll(name,false);
//DoDescriAlgorithmModel(name);
}
else
{
MessageBox.Show("请先加载待测图像!");
}
}
///
///
///
///
/// 是否需要统计检测结果。(如果使用全模型,模型检测的病灶可能和医生标注的不同,慎重使用)
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();
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.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.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 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();
}
}
}
}