private FillSource _GetCurrentFillSource()
        {
            AnalyzeArea analyzeArea      = this._GetCurrentAnalyzeArea();
            Bitmap      analyzeAreaImage = analyzeArea.GetImage(this._Project.X, this._Project.Y);

            int[,] labels = new int[analyzeAreaImage.Width, analyzeAreaImage.Height];

            for (int x = 0; x < analyzeAreaImage.Width; x++)
            {
                for (int y = 0; y < analyzeAreaImage.Height; y++)
                {
                    Color color = analyzeAreaImage.GetPixel(x, y);
                    if (color.R == 255 && color.G == 255 && color.B == 255)
                    {
                        labels[x, y] = 1;
                    }
                    else
                    {
                        labels[x, y] = 0;
                    }
                }
            }

            ConnectedComponents components = new ConnectedComponents(labels, 1);

            return(new FillSource(components, 1));
        }
        private void dataAnalyzeAreas_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewCell cell = dataAnalyzeAreas.SelectedCells[0];

            nudT.Value = cell.ColumnIndex + 1;

            this.checkEnabled.CheckedChanged -= new System.EventHandler(this.checkEnabled_CheckedChanged);
            this.nudX.ValueChanged           -= new System.EventHandler(this.nudX_ValueChanged);
            this.nudY.ValueChanged           -= new System.EventHandler(this.nudY_ValueChanged);
            this.nudR.ValueChanged           -= new System.EventHandler(this.nudR_ValueChanged);
            this.nudThreshold.ValueChanged   -= new System.EventHandler(this.nudThreshold_ValueChanged);

            AnalyzeArea analyzeArea = this._GetCurrentAnalyzeArea();

            checkEnabled.Checked = analyzeArea.Enabled;
            nudX.Value           = analyzeArea.X == -1 ? 0 : analyzeArea.X;
            nudY.Value           = analyzeArea.Y == -1 ? 0 : analyzeArea.Y;
            nudR.Value           = analyzeArea.R == 0 ? this._Project.X * Project.DefaultR / 100 : analyzeArea.R;
            //nudR.Value = analyzeArea.R == 0 ? Project.DefaultR : analyzeArea.R;
            nudThreshold.Value = analyzeArea.Threshold == 0 ? Project.DefaultThreshold : analyzeArea.Threshold;

            this.checkEnabled.CheckedChanged += new System.EventHandler(this.checkEnabled_CheckedChanged);
            this.nudX.ValueChanged           += new System.EventHandler(this.nudX_ValueChanged);
            this.nudY.ValueChanged           += new System.EventHandler(this.nudY_ValueChanged);
            this.nudR.ValueChanged           += new System.EventHandler(this.nudR_ValueChanged);
            this.nudThreshold.ValueChanged   += new System.EventHandler(this.nudThreshold_ValueChanged);
        }
Exemplo n.º 3
0
 public void SetFromAnalyzeArea(AnalyzeArea analyzeArea)
 {
     this.SetAttributes(
         analyzeArea.Enabled,
         analyzeArea.X,
         analyzeArea.Y,
         analyzeArea.R,
         analyzeArea.Threshold
         );
 }
Exemplo n.º 4
0
        private void _SetTargetValueZ()
        {
            if (dataAnalyzeAreaSets.SelectedRows.Count > 0)
            {
                DataGridViewRow s_row            = dataAnalyzeAreaSets.CurrentRow;
                AnalyzeAreaSet  s_analyzeAreaSet = (AnalyzeAreaSet)s_row.DataBoundItem;

                //int selectZ = this._Analyzer.GetZ(s_analyzeAreaSet, scrollT.Value);

                int selectZ = 1;
                for (int z = 1; z <= this._Project.Z; z++)
                {
                    AnalyzeArea aa = s_analyzeAreaSet.GetAnalyzeArea(z, scrollT.Value);
                    if (aa.Enabled)
                    {
                        selectZ = z;
                        break;
                    }
                }

                if (scrollZ.Maximum < selectZ)
                {
                    scrollZ.Maximum = selectZ;
                }
                if (scrollZ.Minimum > selectZ)
                {
                    scrollZ.Minimum = selectZ;
                }
                if (nudZ.Maximum < selectZ)
                {
                    nudZ.Maximum = selectZ;
                }
                if (nudZ.Minimum > selectZ)
                {
                    nudZ.Minimum = selectZ;
                }

                scrollZ.Value = selectZ;
                nudZ.Value    = selectZ;

                //AnalyzeArea analyzeArea = this._GetCurrentAnalyzeArea();
                //nudThreshold.Value = analyzeArea.Threshold;

                scrollZ.Enabled = false;
                nudZ.Enabled    = false;
            }
            else
            {
                scrollZ.Enabled = true;
                nudZ.Enabled    = true;
            }
        }
Exemplo n.º 5
0
        public int AnalyzeArea(AnalyzeArea analyzeArea)
        {
            if (analyzeArea.Enabled == false)
            {
                return(0);
            }

            Bitmap image            = new Bitmap(this.GetImage());
            Bitmap analyzeAreaImage = analyzeArea.GetImage(image.Width, image.Height);

            int pixels = 0;

            int startX = analyzeArea.X - analyzeArea.R - 1;

            startX = startX < 0 ? 0 : startX;

            int endX = analyzeArea.X + analyzeArea.R + 1;

            endX = endX > image.Width ? image.Width : endX;

            int startY = analyzeArea.Y - analyzeArea.R - 1;

            startY = startY < 0 ? 0 : startY;

            int endY = analyzeArea.Y + analyzeArea.R + 1;

            endY = endY > image.Height ? image.Height : endY;

            for (int x = startX; x < endX; x++)
            {
                for (int y = startY; y < endY; y++)
                {
                    Color analyzeAreaColor = analyzeAreaImage.GetPixel(x, y);

                    if (analyzeAreaColor.R == 255 && analyzeAreaColor.G == 255 && analyzeAreaColor.B == 255)
                    {
                        Color color   = image.GetPixel(x, y);
                        int   average = (int)((color.R + color.G + color.B) / 3);

                        if (average > analyzeArea.Threshold)
                        {
                            pixels++;
                        }
                    }
                }
            }

            return(pixels);
        }
        private void _SetCurrentAnalyzeArea()
        {
            AnalyzeArea analyzeArea = this._GetCurrentAnalyzeArea();

            this.AnalyzeAreaSet.Name = textName.Text;
            analyzeArea.Enabled      = checkEnabled.Checked;
            analyzeArea.X            = (int)nudX.Value;
            analyzeArea.Y            = (int)nudY.Value;
            analyzeArea.R            = (int)nudR.Value;
            analyzeArea.Threshold    = (int)nudThreshold.Value;

            DataGridViewCell cell = dataAnalyzeAreas[scrollT.Value - 1, 0];

            cell.Value = analyzeArea.ToString();
        }
        private void _ClearCurrentAnalyzeArea(int t = 0)
        {
            if (t == 0)
            {
                t = scrollT.Value;
            }

            for (int z = 1; z <= this._Project.Z; z++)
            {
                AnalyzeArea analyzeArea = this.AnalyzeAreaSet.GetAnalyzeArea(z, t);
                this.AnalyzeAreaSet.Name = textName.Text;
                analyzeArea.Enabled      = false;
                analyzeArea.X            = -1;
                analyzeArea.Y            = -1;
                analyzeArea.R            = 0;
                analyzeArea.Threshold    = 0;
            }
        }
Exemplo n.º 8
0
        public int GetZ(AnalyzeAreaSet analyzeAreaSet, int t)
        {
            int targetZ = 1;
            //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;
                }
            }

            return(targetZ);
        }
        public bool IsValid()
        {
            if (this.Name == "")
            {
                return(false);
            }

            for (int z = 0; z < this.AnalyzeAreas.GetLength(0); z++)
            {
                for (int t = 0; t < this.AnalyzeAreas.GetLength(1); t++)
                {
                    AnalyzeArea analyzeArea = this.AnalyzeAreas[z, t];
                    if (analyzeArea.IsValid() == false)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public double AnalyzeLuminance(AnalyzeArea analyzeArea, int threshold)
        {
            if (analyzeArea.Enabled == false)
            {
                return(0);
            }
            Bitmap image = this.GetBinarizedImage(threshold);
            //Bitmap analyzeAreaImage = analyzeArea.GetImage(image.Width, image.Height);

            Tiff tif = this.GetImage16Bit();

            int stride = tif.ScanlineSize();

            byte[] buffer = new byte[stride];
            //for (int i = 0; i < image.Height; i++)
            //{
            //    tif.ReadScanline(buffer, i);
            //    for (int src = 0, dst = 0; src < buffer.Length; dst++)
            //    {
            //        int value16 = buffer[src++];
            //        value16 = value16 + (buffer[src++] << 8);
            //    }
            //}

            double luminance = 0;

            int startX = analyzeArea.X - analyzeArea.R - 1;

            startX = startX < 0 ? 0 : startX;

            int endX = analyzeArea.X + analyzeArea.R + 1;

            endX = endX > image.Width ? image.Width : endX;

            int startY = analyzeArea.Y - analyzeArea.R - 1;

            startY = startY < 0 ? 0 : startY;

            int endY = analyzeArea.Y + analyzeArea.R + 1;

            endY = endY > image.Height ? image.Height : endY;

            //選択部分の取得
            Bitmap   imageEllipse = new Bitmap(image.Width, image.Height);
            Graphics g            = Graphics.FromImage(imageEllipse);

            g.Clear(Color.Black);
            g.FillEllipse(Brushes.White, analyzeArea.X - analyzeArea.R, analyzeArea.Y - analyzeArea.R, analyzeArea.R * 2, analyzeArea.R * 2);
            g.Dispose();

            for (int y = startY; y < endY; y++)
            {
                tif.ReadScanline(buffer, y);
                for (int x = startX; x < endX; x++)
                {
                    Color analyzeAreaColor = image.GetPixel(x, y);
                    Color ellipseColor     = imageEllipse.GetPixel(x, y);

                    if (analyzeAreaColor.R == 255 && analyzeAreaColor.G == 255 && analyzeAreaColor.B == 255 && ellipseColor.R == 255 && ellipseColor.G == 255 && ellipseColor.B == 255)
                    {
                        int src     = x * 2;
                        int value16 = buffer[src++];
                        value16    = value16 + (buffer[src++] << 8);
                        luminance += value16;
                    }
                }
            }
            return(luminance);
        }
Exemplo n.º 12
0
        public double AnalyzeSpot(AnalyzeArea analyzeArea, int threshold)
        {
            double return_data = 0;

            if (analyzeArea.Enabled == false)
            {
                return(return_data);
            }

            Bitmap image            = this.GetBinarizedImage(threshold);
            Bitmap analyzeAreaImage = analyzeArea.GetImage(image.Width, image.Height);

            int startX = analyzeArea.X - analyzeArea.R - 1;

            startX = startX < 0 ? 0 : startX;

            int endX = analyzeArea.X + analyzeArea.R + 1;

            endX = endX > image.Width ? image.Width : endX;

            int startY = analyzeArea.Y - analyzeArea.R - 1;

            startY = startY < 0 ? 0 : startY;

            int endY = analyzeArea.Y + analyzeArea.R + 1;

            endY = endY > image.Height ? image.Height : endY;

            ConnectedComponents   components = ConnectedComponents.Analyze(image);
            Dictionary <int, int> labels     = new Dictionary <int, int>();

            //選択部分の取得
            Bitmap   imageEllipse = new Bitmap(image.Width, image.Height);
            Graphics g            = Graphics.FromImage(imageEllipse);

            g.Clear(Color.Black);
            g.FillEllipse(Brushes.White, analyzeArea.X - analyzeArea.R, analyzeArea.Y - analyzeArea.R, analyzeArea.R * 2, analyzeArea.R * 2);
            g.Dispose();

            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 (labels.ContainsKey(label))
                    {
                        labels[label]++;
                    }
                    else
                    {
                        labels[label] = 1;
                    }
                }
            }

            return(labels.Count);
        }
Exemplo n.º 13
0
        private void _Render()
        {
            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            if (this._Analyzer != null)
            {
                menuProjectSave.Enabled   = true;
                menuProjectSaveAs.Enabled = true;
                menuTool.Enabled          = true;

                panel.Enabled = true;

                checkDrawArea.Enabled  = dataAnalyzeAreaSets.SelectedRows.Count > 0 ? true : false;
                checkBinarize.Enabled  = dataAnalyzeAreaSets.SelectedRows.Count > 0 ? true : false;
                buttonAnalyzer.Enabled = dataAnalyzeAreaSets.SelectedRows.Count > 0 ? true : false;
                nudThreshold.Enabled   = dataAnalyzeAreaSets.SelectedRows.Count > 0 ? true : false;

                this._SetTargetValueZ();

                foreach (DataGridViewRow row in dataAnalyzeAreaSets.Rows)
                {
                    if (this._Project.T <= row.Cells.Count)
                    {
                        AnalyzeAreaSet analyzeAreaSet = (AnalyzeAreaSet)row.DataBoundItem;
                        row.HeaderCell.Value = analyzeAreaSet.Name;

                        for (int t = 1; t <= this._Project.T; t++)
                        {
                            int targetZ = 1;
                            for (int z = 1; z <= this._Project.Z; z++)
                            {
                                AnalyzeArea aa = analyzeAreaSet.GetAnalyzeArea(z, t);
                                if (aa.Enabled)
                                {
                                    targetZ = z;
                                    break;
                                }
                            }
                            row.Cells[t - 1].Value = analyzeAreaSet.GetAnalyzeArea(targetZ, t).ToString();
                        }
                    }
                }

                dataAnalyzeAreaSets.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);

                MicroImage microImage;
                if (radioButtonPic473.Checked)
                {
                    microImage = this._GetCurrentMicroImage("473");
                }
                else
                {
                    microImage = this._GetCurrentMicroImage("561");
                }

                Image image;

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

                if (checkDrawArea.Checked == true && dataAnalyzeAreaSets.SelectedRows.Count > 0)
                {
                    AnalyzeArea analyzeArea = this._GetCurrentAnalyzeArea();

                    if (analyzeArea.Enabled == true)
                    {
                        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));
                        g.DrawEllipse(
                            pen,
                            analyzeArea.X - analyzeArea.R,
                            analyzeArea.Y - analyzeArea.R,
                            analyzeArea.R * 2,
                            analyzeArea.R * 2
                            );

                        g.Dispose();

                        image = tmp;
                    }
                }

                pictureMicroImage.Image = image;
            }
            else
            {
                menuProjectSave.Enabled   = false;
                menuProjectSaveAs.Enabled = false;
                menuTool.Enabled          = false;
                chartSpot.Visible         = false;
                buttonExportAsCSV.Enabled = false;
                buttonAnalyzer.Enabled    = false;
                nudThreshold.Enabled      = false;

                panel.Enabled = false;
            }

            Cursor.Current   = oldCursor;
            labelStatus.Text = this._Flash;
            this._Flash      = "";
        }