public static void PutImage(string file, int frameNumber, string[] trace, string outfile) { var data = ImageCache.GetData(file, frameNumber); if (data != null) { var ic = data.splitLevel.ImageControl; using (var img = TraceCapture.ToImage(trace, ic)) { ImageCodecInfo encoder = null; foreach (var ici in ImageCodecInfo.GetImageEncoders()) { if (ici.MimeType == "image/jpeg") { encoder = ici; break; } } var encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)90); img.Save(outfile, encoder, encoderParams); } } }
//hosp public static void GetJpeg(string file, int frameNumber, int level, int cx, int cy, int cw, int ch, double wc, double ww, int rot, int flipX, out byte[] image) { try { image = null; //lock (typeof(ImageUtil)) semaphore.Wait(); try { var data = ImageCache.GetData(file, frameNumber); if (data != null) { DicomSplitLevel lvl; if (level == 0) { lvl = data.splitLevel; } else { lvl = data.splitLevel.CreateLevel(level, true); } var ic = new ImageControl(lvl.GetImage(cx, cy, cw, ch), AppUtil.CELL_SIZE * cw, AppUtil.CELL_SIZE * ch, lvl.ImageControl.PixelSize); ic.Revers = lvl.ImageControl.Revers; ic.IsSign = lvl.ImageControl.IsSign; ic.RescaleIntercept = lvl.ImageControl.RescaleIntercept; ic.RescaleSlope = lvl.ImageControl.RescaleSlope; ic.WindowCenter = wc; ic.WindowWidth = ww; var ic2 = new MyImageControl(ic); ic2.Rotate(rot, flipX != 0); image = ic2.ToJpeg(); } } finally { semaphore.Release(); } } catch { LogUtil.Error(string.Format("GetJpeg({0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10})", file, frameNumber, level, cx, cy, cw, ch, wc, ww, rot, flipX)); throw; } }
public static void GetRoi(string file, int frameNumber, Point p1, Point p2, out RoiItem roi) { roi = new RoiItem(); double minvalue = double.MaxValue; double maxvalue = double.MinValue; double ave = 0; double areasize = 0; double stddev = 0; double total = 0; double x1, y1, x2, y2, w, h, cx, cy; x1 = p1.X < p2.X ? p1.X : p2.X; x2 = p1.X < p2.X ? p2.X : p1.X; y1 = p1.Y < p2.Y ? p1.Y : p2.Y; y2 = p1.Y < p2.Y ? p2.Y : p1.Y; w = x2 - x1; h = y2 - y1; cx = x1 + w / 2; cy = y1 + h / 2; //lock (typeof(ImageUtil)) { var data = ImageCache.GetData(file, frameNumber); if (data != null) { var ic = data.splitLevel.ImageControl; if (ic.PixelSize == 24 || ic.PixelSize == 8) { return; } for (int x = x1 < 0 ? 0 : (int)x1; x < x2 && x < ic.Width; x++) { for (int y = y1 < 0 ? 0 : (int)y1; y < y2 && y < ic.Height; y++) { double px = Math.Abs(x - cx) / w; double py = Math.Abs(y - cy) / h; double len = Math.Sqrt(px * px + py * py); if (len >= 0.5) { continue; } areasize++; var val = ic.swPixels[y * ic.Width + x] * ic.RescaleSlope + ic.RescaleIntercept; total += val; if (minvalue > val) { minvalue = val; } if (maxvalue < val) { maxvalue = val; } } } if (areasize != 0) { ave = total / areasize; double stdsum = 0; for (int x = x1 < 0 ? 0 : (int)x1; x < x2 && x < ic.Width; x++) { for (int y = y1 < 0 ? 0 : (int)y1; y < y2 && y < ic.Height; y++) { double px = Math.Abs(x - cx) / w; double py = Math.Abs(y - cy) / h; double len = Math.Sqrt(px * px + py * py); if (len >= 0.5) { continue; } var val = ic.swPixels[y * ic.Width + x] * ic.RescaleSlope + ic.RescaleIntercept; stdsum += ((float)val - ave) * ((float)val - ave); } } stddev = (float)Math.Sqrt(stdsum / areasize); } } } roi.Minimum = minvalue; roi.Maximum = maxvalue; roi.Average = ave; roi.Area = areasize; roi.StandardDeviation = stddev; }