ImageUtility.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. 
  2. using System;
  3. using System.Drawing;
  4. using System.Windows.Media.Imaging;
  5. using System.Drawing.Imaging;
  6. using System.Runtime.InteropServices;
  7. namespace ThyroidDescriptionUI
  8. {
  9. //回声
  10. public enum EchoPatternEnum
  11. {
  12. Anechoic, // 无回声
  13. Hyperechoic, // 高回声
  14. Isoechoic, // 等回声
  15. Hypoechoic, // 低回声
  16. HypoechoicLower, // 极低回声
  17. }
  18. //形状
  19. public enum ShapeEnum
  20. {
  21. WiderThanTall, // 宽大于高 水平位(Wider-than-tall)
  22. TallThanWider, // 高大于宽 垂直位(Taller-than-wide)
  23. }
  24. //边缘
  25. public enum MarginEnum
  26. {
  27. Smooth, // 边缘光整
  28. IllDefined, // 边缘模糊
  29. Lobulated, // 边缘分叶状
  30. Irregular, // 边缘不规则
  31. ExtraThyroidalExtension, // 甲状腺外侵犯
  32. }
  33. //局灶性强回声
  34. public enum EchogenicFociEnum
  35. {
  36. NoCifications, //无钙化
  37. Coarsecalcifications, //粗钙化
  38. Microcalcifications, //微钙化
  39. }
  40. public struct roiCoor
  41. {
  42. public int x;
  43. public int y;
  44. public int width;
  45. public int height;
  46. }
  47. public class MyPoint
  48. {
  49. public int X
  50. {
  51. get;
  52. set;
  53. }
  54. public int Y
  55. {
  56. get;
  57. set;
  58. }
  59. public MyPoint(int x, int y)
  60. {
  61. X = x;
  62. Y = y;
  63. }
  64. }
  65. [StructLayout(LayoutKind.Sequential)]
  66. public struct StructPoint
  67. {
  68. public int X;
  69. public int Y;
  70. }
  71. /// 病灶轮廓的纵、横轴的坐标点
  72. public struct AxisPoint
  73. {
  74. public StructPoint horizontalPt1; // 病灶轮廓的 横轴(水平方向) 端点坐标
  75. public StructPoint horizontalPt2;
  76. public StructPoint verticalPt1; // 病灶轮廓的 纵轴 端点坐标
  77. public StructPoint verticalPt2;
  78. }
  79. public struct LesionDescri
  80. {
  81. public int shape;
  82. public int echo;
  83. public int margin;
  84. public int echogenicFoci;
  85. public AxisPoint axisPt;
  86. }
  87. public static class ImageUtility
  88. {
  89. public static BitmapImage BitmapToBitmapImage(Bitmap img)
  90. {
  91. BitmapImage bmpimg = new BitmapImage();
  92. using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
  93. {
  94. img.Save(ms, ImageFormat.Png);
  95. bmpimg.BeginInit();
  96. bmpimg.StreamSource = ms;
  97. bmpimg.CacheOption = BitmapCacheOption.OnLoad;
  98. bmpimg.EndInit();
  99. bmpimg.Freeze();
  100. ms.Dispose();
  101. }
  102. return bmpimg;
  103. }
  104. }
  105. public class SegDataInput
  106. {
  107. /// 输入图像
  108. public Bitmap InputImage { get; set; } = null;
  109. /// 感兴趣区域
  110. public Rectangle InputRoi { get; set; } = Rectangle.Empty;
  111. /// 构造函数
  112. public SegDataInput(Bitmap img, Rectangle rect)
  113. {
  114. InputImage = (Bitmap)img.Clone();
  115. InputRoi = rect;
  116. }
  117. public void Dispose()
  118. {
  119. InputImage?.Dispose();
  120. }
  121. }
  122. //public class RawImage
  123. //{
  124. // public byte[] DataBuffer
  125. // {
  126. // get;
  127. // set;
  128. // }
  129. // public int Width
  130. // {
  131. // get;
  132. // set;
  133. // }
  134. // public int Height
  135. // {
  136. // get;
  137. // set;
  138. // }
  139. // public int Channel
  140. // {
  141. // get;
  142. // set;
  143. // }
  144. // public RawImage()
  145. // {
  146. // DataBuffer = null;
  147. // Width = 0;
  148. // Height = 0;
  149. // Channel = 0;
  150. // }
  151. // public RawImage(byte[] data, int width, int height, int channel)
  152. // {
  153. // DataBuffer = data;
  154. // Width = width;
  155. // Height = height;
  156. // Channel = channel;
  157. // }
  158. // public RawImage CropRect(MyRect rect)
  159. // {
  160. // int width = Width;
  161. // int height = Height;
  162. // int channel = Channel;
  163. // byte[] dataBuffer = DataBuffer;
  164. // if (rect == null)
  165. // {
  166. // return null;
  167. // }
  168. // int left = rect.Left;
  169. // int right = rect.Right;
  170. // int top = rect.Top;
  171. // int bottom = rect.Bottom;
  172. // int width2 = rect.Width;
  173. // int height2 = rect.Height;
  174. // if (left < 0 || left > width - 1)
  175. // {
  176. // throw new ArgumentOutOfRangeException("rect.Left", "Left of the crop rect is out of the image.");
  177. // }
  178. // if (right < 0 || right > width)
  179. // {
  180. // throw new ArgumentOutOfRangeException("rect.Right", "Right of the crop rect is out of the image.");
  181. // }
  182. // if (top < 0 || top > height - 1)
  183. // {
  184. // throw new ArgumentOutOfRangeException("rect.Top", "Top of the crop rect is out of the image.");
  185. // }
  186. // if (bottom < 0 || bottom > height)
  187. // {
  188. // throw new ArgumentOutOfRangeException("rect.Bottom", "Right of the crop rect is out of the image.");
  189. // }
  190. // if (left == 0 && top == 0 && width2 == width && height2 == height)
  191. // {
  192. // int num = dataBuffer.Length;
  193. // byte[] array = new byte[num];
  194. // Buffer.BlockCopy(dataBuffer, 0, array, 0, num);
  195. // return new RawImage(array, width, height, channel);
  196. // }
  197. // byte[] array2 = new byte[width2 * height2 * channel];
  198. // int num2 = width2 * channel;
  199. // int num3 = top * width * channel + left * channel;
  200. // int num4 = width * channel;
  201. // for (int i = 0; i < height2; i++)
  202. // {
  203. // Buffer.BlockCopy(dataBuffer, num3 + i * num4, array2, i * num2, num2);
  204. // }
  205. // return new RawImage(array2, width2, height2, channel);
  206. // }
  207. // public void Dispose()
  208. // {
  209. // DataBuffer = null;
  210. // Width = 0;
  211. // Height = 0;
  212. // Channel = 0;
  213. // }
  214. //}
  215. public class MyRect
  216. {
  217. public int Left
  218. {
  219. get;
  220. protected set;
  221. }
  222. public int Top
  223. {
  224. get;
  225. protected set;
  226. }
  227. public int Right
  228. {
  229. get;
  230. protected set;
  231. }
  232. public int Bottom
  233. {
  234. get;
  235. protected set;
  236. }
  237. public int Width
  238. {
  239. get;
  240. protected set;
  241. }
  242. public int Height
  243. {
  244. get;
  245. protected set;
  246. }
  247. public MyRect(int left, int top, int width, int height)
  248. {
  249. if (width < 0)
  250. {
  251. throw new ArgumentException("width", "Width should be greater than 0.");
  252. }
  253. if (height < 0)
  254. {
  255. throw new ArgumentException("height", "Height should be greater than 0");
  256. }
  257. Left = left;
  258. Top = top;
  259. Right = left + width;
  260. Bottom = top + height;
  261. Width = width;
  262. Height = height;
  263. }
  264. public bool IsEmpty()
  265. {
  266. return Left == 0 && Right == 0 && Top == 0 && Bottom == 0;
  267. }
  268. public MyRect()
  269. {
  270. Left = 0;
  271. Right = 0;
  272. Top = 0;
  273. Bottom = 0;
  274. Width = 0;
  275. Height = 0;
  276. }
  277. }
  278. }