Пример #1
0
        public CalPAP(UISettings ui, FileData file, ref ConcurrentBag <double> AreaBag) : base(ui, file)
        {
            try {
                MulticolorComponentsLabeling mclabel = new MulticolorComponentsLabeling()
                {
                    Low  = (int)Math.Round(Low_Threshold / ui.um2px2),
                    High = (int)Math.Round(Math.Min(int.MaxValue, High_Threshold / ui.um2px2))
                };

                Invert AFinvert = new Invert();
                UnmanagedResult = mclabel.Apply(AFinvert.Apply(UnmanagedBlackWhite));
                foreach (Blobx blob in mclabel.BlobCounter.blobs)
                {
                    //if (blob.Area<mclabel.Low) {
                    //	Low_count++; Low_sumArea+=blob.Area;
                    //} else if (blob.Area<=mclabel.High) {
                    Normal_count++; Normal_SumArea += ui.um2px2 * blob.Area; AreaBag.Add(ui.um2px2 * blob.Area);
                    //} else {
                    //	High_count++; High_sumArea+=blob.Area;
                    //}
                }

                Total_SumArea = ui.um2px2 * (UnmanagedMarkup.Width * UnmanagedMarkup.Height); // total area
                Lung_SumArea  = Total_SumArea - Low_SumArea - High_SumArea;                   // lung area
                Paren_SumArea = Lung_SumArea - NonParen_SumArea;                              // parenchymal area
                Tis_SumArea   = Paren_SumArea - Normal_SumArea;                               // septum tissue
                Normal_Count  = 1000.0d * 1000.0d * Normal_count / Paren_SumArea;             // counts per reference area

                StringBuilder header = new StringBuilder();
                header.Append($"{FileName}  ps: {ui.PixelScale:G2}/{ui.ResizeValue:G2} px/um"
                              + $"\nlung: {Lung_SumArea:G2}µm\xB2, {Lung_SumArea/Total_SumArea:0%} image (blw: {Low_SumArea/Total_SumArea:0%} ovr: {High_SumArea/Total_SumArea:0%})"
                              + $"\nparenchyma: {Paren_SumArea:G2}µm\xB2, {Paren_SumArea/Lung_SumArea:0%} lung (exc: {NonParen_SumArea/Total_SumArea:0%})"
                              + $"\nseptum: {Tis_SumArea:G2}µm\xB2, {Tis_SumArea/Paren_SumArea:0%} paren (airspace: {Normal_SumArea/Total_SumArea:0%})");

                StringBuilder footer = new StringBuilder();
                footer.Append($"Total #: {mclabel.BlobCounter.blobs.Count}");

                UnmanagedMarkup = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedMarkup.ToManagedImage(false), Color.Black, $"{header}", $"{footer}", null, null, (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
                UnmanagedResult = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedResult.ToManagedImage(false), Color.PaleGreen, $"{header}", $"{footer}", null, null, (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
            } catch { throw new Exception("Error Occured During Airspace Profiling"); }
        }
Пример #2
0
        public CalPAQ1(UISettings ui, FileData f, CalPAC categ = null) : base(ui, f)
        {
            try {
                // low-alv-des-high cut
                if (categ != null)                 // use alv des cutoffs from categorize class
                {
                    Alv_Log_Size = categ.p1Mean;
                    //Sac_Log_Size=categ.p2Mean;
                    //Des_Log_Size=categ.p3Mean;
                    Alv_Size = Math.Pow(10.0d, categ.p1Mean) - 1;
                    //Sac_size=Math.Pow(10.0d, categ.p2Mean)-1;
                    //Des_size=Math.Pow(10.0d, categ.p3Mean)-1;
                    //Alv_Cut=Math.Pow(10.0d, categ.Alv_Log_Cut)-1;
                    DucDes_Threshold = Math.Pow(10.0d, categ.c1_DucDes_CI95_1tail) - 1;
                    //Alv_cut=Alv_Cut/px2um2;
                }
                else                     // alv des cutoffs from ui
                {
                    DucDes_Threshold = Math.Pow(10.0d, ui.BlobDes) - 1;
                }
                DucDes_Log_Threshold = Math.Log10(DucDes_Threshold + 1);

                AreaComponentsLabeling aclabel = new AreaComponentsLabeling()
                {
                    Low  = (int)Math.Round(Low_Threshold / ui.um2px2),
                    High = (int)Math.Round(Math.Min(int.MaxValue, High_Threshold / ui.um2px2)),
                    Alv  = (int)Math.Round(DucDes_Threshold / ui.um2px2),                // use Des_cut to elliminate Sac color
                    Des  = (int)Math.Round(DucDes_Threshold / ui.um2px2)
                };
                Invert AFinvert = new Invert();
                UnmanagedResult = aclabel.Apply(AFinvert.Apply(UnmanagedBlackWhite));
                //Low_count = Low_sumArea = High_count = High_sumArea = 0;
                foreach (Blobx blob in aclabel.BlobCounter.blobs)
                {
                    if (blob.Area <= aclabel.Des)                     // alv/sac
                    {
                        AlvSac_count++; AlvSac_SumArea += ui.um2px2 * blob.Area; AlvSac_SumBoundary += ui.umpx * blob.Perimeter;
                    }
                    else                          // duct/des
                    {
                        DucDes_count++; DucDes_SumArea += ui.um2px2 * blob.Area; DucDes_SumBoundary += ui.umpx * blob.Perimeter;
                    }
                }

                Total_SumArea = ui.um2px2 * (UnmanagedMarkup.Width * UnmanagedMarkup.Height); // total area
                Lung_SumArea  = Total_SumArea - Low_SumArea - High_SumArea;                   // lung area
                Paren_SumArea = Lung_SumArea - NonParen_SumArea;                              // parenchymal area
                Tis_SumArea   = Paren_SumArea - AlvSac_SumArea - DucDes_SumArea;              // septum tissue

                AlvSac_Count    = 1000.0d * 1000.0d * AlvSac_count / Paren_SumArea;
                DucDes_Count    = 1000.0d * 1000.0d * DucDes_count / Paren_SumArea;
                AlvSac_Boundary = 1.0d * AlvSac_SumBoundary / Paren_SumArea;
                DucDes_Boundary = 1.0d * DucDes_SumBoundary / Paren_SumArea;
                AlvSac_Fraction = 1.0d * AlvSac_SumArea / Paren_SumArea;
                DucDes_Fraction = 1.0d * DucDes_SumArea / Paren_SumArea;           // is still better to divide by paren area

                Tis_Fraction     = 1.0d - AlvSac_Fraction - DucDes_Fraction;
                DucDes_Alv_Ratio = DucDes_Fraction / AlvSac_Fraction;

                StringBuilder header = new StringBuilder();
                header.Append($"{FileName}  ps: {ui.PixelScale:G2}/{ui.ResizeValue:G2} px/um" + $"\nduc/des thres:{DucDes_Log_Threshold:0.00} log\x2081\x2080µm\xB2");
                header.Append($"\nlung: {Lung_SumArea:G2}µm\xB2, {(1.0d*Lung_SumArea/Total_SumArea):0%} image (blw: {Low_SumArea/Total_SumArea:0%} ovr: {1.0d*High_SumArea/Total_SumArea:0%})");
                header.Append($"\nparenchyma: {Paren_SumArea:G2}µm\xB2, {(Paren_SumArea/Lung_SumArea):0%} lung (exc: {1.0d*NonParen_SumArea/Total_SumArea:0%})");
                header.Append($"\nseptum: {Tis_SumArea:G2}µm\xB2, {Tis_SumArea/Paren_SumArea:0%} paren (airspace: {(AlvSac_SumArea+DucDes_SumArea)/Total_SumArea:0%})");

                StringBuilder footer = new StringBuilder();
                if (Math.Abs(Alv_Size) > 0.01d)
                {
                    footer.Append($" AS:{Alv_Size:G2} (Size, µm\xB2)");
                }
                footer.Append($"\nASC:{AlvSac_Count:G2} DC:{DucDes_Count:G2} (Count\x2090: 1/mm\xB2)"
                              + $"\nASB:{AlvSac_Boundary:G2} DB:{DucDes_Boundary:G2} (Boundary\x2090, 1/µm)"
                              + $"\nASF:{AlvSac_Fraction:0%} DF:{DucDes_Fraction:0%} (Area\x2090 Fraction, %)"
                              + $"\nTF:{Tis_Fraction:0.0%} D2A:{DucDes_Alv_Ratio:F2} (Fraction, Ratio)");

                UnmanagedMarkup = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedMarkup.ToManagedImage(false), Color.Black, $"{header}", $"{footer}", null, null,     // ,blobs, blobDes.ToArray()
                                                                              (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
                UnmanagedResult = UnmanagedImage.FromManagedImage(AddBlobText(UnmanagedResult.ToManagedImage(false), Color.PaleGreen, $"{header}", $"{footer}", null, null, // ,blobs, blobDes.ToArray()
                                                                              (int)Math.Round(0.02d * UnmanagedMarkup.Width * Math.Sqrt(ui.ExportDetailRatio))));
            } catch { throw new Exception("Error Occured During Airspace Quantification"); }
        }