コード例 #1
0
        private void buttonFill_Click(object sender, EventArgs e)
        {
            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            int t = scrollT.Value;

            FillSource source    = this._GetCurrentFillSource();
            int        threshold = (int)nudThreshold.Value;

            for (int tw = 1; tw <= this._Project.T; tw++)
            {
                this._ClearCurrentAnalyzeArea(tw);
                source = this._Fill(this._getTargetZ(tw), tw, source, threshold);
            }

            nudT.Value     = t;
            Cursor.Current = oldCursor;
        }
コード例 #2
0
        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);
        }