using System; using System.Drawing; using System.Windows.Media.Imaging; using System.Drawing.Imaging; using System.Runtime.InteropServices; namespace ThyroidDescriptionUI { //回声 public enum EchoPatternEnum { Anechoic, // 无回声 Hyperechoic, // 高回声 Isoechoic, // 等回声 Hypoechoic, // 低回声 HypoechoicLower, // 极低回声 } //形状 public enum ShapeEnum { WiderThanTall, // 宽大于高 水平位(Wider-than-tall) TallThanWider, // 高大于宽 垂直位(Taller-than-wide) } //边缘 public enum MarginEnum { Smooth, // 边缘光整 IllDefined, // 边缘模糊 Lobulated, // 边缘分叶状 Irregular, // 边缘不规则 ExtraThyroidalExtension, // 甲状腺外侵犯 } //局灶性强回声 public enum EchogenicFociEnum { NoCifications, //无钙化 Coarsecalcifications, //粗钙化 Microcalcifications, //微钙化 } public struct roiCoor { public int x; public int y; public int width; public int height; } public class MyPoint { public int X { get; set; } public int Y { get; set; } public MyPoint(int x, int y) { X = x; Y = y; } } [StructLayout(LayoutKind.Sequential)] public struct StructPoint { public int X; public int Y; } /// 病灶轮廓的纵、横轴的坐标点 public struct AxisPoint { public StructPoint horizontalPt1; // 病灶轮廓的 横轴(水平方向) 端点坐标 public StructPoint horizontalPt2; public StructPoint verticalPt1; // 病灶轮廓的 纵轴 端点坐标 public StructPoint verticalPt2; } public struct LesionDescri { public int shape; public int echo; public int margin; public int echogenicFoci; public AxisPoint axisPt; } public static class ImageUtility { public static BitmapImage BitmapToBitmapImage(Bitmap img) { BitmapImage bmpimg = new BitmapImage(); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { img.Save(ms, ImageFormat.Png); bmpimg.BeginInit(); bmpimg.StreamSource = ms; bmpimg.CacheOption = BitmapCacheOption.OnLoad; bmpimg.EndInit(); bmpimg.Freeze(); ms.Dispose(); } return bmpimg; } } public class SegDataInput { /// 输入图像 public Bitmap InputImage { get; set; } = null; /// 感兴趣区域 public Rectangle InputRoi { get; set; } = Rectangle.Empty; /// 构造函数 public SegDataInput(Bitmap img, Rectangle rect) { InputImage = (Bitmap)img.Clone(); InputRoi = rect; } public void Dispose() { InputImage?.Dispose(); } } //public class RawImage //{ // public byte[] DataBuffer // { // get; // set; // } // public int Width // { // get; // set; // } // public int Height // { // get; // set; // } // public int Channel // { // get; // set; // } // public RawImage() // { // DataBuffer = null; // Width = 0; // Height = 0; // Channel = 0; // } // public RawImage(byte[] data, int width, int height, int channel) // { // DataBuffer = data; // Width = width; // Height = height; // Channel = channel; // } // public RawImage CropRect(MyRect rect) // { // int width = Width; // int height = Height; // int channel = Channel; // byte[] dataBuffer = DataBuffer; // if (rect == null) // { // return null; // } // int left = rect.Left; // int right = rect.Right; // int top = rect.Top; // int bottom = rect.Bottom; // int width2 = rect.Width; // int height2 = rect.Height; // if (left < 0 || left > width - 1) // { // throw new ArgumentOutOfRangeException("rect.Left", "Left of the crop rect is out of the image."); // } // if (right < 0 || right > width) // { // throw new ArgumentOutOfRangeException("rect.Right", "Right of the crop rect is out of the image."); // } // if (top < 0 || top > height - 1) // { // throw new ArgumentOutOfRangeException("rect.Top", "Top of the crop rect is out of the image."); // } // if (bottom < 0 || bottom > height) // { // throw new ArgumentOutOfRangeException("rect.Bottom", "Right of the crop rect is out of the image."); // } // if (left == 0 && top == 0 && width2 == width && height2 == height) // { // int num = dataBuffer.Length; // byte[] array = new byte[num]; // Buffer.BlockCopy(dataBuffer, 0, array, 0, num); // return new RawImage(array, width, height, channel); // } // byte[] array2 = new byte[width2 * height2 * channel]; // int num2 = width2 * channel; // int num3 = top * width * channel + left * channel; // int num4 = width * channel; // for (int i = 0; i < height2; i++) // { // Buffer.BlockCopy(dataBuffer, num3 + i * num4, array2, i * num2, num2); // } // return new RawImage(array2, width2, height2, channel); // } // public void Dispose() // { // DataBuffer = null; // Width = 0; // Height = 0; // Channel = 0; // } //} public class MyRect { public int Left { get; protected set; } public int Top { get; protected set; } public int Right { get; protected set; } public int Bottom { get; protected set; } public int Width { get; protected set; } public int Height { get; protected set; } public MyRect(int left, int top, int width, int height) { if (width < 0) { throw new ArgumentException("width", "Width should be greater than 0."); } if (height < 0) { throw new ArgumentException("height", "Height should be greater than 0"); } Left = left; Top = top; Right = left + width; Bottom = top + height; Width = width; Height = height; } public bool IsEmpty() { return Left == 0 && Right == 0 && Top == 0 && Bottom == 0; } public MyRect() { Left = 0; Right = 0; Top = 0; Bottom = 0; Width = 0; Height = 0; } } }