private void _RenderMicroImage()
        {
            MicroImage microImage = radioButtonPic473.Checked ? this._GetCurrentMicroImage("473") : this._GetCurrentMicroImage("561");

            Image image;

            if (checkBinarize.Checked == true)
            {
                int threshold = (int)nudThreshold.Value;
                image = microImage.GetBinarizedImage(threshold);
            }
            else
            {
                image = microImage.GetImage();
            }

            if (checkEnabled.Checked == true && nudX.Value > 0 && nudY.Value > 0 && nudR.Value > 0)
            {
                int x = (int)nudX.Value;
                int y = (int)nudY.Value;
                int r = (int)nudR.Value;

                Image    tmp = new Bitmap(image.Width, image.Height);
                Graphics g   = Graphics.FromImage(tmp);
                g.DrawImage(image, 0, 0, image.Width, image.Height);

                Pen pen = new Pen(Color.FromArgb(191, Color.LightGray), this._Project.X / 200);
                g.DrawEllipse(pen, x - r, y - r, r * 2, r * 2);
                g.Dispose();

                image = tmp;
            }

            pictureMicroImage.Image = image;
        }
Ejemplo n.º 2
0
        public Analyzer(Project project, int c)
        {
            this._Project = project;
            this.C        = c;

            MicroImage[,] microImages    = new MicroImage[this._Project.Z, this._Project.T];
            MicroImage[,] microImages561 = new MicroImage[this._Project.Z, this._Project.T];

            for (int z = 1; z <= this._Project.Z; z++)
            {
                for (int t = 1; t <= this._Project.T; t++)
                {
                    string file    = this._Project.GetImageFile(this.C, z, t, "473");
                    string file561 = this._Project.GetImageFile(this.C, z, t, "561");
                    microImages[z - 1, t - 1]    = new MicroImage(file, this.C, z, t);
                    microImages561[z - 1, t - 1] = new MicroImage(file561, this.C, z, t);
                }
            }

            this.MicroImages    = microImages;
            this.MicroImages561 = microImages561;
        }
Ejemplo n.º 3
0
        public double[] AnalyzeSpot(AnalyzeAreaSet analyzeAreaSet, int t, int threshold)
        {
            int targetZ = 0;
            //AnalyzeArea analyzeArea = analyzeAreaSet.GetAnalyzeArea(1, t);
            AnalyzeArea analyzeArea = new AnalyzeArea();

            for (int z = 1; z <= this._Project.Z; z++)
            {
                analyzeArea = analyzeAreaSet.GetAnalyzeArea(z, t);

                if (analyzeArea.Enabled)
                {
                    targetZ = z;
                    break;
                }
            }

            if (targetZ == 0)
            {
                return(new double[3]);
            }

            double[]   spots         = new double[3];
            MicroImage microImage473 = this.GetMicroImage(targetZ, t, "473");
            MicroImage microImage561 = this.GetMicroImage(targetZ, t, "561");

            //spots[0] = analyzeArea.Count473;
            //spots[1] = analyzeArea.Count561;

            spots[0] = microImage473.AnalyzeSpot(analyzeArea, threshold);
            spots[1] = microImage561.AnalyzeSpot(analyzeArea, threshold);

            //Integrated Density
            spots[2] = microImage473.AnalyzeLuminance(analyzeArea, threshold);

            return(spots);
        }
        private FillSource _Fill(int z, int t, FillSource source, int threshold)
        {
            MicroImage microImage = this._Analyzer.GetMicroImage(z, t, "473");
            //MicroImage microImage561 = this._Analyzer.GetMicroImage(z, t, "561");
            Bitmap image = microImage.GetBinarizedImage(threshold);
            //Bitmap image561 = microImage561.GetBinarizedImage(threshold);

            ConnectedComponents components = ConnectedComponents.Analyze(image);
            //ConnectedComponents components561 = ConnectedComponents.Analyze(image561);

            Dictionary <int, int> labels = new Dictionary <int, int>();

            int sMinX = (source.MinX < 1) ? 0 : source.MinX;
            int sMaxX = (source.MaxX < 1) ? 0 : source.MaxX;
            int sMinY = (source.MinY < 1) ? 0 : source.MinY;
            int sMaxY = (source.MaxY < 1) ? 0 : source.MaxY;

            if (source.Label > 0)
            {
                for (int x = sMinX; x <= sMaxX; x++)
                {
                    for (int y = sMinY; y <= sMaxY; y++)
                    {
                        int label = components.Labels[x, y];

                        if (label <= 0)
                        {
                            continue;
                        }

                        if (source.Components.Labels[x, y] == source.Label)
                        {
                            if (labels.ContainsKey(label))
                            {
                                labels[label]++;
                            }
                            else
                            {
                                labels[label] = 1;
                            }
                        }
                    }
                }
            }

            int max = 0;

            foreach (KeyValuePair <int, int> label in labels)
            {
                if (max == 0)
                {
                    max = label.Key;
                }
                else if (label.Value >= labels[max])                 // TODO: 等しい場合の処理 中心が近いものなど
                {
                    max = label.Key;
                }
            }

            nudT.Value = t;

            FillSource newSource = new FillSource(components, max);

            if (max == 0)
            {
                checkEnabled.Checked = false;
            }
            else
            {
                int xLength = newSource.MaxX - newSource.MinX;
                int yLength = newSource.MaxY - newSource.MinY;
                int longer  = xLength > yLength ? xLength : yLength;

                checkEnabled.Checked = true;
                nudX.Value           = newSource.MinX + (int)(xLength / 2);
                nudY.Value           = newSource.MinY + (int)(yLength / 2);

                if (nudR.Maximum < ((int)(longer / 2) + 3))
                {
                    nudR.Value = nudR.Maximum;
                }
                else
                {
                    nudR.Value = (int)(longer / 2) + 3; // TODO: 3 shold be defined some where else.
                }

                nudThreshold.Value = threshold;
            }

            ////*************************** SPOT 解析 ***************************


            ////選択部分の取得
            //Bitmap imageEllipse = new Bitmap(image.Width, image.Height);
            //Graphics g = Graphics.FromImage(imageEllipse);
            //g.Clear(Color.Black);
            //g.FillEllipse(Brushes.White, (int)nudX.Value - (int)nudR.Value, (int)nudY.Value - (int)nudR.Value, (int)nudR.Value * 2, (int)nudR.Value * 2);
            //g.Dispose();

            //Dictionary<int, int> spotlabels = new Dictionary<int, int>();
            //Dictionary<int, int> spotlabels561 = new Dictionary<int, int>();

            //int startX = (int)nudX.Value - (int)nudR.Value - 1;
            //startX = startX < 0 ? 0 : startX;

            //int endX = (int)nudX.Value + (int)nudR.Value + 1;
            //endX = endX > image.Width ? image.Width : endX;

            //int startY = (int)nudY.Value - (int)nudR.Value - 1;
            //startY = startY < 0 ? 0 : startY;

            //int endY = (int)nudY.Value + (int)nudR.Value + 1;
            //endY = endY > image.Height ? image.Height : endY;

            //for (int x = startX; x < endX; x++)
            //{
            //    for (int y = startY; y < endY; y++)
            //    {
            //        int label = components.Labels[x, y];
            //        Color color = imageEllipse.GetPixel(x, y);

            //        if (label <= 0 || (color.R == 0 && color.G == 0 && color.B == 0))
            //        {
            //            continue;
            //        }

            //        if (spotlabels.ContainsKey(label))
            //        {
            //            spotlabels[label]++;
            //        }
            //        else
            //        {
            //            spotlabels[label] = 1;
            //        }
            //    }
            //}

            //for (int x = startX; x < endX; x++)
            //{
            //    for (int y = startY; y < endY; y++)
            //    {
            //        int label = components561.Labels[x, y];
            //        Color color = imageEllipse.GetPixel(x, y);

            //        if (label <= 0 || (color.R == 0 && color.G == 0 && color.B == 0))
            //        {
            //            continue;
            //        }

            //        if (spotlabels561.ContainsKey(label))
            //        {
            //            spotlabels561[label]++;
            //        }
            //        else
            //        {
            //            spotlabels561[label] = 1;
            //        }
            //    }
            //}
            //nudCount473.Value = spotlabels.Count;
            //nudCount561.Value = spotlabels561.Count;
            ////**************************************************

            this._SetCurrentAnalyzeArea();

            return(newSource);
        }