示例#1
0
        } /* SaveImagesByClass */

        private void  SaveImagesInList(PicesDataBaseImageList list,
                                       String dirName
                                       )
        {
            dirName = OSservices.AddSlash(dirName);
            curDir  = dirName;
            foreach (PicesDataBaseImage i in list)
            {
                if (cancelRequested)
                {
                    break;
                }

                String      fullName = dirName + i.ImageFileName + ".bmp";
                PicesRaster r        = dbConn.ImageFullSizeFind(i.ImageFileName);
                if (r == null)
                {
                    imagesFailedToExtract++;
                }
                else
                {
                    r.Save(fullName);
                }
                imagesSaved++;
            }
        } /* SaveImagesInList */
示例#2
0
        public ImageEditor(PicesRaster _raster)
        {
            InitializeComponent();

            //raster         = (byte[][])_raster.BuildRasterArray ();
            raster        = _raster.BuildRasterArray2();
            imageFileName = _raster.FileName;

            instrumentData = null;
            height         = _raster.Height;
            width          = _raster.Width;

            _raster = null;

            BuildColorValues();

            SizeOptions.SelectedOption = "100%";

            image = BuildBitmapFromRasterData(raster);

            pictureBox1.Height = image.Height;
            pictureBox1.Width  = image.Width;
            pictureBox1.Image  = image;

            ImagePanel.AutoScroll = true;
            //ImagePanel.SetStyle   (ControlStyles.ResizeRedraw, false);
            ImagePanel.AutoScroll        = true;
            ImagePanel.AutoScrollMinSize = image.Size;
            ImagePanel.Invalidate();

            MakePredictions();
        }
示例#3
0
        } /* UpdateOperationsList */

        private byte[][]  PerformAllOperations(byte[][]  startRaster)
        {
            PicesRaster lastRaster = new PicesRaster(startRaster);

            foreach (Operation o in  operations)
            {
                PicesRaster nextRaster = o.PerformOperation(lastRaster);
                if (nextRaster == null)
                {
                    MessageBox.Show("Morphological operation[" + o.ToString() + "] failed.");
                    break;
                }
                lastRaster = nextRaster;
            }

            byte[][] finalResult = null;

            try
            {
                finalResult = lastRaster.BuildRasterArray2();
            }
            catch (Exception)
            {
                // Lets try one more time.
                finalResult = lastRaster.BuildRasterArray2();
                MessageBox.Show("PerformAllOperations     Called  'BuildRasterArray2'  Two Times.");
            }

            lastRaster = null;

            return(finalResult);
        } /* PerformAllOperations */
        public PredictionBreakDownDisplay(PicesDataBase _dbConn,
                                          PicesDataBaseImage _image,
                                          PicesRaster _raster,
                                          TrainingModel2 _trainingModel,
                                          PicesInstrumentData _instrumentData, /*!<  Instrument data that goes with image, if null will read from database. */
                                          PicesRunLog _runLog
                                          )
        {
            if (_runLog == null)
            {
                runLog = new PicesRunLog();
            }
            else
            {
                runLog = _runLog;
            }

            if (_image == null)
            {
                return;
            }

            fileName       = _image.ImageFileName;
            instrumentData = _instrumentData;
            trainingModel  = _trainingModel;

            PicesRaster raster = _raster;

            if (_dbConn != null)
            {
                if (raster == null)
                {
                    raster = _dbConn.ImageFullSizeFind(fileName);
                }

                if (instrumentData == null)
                {
                    instrumentData = _dbConn.InstrumentDataGetByScanLine(_image.SipperFileName, _image.TopLeftRow);
                }

                dbFeatureVector = _dbConn.FeatureDataRecLoad(fileName);
            }

            if (raster == null)
            {
                return;
            }

            //raster = raster.ConnectedComponent ();

            featureCalcImages = new PicesRasterList();
            featureVector     = new PicesFeatureVector(raster, fileName, featureCalcImages, runLog);
            if (instrumentData != null)
            {
                featureVector.AddInstrumentData(instrumentData);
            }

            InitializeComponent();
        }
示例#5
0
 public Operation(PicesRaster.OperationType _op,
                  PicesRaster.MaskType _mt
                  )
 {
     operation = _op;
     mask      = _mt;
     maskSize  = PicesRaster.MaskSize(_mt);
 }
        /// <summary>
        /// Using supplied 'Raster' data it will call each currently active model and return there predictions.
        /// </summary>
        /// <param name="raster">Raster of image to predict. .</param>
        /// <param name="instrumentData">Instrument data that was recorded with the 'raster' .</param>
        /// <param name="imageFileName">Name of the image file.</param>
        /// <param name="model1Predictions">The model1 predictions.</param>
        /// <param name="model2Predictions">The model2 predictions.</param>
        /// <param name="runLog">The run log.</param>
        public static void  MakePredictions(PicesRaster raster,
                                            InstrumentData instrumentData,
                                            String imageFileName,
                                            ref PicesPredictionList model1Predictions,
                                            ref PicesPredictionList model2Predictions,
                                            PicesRunLog runLog
                                            )
        {
            model1Predictions = null;
            model2Predictions = null;
            if (!ModelsAreAvailable())
            {
                return;
            }

            ParsedImageFileName pifn = PicesFeatureVector.ParseImageFileName(imageFileName);
            String sipperFileName    = pifn.sipperFileName;
            uint   scanLineNum       = pifn.scanLineNum;

            PicesFeatureVector fv = new PicesFeatureVector(raster, imageFileName, null, runLog);

            if (instrumentData != null)
            {
                fv.AddInstrumentData(instrumentData.Depth(),
                                     instrumentData.Salinity(),
                                     instrumentData.Oxygen(),
                                     instrumentData.Fluorescence()
                                     );
            }
            else
            {
                PicesDataBase       dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);
                PicesInstrumentData pid    = dbConn.InstrumentDataGetByScanLine(sipperFileName, scanLineNum);
                if (pid != null)
                {
                    fv.AddInstrumentData(pid);
                }
                pid = null;
                dbConn.Close();
                dbConn = null;
            }

            if (model1 != null)
            {
                model1Predictions = model1.PredictProbabilities(fv);
            }

            if (model2 != null)
            {
                model2Predictions = model2.PredictProbabilities(fv);
            }

            fv = null;

            return;
        } /* MakePredictions */
示例#7
0
        } /* RemoveImageFromTrainigLibray */

        private void  ThumbNail_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                PictureBox  pb            = (PictureBox)sender;
                String      imageFileName = pb.Name;
                PicesRaster pr            = new PicesRaster(imageFileName);
                ImageEditor ie            = new ImageEditor(pr);
                ie.ShowDialog(this);
            }
        }
        public PredictionBreakDownDisplayDual(PicesDataBase _dbConn,
                                              String _fileName,
                                              TrainingModel2 _trainingModel,
                                              PicesInstrumentData _instrumentData, /**<  Instrument data that goes with image,  if null will read from dtabase. */
                                              PicesRunLog _runLog
                                              )
        {
            if (_runLog == null)
            {
                runLog = new PicesRunLog();
            }
            else
            {
                runLog = _runLog;
            }

            fileName       = _fileName;
            instrumentData = _instrumentData;
            trainingModel  = _trainingModel;

            PicesDataBase dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);
            PicesRaster   raster = dbConn.ImageFullSizeFind(fileName);

            if (raster == null)
            {
                return;
            }

            if (_dbConn != null)
            {
                dbFeatureVector = _dbConn.FeatureDataRecLoad(_fileName);
                if (instrumentData == null)
                {
                    PicesDataBaseImage image = dbConn.ImageLoad(fileName);
                    if (image != null)
                    {
                        instrumentData = dbConn.InstrumentDataGetByScanLine(image.SipperFileName, image.TopLeftRow);
                    }
                }
            }

            featureVector = new PicesFeatureVector(raster, fileName, null, runLog);

            if (instrumentData != null)
            {
                featureVector.AddInstrumentData(instrumentData);
            }

            dbConn.Close();
            dbConn = null;
            GC.Collect();

            InitializeComponent();
        }
示例#9
0
        private PicesPredictionList  PredictClasses(PicesFeatureVector fv,
                                                    PicesPrediction pred1,
                                                    PicesPrediction pred2,
                                                    String imageFileName,
                                                    String imageFileRootName
                                                    )
        {
            PicesFeatureVector  fvToUse      = fv;
            PicesPredictionList probPredList = null;

            if (fvToUse.FeatureDataMissing)
            {
                fvToUse = null;

                // Feature data is missing.  we need to compute from original image.
                PicesDataBaseImage pdbi = DbConn().ImageLoad(imageFileRootName);
                if (pdbi != null)
                {
                    PicesRaster pr = DbConn().ImageFullSizeFind(imageFileRootName);
                    if (pr == null)
                    {
                        ErrorMsgsAdd("Failed to Load FullSize image [" + imageFileRootName + "]");
                    }
                    else
                    {
                        fvToUse = new PicesFeatureVector(pr, imageFileName, null, runLog);
                        // Since we had to compute the FeatureDatya from the raster image we now need to
                        // get the instrument data that matches it.
                        PicesInstrumentData id = DbConn().InstrumentDataGetByScanLine(pdbi.SipperFileName, pdbi.TopLeftRow);
                        if (id != null)
                        {
                            fvToUse.AddInstrumentData(id);
                        }
                        DbConn().FeatureDataInsertRow(pdbi.SipperFileName, fvToUse);
                        pr.Dispose();
                    }

                    pr = null;
                }
            }

            if (fvToUse != null)
            {
                classifier.PredictClass(fvToUse, pred1, pred2);
                probPredList = classifier.PredictProbabilities(fvToUse);
            }
            else
            {
                pred1.MLClass = PicesClassList.GetUnKnownClassStatic();   pred1.Probability = 1.0f;
                pred2.MLClass = PicesClassList.GetUnKnownClassStatic();   pred2.Probability = 0.0f;
            }

            return(probPredList);
        } /* PredictClasses */
示例#10
0
 public Operation(PicesRaster.OperationType _op,
                  PicesRaster.MaskType _mt,
                  uint _thLowerBound,
                  uint _thUpperBound
                  )
 {
     operation    = _op;
     mask         = _mt;
     maskSize     = PicesRaster.MaskSize(_mt);
     thLowerBound = _thLowerBound;
     thUpperBound = _thUpperBound;
 }
示例#11
0
        } /* MakePredictions */

        private void  ImageEditor_Load(object sender, EventArgs e)
        {
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.CROSS3));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.CROSS5));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.SQUARE3));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.SQUARE5));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.SQUARE7));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.SQUARE9));
            MaskTypesComboBox.Items.Add(PicesRaster.MaskTypeToStr(PicesRaster.MaskType.SQUARE11));

            MaskTypesComboBox.SelectedIndex = 2;
        }
示例#12
0
        private void  ViewImage(Object sender, EventArgs e)
        {
            String             imageFileName = lastSelectedImage;
            PicesDataBaseImage pi            = dbConn.ImageLoad(imageFileName);

            if (pi != null)
            {
                PicesRaster pr = dbConn.ImageFullSizeFind(imageFileName);
                ImageViewer iv = new ImageViewer(pr, pi, null);
                iv.ShowDialog(this);
            }
        }
示例#13
0
 public Operation(PicesRaster.OperationType _op,
                  PicesRaster.MaskType _mt,
                  float _lowerBound,
                  float _upperBound
                  )
 {
     operation  = _op;
     mask       = _mt;
     maskSize   = PicesRaster.MaskSize(_mt);
     lowerBound = _lowerBound;
     upperBound = _upperBound;
 }
示例#14
0
        private void  CopyImageToClipboard(Object sender, EventArgs e)
        {
            String imageFileName = lastSelectedImage;

            PicesDataBaseImage pi = dbConn.ImageLoad(imageFileName);

            if (pi != null)
            {
                PicesRaster pr = dbConn.ImageFullSizeFind(imageFileName);
                Image       i  = pr.BuildBitmap();
                if (i != null)
                {
                    Clipboard.SetImage(i);
                }
            }
        } /* CopyImageToClipboard */
示例#15
0
        public ImageEditor(String _fileName)
        {
            InitializeComponent();

            imageFileName = _fileName;

            PicesRaster pr = null;

            try
            {
                pr = new PicesRaster(_fileName);
            }
            catch (Exception e)
            {
                pr = null;
                throw new Exception("ImageEditor", e);
            }

            raster         = pr.BuildRasterArray2();
            fileName       = _fileName;
            instrumentData = null;
            height         = pr.Height;
            width          = pr.Width;

            pr = null;

            BuildColorValues();

            SizeOptions.SelectedOption = "100%";

            image = BuildBitmapFromRasterData(raster);

            pictureBox1.Height = image.Height;
            pictureBox1.Width  = image.Width;
            pictureBox1.Image  = image;

            ImagePanel.AutoScroll = true;
            //ImagePanel.SetStyle   (ControlStyles.ResizeRedraw, false);
            ImagePanel.AutoScroll        = true;
            ImagePanel.AutoScrollMinSize = image.Size;
            ImagePanel.Invalidate();

            MakePredictions();
        }
示例#16
0
            public override String  ToString()
            {
                String s = PicesRaster.OperationTypeToStr(operation);

                switch (operation)
                {
                case  PicesRaster.OperationType.Closing:
                case  PicesRaster.OperationType.Dilation:
                case  PicesRaster.OperationType.Erosion:
                case  PicesRaster.OperationType.Opening:
                {
                    s  = s.PadRight(12);
                    s += PicesRaster.MaskTypeToStr(mask);
                }
                break;

                case  PicesRaster.OperationType.SmoothAveraging:
                case  PicesRaster.OperationType.SmoothMedium:
                {
                    s  = s.PadRight(12);
                    s += PicesRaster.MaskSize(mask);
                }
                break;

                case  PicesRaster.OperationType.BandPass:
                {
                    s  = s.PadRight(12);
                    s += ((float)(lowerBound * 100.0)).ToString("##0.0") + " - " +
                         ((float)(upperBound * 100.0)).ToString("##0.0");
                }
                break;


                case  PicesRaster.OperationType.BinarizeTH:
                {
                    s  = s.PadRight(12);
                    s += thLowerBound.ToString("##0.0") + " - " + thUpperBound.ToString("##0.0");
                }
                break;
                }

                return(s);
            } /* ToString */
示例#17
0
        //SMP751001034_02_00025491_3588



        private void  SaveSampleImages(PicesDataBaseImageList planktonData)
        {
            PicesClassList classes = planktonData.ExtractListOfClasses();

            if (classes == null)
            {
                return;
            }

            String sampleDir = OSservices.AddSlash(OSservices.GetPathPartOfFile(dataFileName)) +
                               OSservices.GetRootName(dataFileName) +
                               "_SampleImages";

            sampleDir = OSservices.AddSlash(sampleDir);
            OSservices.CreateDirectoryPath(sampleDir);

            foreach (PicesClass pc in classes)
            {
                String classSampleDir = OSservices.AddSlash(sampleDir + pc.Name);
                OSservices.CreateDirectoryPath(classSampleDir);
                PicesDataBaseImageList examplesThisClass = planktonData.ExtractExamplesForAGivenClass(pc);
                examplesThisClass.RandomizeOrder();

                int numWritten = 0;
                foreach (PicesDataBaseImage i in examplesThisClass)
                {
                    String imageRootName = OSservices.GetRootName(i.ImageFileName);

                    PicesRaster fullSizeImage = dbConn.ImageFullSizeFind(imageRootName);
                    if (fullSizeImage != null)
                    {
                        String imageFileName = classSampleDir + imageRootName + ".bmp";
                        fullSizeImage.Save(imageFileName);
                        ++numWritten;
                    }
                    if (numWritten >= includeSampleImagesNumPerClass)
                    {
                        break;
                    }
                }
            }
        } /* SaveSampleImages */
示例#18
0
        } /* CopyImageToClipboard */

        private void  SaveImage(Object sender, EventArgs e)
        {
            String imageFileName = lastSelectedImage;

            PicesRaster pr = dbConn.ImageFullSizeFind(imageFileName);

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            fbd.Description         = "Select directory to save images to";
            fbd.ShowNewFolderButton = true;
            fbd.SelectedPath        = lastSaveImageDir;
            DialogResult dr = fbd.ShowDialog();

            if (dr == DialogResult.OK)
            {
                if (lastSaveImageDir != fbd.SelectedPath)
                {
                    lastSaveImageDir = fbd.SelectedPath;
                }

                String destDir = OSservices.AddSlash(fbd.SelectedPath);

                System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(destDir);
                if (!di.Exists)
                {
                    MessageBox.Show(this, "No Such Directory [" + destDir + "]", "Save Images", MessageBoxButtons.OK);
                    return;
                }

                String fullFileName = destDir + imageFileName + ".bmp";

                try { pr.Save(fullFileName); }
                catch (Exception e3)
                {
                    MessageBox.Show(this,
                                    "Exception occurred saving image\n\n" + e3.ToString(),
                                    "Save Image",
                                    MessageBoxButtons.OK
                                    );
                }
            }
        } /* SaveImage */
示例#19
0
        private void  AddOperation(PicesRaster.OperationType _operation)
        {
            PicesRaster.MaskType mt = PicesRaster.MaskTypeFromStr(MaskTypesComboBox.SelectedItem.ToString());

            if (_operation == PicesRaster.OperationType.BandPass)
            {
                operations.Add(new Operation(_operation, mt, lowerBound, upperBound));
            }

            else if (_operation == PicesRaster.OperationType.BinarizeTH)
            {
                operations.Add(new Operation(_operation, mt, thLowerBound, thUpperBound));
            }

            else
            {
                operations.Add(new Operation(_operation, mt));
            }
            UpdateOperationsList();
            RePaintImage();
        } /* AddOperation */
示例#20
0
            } /* ToString */

            public PicesRaster  PerformOperation(PicesRaster r)
            {
                PicesRaster result = null;

                switch (operation)
                {
                case  PicesRaster.OperationType.BandPass:           result = r.BandPass(lowerBound, upperBound, true); break;

                case  PicesRaster.OperationType.Binarize:           result = r.Binarize();                  break;

                case  PicesRaster.OperationType.BinarizeTH:         result = r.BinarizeByThreshold(thLowerBound, thUpperBound); break;

                case  PicesRaster.OperationType.Closing:            result = r.CloseImage(mask);              break;

                case  PicesRaster.OperationType.ConnectedComponent: result = r.ConnectedComponent((byte)maskSize);    break;

                case  PicesRaster.OperationType.ConvexHull:         result = r.ConvexHull();                  break;

                case  PicesRaster.OperationType.Dilation:          result = r.DialateImage(mask);              break;

                case  PicesRaster.OperationType.Edge:               result = r.EdgeImage();                  break;

                case  PicesRaster.OperationType.Erosion:            result = r.ErodeImage(mask);              break;

                case  PicesRaster.OperationType.FillHoles:          result = r.FillHoles();                  break;

                case  PicesRaster.OperationType.FourierTransform:   result = r.FourierTransform();                  break;

                case  PicesRaster.OperationType.Opening:            result = r.OpenImage(mask);              break;

                case  PicesRaster.OperationType.SmoothAveraging:    result = r.SmoothAveraging(maskSize);          break;

                case  PicesRaster.OperationType.SmoothMedium:       result = r.SmoothMedium(maskSize);          break;

                case  PicesRaster.OperationType.Thinning:           result = r.Thinning();                  break;
                } /* operation */

                return(result);
            } /* PerformOperation */
示例#21
0
        } /* MakePredictions */

        public static void  MakePredictions(PicesRaster raster,
                                            ref PicesPrediction model1Prediction1,
                                            ref PicesPrediction model1Prediction2,
                                            ref PicesPrediction model2Prediction1,
                                            ref PicesPrediction model2Prediction2,
                                            PicesRunLog runLog
                                            )
        {
            String imageFileName = raster.FileName;

            ParsedImageFileName pifn = PicesFeatureVector.ParseImageFileName(imageFileName);
            String sipperFileName    = pifn.sipperFileName;
            uint   scanLineNum       = pifn.scanLineNum;

            PicesFeatureVector fv = new PicesFeatureVector(raster, imageFileName, null, runLog);

            {
                PicesDataBase       dbConn = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);
                PicesInstrumentData pid    = dbConn.InstrumentDataGetByScanLine(sipperFileName, scanLineNum);
                if (pid != null)
                {
                    fv.AddInstrumentData(pid);
                }
                pid = null;
                dbConn.Close();
                dbConn = null;
            }

            MakePredictions(fv,
                            ref model1Prediction1,
                            ref model1Prediction2,
                            ref model2Prediction1,
                            ref model2Prediction2,
                            runLog
                            );
            fv = null;
        }
示例#22
0
        public ImageViewer(PicesRaster _raster,
                           PicesDataBaseImage _image,
                           PicesClassList _classes
                           )
        {
            runLog  = new PicesRunLog();
            raster  = _raster;
            classes = _classes;
            dbConn  = PicesDataBase.GetGlobalDatabaseManagerNewInstance(runLog);
            image   = _image;

            sizeCoordinates = image.SizeCoordinates;

            if (raster == null)
            {
                raster = PicesRaster.GetOrigSipperImage(image.SipperFileName,
                                                        image.ByteOffset,
                                                        image.TopLeftRow,
                                                        image.TopLeftCol,
                                                        image.Height,
                                                        image.Width,
                                                        image.ConnectedPixelDist,
                                                        runLog
                                                        );
            }

            if (raster == null)
            {
                MessageBox.Show("Could not locate source image or SipperFile[" + image.SipperFileName + "]");
                return;
            }

            {
                uint scanLine = image.TopLeftRow;
                scanLine       = 4096 * (uint)(scanLine / 4096);
                instrumentData = dbConn.InstrumentDataGetByScanLine(image.SipperFileName, image.TopLeftRow);
                sipperFile     = dbConn.SipperFileRecLoad(image.SipperFileName);
            }

            double pixelsPerScanLine = pixelsPerScanLineDefault;


            if (instrumentData != null)
            {
                if (instrumentData.ActiveColumns > 0)
                {
                    pixelsPerScanLine = instrumentData.ActiveColumns;
                }
                if (instrumentData.FlowRate1 > 0.0)
                {
                    flowRate1 = instrumentData.FlowRate1;
                }
            }

            if (sipperFile != null)
            {
                if (sipperFile.ScanRate > 0.0)
                {
                    scanRate = sipperFile.ScanRate;
                }
                deployment = dbConn.SipperDeploymentLoad(sipperFile.CruiseName, sipperFile.StationName, sipperFile.DeploymentNum);
                if (deployment != null)
                {
                    chamberWidth = deployment.ChamberWidth;
                }
            }

            if ((dataFieldAssignments == null) || (DataLabels == null))
            {
                ConfigurationLoad();
            }

            InitializeComponent();
            if (image != null)
            {
                extractionLogEntry = dbConn.LogEntriesSelect(image.ExtractionLogEntryId);
                classLogEntry      = dbConn.LogEntriesSelect(image.ClassLogEntryId);
            }

            mmPerPixelAccrossChamber = chamberWidth * mmPerMeter / pixelsPerScanLine;
            mmPerPixelWithFlow       = mmPerMeter * flowRate1 / scanRate;

            DataLabels    = new Label[4];
            DataLabels[0] = DataLabel0;
            DataLabels[1] = DataLabel1;
            DataLabels[2] = DataLabel2;
            DataLabels[3] = DataLabel3;

            displayDataFields    = new TextBox[4];
            displayDataFields[0] = DataField0;
            displayDataFields[1] = DataField1;
            displayDataFields[2] = DataField2;
            displayDataFields[3] = DataField3;

            UpdateDataFields();

            ImageFileName.Text = image.ImageFileName;
        }
示例#23
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 */
示例#24
0
        private void  ImportImage(PicesDataBase threadConn,
                                  String fileName
                                  )
        {
            String rootName      = OSservices.GetRootName(fileName);
            String picesRootName = sipperFileName + "_" + rootName;

            PicesDataBaseImage dbi = threadConn.ImageLoad(picesRootName);

            if (dbi != null)
            {
                return;
            }

            PicesRaster r = new PicesRaster(fileName);

            r = r.Padded(2);

            PicesFeatureVector fv = new PicesFeatureVector(r, picesRootName, null, runLog);

            fv.ExampleFileName = picesRootName;

            int  imageId    = 0;
            bool successful = false;


            uint centroidRow = (uint)(0.5f + fv.CentroidRow);
            uint centroidCol = (uint)(0.5f + fv.CentroidCol);

            if ((centroidRow < 0) || (centroidRow > r.Height))
            {
                centroidRow = (uint)(r.Height / 2);
            }

            if ((centroidCol < 0) || (centroidCol > r.Width))
            {
                centroidCol = (uint)(r.Width / 2);
            }

            threadConn.ImageInsert(r,
                                   picesRootName,
                                   sipperFileName,
                                   0, 0, 0,
                                   (uint)r.Height, (uint)r.Width,
                                   (uint)fv.OrigSize,
                                   3,
                                   extractionLogEntryId.LogEntryId, extractionLogEntryId.LogEntryId,
                                   centroidRow, centroidCol,
                                   unknownClass, 1.0f, null, 0.0f, null,
                                   0.0f, // depth,
                                   0.0f, // Image Size
                                   null,
                                   ref imageId,
                                   ref successful
                                   );
            if (successful)
            {
                threadConn.FeatureDataInsertRow(sipperFileName, fv);
            }
            else
            {
                RunLogAddMsg("RootName[" + rootName + "] Failed: " + threadConn.LastErrorDesc() + "\n");
            }
        } /* ImportImage */
示例#25
0
        private void  SaveOneBatchOfImages(String dirPath,
                                           Dictionary <String, int> imagesPerClass,
                                           PicesDataBaseImageList batch
                                           )
        {
            if (classKeyToUse == 'V')
            {
                batch.Sort(PicesDataBaseImageList.SortOrderType.soValidatedClassName, false);
            }
            else
            {
                batch.Sort(PicesDataBaseImageList.SortOrderType.soClassName, false);
            }

            int idx = 0;
            PicesDataBaseImage i = batch[0];

            while ((idx < batch.Count) && (!cancelRequested))
            {
                String className = i.Class1Name;
                if (classKeyToUse == 'V')
                {
                    className = i.ValidatedClassName;
                }

                String curClassName = className;

                String classDir = OSservices.AddSlash(dirPath) + className;

                try { OSservices.CreateDirectoryPath(classDir); }  catch (Exception)  {}

                int countThisClass = 0;
                if (imagesPerClass.ContainsKey(curClassName))
                {
                    countThisClass = imagesPerClass[curClassName];
                }
                else
                {
                    imagesPerClass.Add(curClassName, 0);
                }

                int    lastFoldNum = -1;
                String foldDir     = "";

                while ((idx < batch.Count) && (!cancelRequested) && (className == curClassName))
                {
                    int foldNum = countThisClass / imagsPerDir;

                    if (foldNum != lastFoldNum)
                    {
                        foldDir = OSservices.AddSlash(classDir) + curClassName + "_" + foldNum.ToString("000");

                        OSservices.CreateDirectoryPath(foldDir);
                        lastFoldNum = foldNum;
                    }

                    String      fullName = OSservices.AddSlash(foldDir) + i.ImageFileName + ".bmp";
                    PicesRaster r        = dbConn.ImageFullSizeFind(i.ImageFileName);
                    if (r == null)
                    {
                        imagesFailedToExtract++;
                    }
                    else
                    {
                        r.Save(fullName);
                    }
                    imagesSaved++;

                    // Get the next image to save.
                    idx++;
                    if (idx < batch.Count)
                    {
                        i         = batch[idx];
                        className = i.Class1Name;
                        if (classKeyToUse == 'V')
                        {
                            className = i.ValidatedClassName;
                        }
                    }

                    countThisClass++;
                }

                imagesPerClass[curClassName] = countThisClass;
            }
        } /* SaveOneBatchOfImages */