Beispiel #1
0
        } /* PerformAllOperations */

        private void  MakePredictions()
        {
            pred1ClassName.Text = "";
            pred2ClassName.Text = "";

            BlobDetector bd    = new BlobDetector(raster, 20);
            BlobList     blobs = bd.ExtractBlobs();

            if ((blobs == null) || (blobs.Count < 1))
            {
                return;
            }

            Blob largestBlob = blobs.LocateLargestBlob();

            if (largestBlob == null)
            {
                return;
            }

            byte[][] largestRaster = bd.ExtractedBlobImage(largestBlob);

            PicesRunLog runLog      = new PicesRunLog();
            PicesRaster picesRaster = new PicesRaster(largestRaster);

            //PicesPredictionList  trainLibrary1Predictions = null;
            //PicesPredictionList  trainLibrary2Predictions = null;

            //ActiveTrainingLibraries.MakePredictions (picesRaster,
            //                                         instrumentData,
            //                                         imageFileName,
            //                                         ref trainLibrary1Predictions,
            //                                         ref trainLibrary2Predictions,
            //                                         runLog
            //                                        );

            picesRaster.FileName = imageFileName;

            PicesPrediction model1Prediction1 = new PicesPrediction(null, 0, 0.0f);
            PicesPrediction model1Prediction2 = new PicesPrediction(null, 0, 0.0f);
            PicesPrediction model2Prediction1 = new PicesPrediction(null, 0, 0.0f);
            PicesPrediction model2Prediction2 = new PicesPrediction(null, 0, 0.0f);

            ActiveTrainingLibraries.MakePredictions(picesRaster,
                                                    ref model1Prediction1,
                                                    ref model1Prediction2,
                                                    ref model2Prediction1,
                                                    ref model2Prediction2,
                                                    runLog
                                                    );

            if (model1Prediction1 != null)
            {
                TrainLib1Name.Text  = ActiveTrainingLibraries.Model1Name;
                pred1Prob.Text      = model1Prediction1.Probability.ToString("p");
                pred1ClassName.Text = model1Prediction1.ClassName;
                this.Text           = model1Prediction1.ClassName;

                if (model1Prediction2 != null)
                {
                    pred2Prob.Text      = model1Prediction2.Probability.ToString("p");
                    pred2ClassName.Text = model1Prediction2.ClassName;
                }
            }

            if (model2Prediction1 != null)
            {
                TrainLib2Name.Text      = ActiveTrainingLibraries.Model2Name;
                lib2Pred1Prob.Text      = model2Prediction1.Probability.ToString("p");
                lib2Pred1ClassName.Text = model2Prediction1.ClassName;
                if (model2Prediction2 != null)
                {
                    lib2Pred2Prob.Text      = model2Prediction2.Probability.ToString("p");
                    lib2Pred2ClassName.Text = model2Prediction2.ClassName;
                }
            }

            picesRaster = null;

            blobs.Dispose();
            largestBlob.Dispose();
            bd.Dispose();
            bd = null;
        } /* MakePredictions */
Beispiel #2
0
        public BlobList  ExtractBlobs()
        {
            byte[] curRow        = null;
            int[]  curRowBlobIds = null;

            int col = 2;
            int row = 2;

            Blob curBlob    = null;
            int  curBlobId  = 0;
            int  nearBlobId = 0;

            int blankColsInARow = 0;

            if (raster == null)
            {
                return(null);
            }


            BlobList blobs = new BlobList(true);

            for (row = 0; row < height; row++)
            {
                curRow        = raster[row];
                curRowBlobIds = blobIds[row];

                prev1Row = row - 1;
                prev2Row = row - 2;
                prev3Row = row - 3;

                curBlob = null;

                col = 0;
                while (col < width)
                {
                    if (ForegroundPixel(curRow[col]))
                    {
                        blankColsInARow = 0;

                        // Check Upper Left
                        nearBlobId = UpperLeft(col);

                        if (nearBlobId < 0)
                        {
                            // If nothing in Top Left  then check Top Right
                            nearBlobId = Max(BlobId(prev1Row, col - 1),
                                             BlobId(prev2Row, col - 1),
                                             BlobId(prev3Row, col - 1),
                                             BlobId(prev1Row, col - 2),
                                             BlobId(prev2Row, col - 2),
                                             BlobId(prev1Row, col - 3)
                                             );
                        }

                        if (curBlob != null)
                        {
                            if (nearBlobId >= 0)
                            {
                                if (nearBlobId != curBlobId)
                                {
                                    curBlob   = blobs.MergeIntoSingleBlob(curBlob, nearBlobId, blobIds);
                                    curBlobId = curBlob.Id;
                                }
                            }

                            curRowBlobIds[col]    = curBlobId;
                            curBlob.ColRightMaybe = col;
                            curBlob.RowBotMaybe   = row;
                            curBlob.PixelCountIncrement();
                        }

                        else
                        {
                            // No Current Blob
                            if (nearBlobId >= 0)
                            {
                                curBlob   = blobs.LookUpByBlobId(nearBlobId);
                                curBlobId = curBlob.Id;
                            }

                            else
                            {
                                curBlob   = blobs.NewBlob(row, col);
                                curBlobId = curBlob.Id;
                            }

                            curRowBlobIds[col]    = curBlobId;
                            curBlob.ColLeftMaybe  = col;
                            curBlob.ColRightMaybe = col;
                            curBlob.RowBotMaybe   = row;
                            curBlob.RowTopMaybe   = row;
                            curBlob.PixelCountIncrement();
                        }
                    }

                    else
                    {
                        blankColsInARow++;

                        if (blankColsInARow > 3)
                        {
                            curBlob   = null;
                            curBlobId = -1;
                        }

                        else if (curBlob != null)
                        {
                            // Check Upper Left
                            nearBlobId = UpperLeft(col);

                            if (nearBlobId >= 0)
                            {
                                if (nearBlobId != curBlobId)
                                {
                                    curBlob   = blobs.MergeIntoSingleBlob(curBlob, nearBlobId, blobIds);
                                    curBlobId = curBlob.Id;
                                }
                            }
                        }
                    }

                    col++;
                }
            } /* ExtractBlobs */



            BlobList compressedBlobList = new BlobList(true);

            {
                int idx;

                for (idx = 0; idx < blobs.Count; idx++)
                {
                    Blob b = blobs[idx];

                    if (b != null)
                    {
                        if (b.PixelCount < minSize)
                        {
                            b.Dispose();
                            blobs[idx] = null;
                        }
                        else
                        {
                            float widthHeightRatio = (float)b.Width / (float)b.Height;
                            if (widthHeightRatio < 0.1)
                            {
                                b.Dispose();
                                blobs[idx] = null;
                            }

                            else
                            {
                                compressedBlobList.Add(b);
                            }
                        }

                        blobs[idx] = null;
                    }
                }
            }

            blobs.Dispose();
            blobs = null;

            return(compressedBlobList);
        } /* ExtractBlobs */