Example #1
0
        //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;
            }
        }
Example #2
0
        public static ImageCache GetData(string file, int frameNumber)
        {
            ImageCache cache = null;

            if (AppUtil.ImageCacheMax > 0)
            {
                var key = string.Format("{0}:{1}", file, frameNumber);
                if (dict.ContainsKey(key))
                {
                    dict[key].accessDate = new TimeSpan(DateTime.Now.Ticks);
                    cache = dict[key];
                }
                else
                {
                    lock (dict)
                    {
                        if (dict.ContainsKey(key))
                        {
                            dict[key].accessDate = new TimeSpan(DateTime.Now.Ticks);
                            cache = dict[key];
                        }
                        else
                        {
                            cache = new ImageCache();
                            dict.Add(key, cache);
                        }
                    }
                }

                if (cache.IsLoad)
                {
                    return(cache);
                }
            }
            else
            {
                cache = new ImageCache();
            }

            lock (syncImage)
            {
                if (cache.IsLoad)
                {
                    return(cache);
                }

                using (var dcm = new DicomData(file))
                {
                    if (!dcm.Images.Load())
                    {
                        return(null);
                    }

                    var ctrl = dcm.Images.CreateImageControl(frameNumber);

                    var data = DicomSplitData.Open(dcm);
                    var lvl  = data.CreateTopLevel(0, ctrl);

                    cache.Load(lvl);
                }

                return(cache);
            }
        }
Example #3
0
        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;
        }