Exemple #1
0
        public Galloway(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("GLRL-Matrix", typeof(TMatrix)));

            output.Add(new Compatible("Galloway Features", typeof(TFeatureList<double>)));
        }
Exemple #2
0
        public Moments(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("Moments", typeof(TFeatureList<double>)));
        }
Exemple #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Baimp.AlgorithmTreeView"/> class.
        /// </summary>
        public AlgorithmTreeView(ScanCollection scanCollection)
        {
            nameCol = new DataField<object>();
            store = new TreeStore(nameCol);

            Type baseType = typeof(BaseAlgorithm);
            IEnumerable<Type> algorithms = AppDomain.CurrentDomain.GetAssemblies()
                .SelectMany(s => s.GetTypes())
                .Where(t => t.BaseType == baseType);

            algorithmCollection = new Dictionary<string, List<BaseAlgorithm>>();
            foreach (Type algorithm in algorithms) {

                BaseAlgorithm instance =
                    Activator.CreateInstance(algorithm, (PipelineNode) null, scanCollection) as BaseAlgorithm;
                string algorithmType = instance.AlgorithmType.ToString();

                if (!algorithmCollection.ContainsKey(algorithmType)) {
                    algorithmCollection[algorithmType] = new List<BaseAlgorithm>();
                }

                algorithmCollection[algorithmType].Add(instance);
            }

            InitializeUI();
        }
Exemple #4
0
        public Haralick(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Matrix", typeof(TMatrix)));

            output.Add(new Compatible("Haralick Features", typeof(TFeatureList<double>)));
        }
Exemple #5
0
        public HistogramFeatures(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Histogram", typeof(THistogram)));

            output.Add(new Compatible("Histogram Features", typeof(TFeatureList<double>)));
        }
Exemple #6
0
        public Autocorrelation(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("Correlogram", typeof(THistogram)));

            options.Add(new Option("Offest", 0, 1024, 6));
        }
Exemple #7
0
        public GLRLM(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("GLRL-Matrix", typeof(TMatrix)));

            options.Add(new Option("Bpp", 2, 32, 8));
        }
Exemple #8
0
        public LawsEnergy(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image (Windowed)", typeof(TScan)));

            output.Add(new Compatible("Laws Energy Features", typeof(TFeatureList<double>)));

            options.Add(new OptionBool("Normalize", true));
        }
Exemple #9
0
        public Tamura(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("Tamura Features", typeof(TFeatureList<double>)));
            output.Add(new Compatible("Directionality Histogram", typeof(THistogram)));

            options.Add(new Option("Directionality Histogram #Bins", 4, int.MaxValue, 64));
        }
Exemple #10
0
        public GLCM(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("Co-occurence matrix", typeof(TMatrix)));

            options.Add(new Option("Bpp", 2, 32, 8));
            options.Add(new Option("X Offest", 0, 10, 1));
            options.Add(new Option("Y Offest", 0, 10, 1));
        }
Exemple #11
0
        public LBP(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible("Image", typeof(TScan)));

            output.Add(new Compatible("LBP Feature Vector", typeof(TFeatureList<double>)));
            output.Add(new Compatible("LBP Histogram", typeof(THistogram)));

            options.Add(new Option("Block size 2^x", 2, 32, 3));
            options.Add(new OptionBool("Normalize", true));
            options.Add(new OptionBool("Rotation invariant", true));
            options.Add(new OptionBool("Uniform LBP", true));
        }
Exemple #12
0
        public Windower(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            input.Add(new Compatible(
                "Image",
                typeof(TScan)
            ));

            output.Add(new Compatible(
                "ROI",
                typeof(TScan)
            ));

            options.Add(new Option("Width", 1, int.MaxValue, 64));
            options.Add(new Option("Height", 1, int.MaxValue, 64));
        }
Exemple #13
0
        public ProjectFiles(PipelineNode parent, ScanCollection scanCollection)
            : base(parent, scanCollection)
        {
            output.Add(new Compatible(
                "Scan",
                typeof(TScan)
            ));

            options.Add(new OptionBool("Masked only", true));

            scanTypeComboBox = new OptionDropDown("Scan type", "Unknown");
            options.Add(scanTypeComboBox);

            request.Add(RequestType.ScanCollection);

            UpdateFiberTypes(scanCollection);
            scanCollection.FilesChanged += (s, e) => UpdateFiberTypes(scanCollection);
        }
Exemple #14
0
        internal BaseAlgorithm(PipelineNode parent, ScanCollection scanCollection)
        {
            this.Parent = parent;

            input = new List<Compatible>();
            output = new List<Compatible>();
            request = new HashSet<RequestType>();
            options = new List<BaseOption>();
        }
Exemple #15
0
 public Census(PipelineNode parent, ScanCollection scanCollection)
     : base(parent, scanCollection)
 {
     input.Add(new Compatible("Image", typeof(TScan)));
 }
Exemple #16
0
        /// <summary>
        /// Loads previews of all loaded file async.
        /// Show them in tree view.
        /// </summary>
        /// <param name="scans">Scans.</param>
        private void LoadPreviewsAsync(ScanCollection scans)
        {
            foreach (BaseScan scan in scans) {
                scan.isLoadingThumbnail = true;
            }

            Task.Factory.StartNew(() => {
                List<BaseScan> scansCopy = new List<BaseScan>(scans);
                Project.RequestZipAccess(new Project.ZipUsageCallback(zipFile => {
                    foreach (BaseScan scan in scansCopy) {
                        var lScan = scan;
                        Image[] thumbnails = lScan.GetThumbnails(zipFile);

                        if (thumbnails.Length > 0 && thumbnails[0] != null) {
                            Application.Invoke(() => {
                                if (isFiltered) {
                                    string name = store.GetNavigatorAt(lScan.position).GetValue(nameCol);
                                    if (filteredPositions.ContainsKey(name)) {
                                        storeFilter.GetNavigatorAt(filteredPositions[name])
                                            .SetValue(thumbnailColFilter, thumbnails[0].WithBoxSize(int.MaxValue, THUMB_SIZE));
                                    }
                                }

                                store.GetNavigatorAt(lScan.position)
                                    .SetValue(thumbnailCol, thumbnails[0].WithBoxSize(int.MaxValue, THUMB_SIZE));
                            });
                        }
                    }
                    return null;
                }));

                foreach (BaseScan scan in scans) {
                    scan.isLoadingThumbnail = false;
                }
            });
        }
Exemple #17
0
        /// <summary>
        /// Reloads file tree information.
        /// </summary>
        /// <param name="scans">Collection of loaded scans</param>
        /// <param name="currentScan">Current focused scan</param>
        /// <param name="save">Update scan collection</param>
        public void Reload(ScanCollection scans, BaseScan currentScan = null, bool save = true)
        {
            if (scans.Count > 0) {
                scans.Sort(scans[0]);
            }

            if (save) {
                scanCollection = scans;
            }

            DataSource = store;
            store.Clear();

            TreePosition pos = null;
            fiberTypeNodes = new Dictionary<string, TreePosition>();
            foreach (BaseScan scan in scans) {
                TreePosition currentNode;
                if (fiberTypeNodes.ContainsKey(scan.FiberType)) {
                    currentNode = fiberTypeNodes[scan.FiberType];
                } else {
                    TextLayout text = new TextLayout();
                    text.Text = scan.FiberType;
                    ImageBuilder ib = new ImageBuilder(text.GetSize().Width, text.GetSize().Height);
                    ib.Context.DrawTextLayout(text, Point.Zero);

                    currentNode = store.AddNode(null).SetValue(thumbnailCol, ib.ToVectorImage()).CurrentPosition;
                    fiberTypeNodes[scan.FiberType] = currentNode;

                    text.Dispose();
                    ib.Dispose();
                }

                var v = store.AddNode(currentNode)
                    .SetValue(nameCol, scan.ToString())
                    .SetValue(finishCol, scan.IsFinish() ? tick : cross)
                    .SetValue(saveStateCol, scan.HasUnsaved() ? "*" : "")
                    .CurrentPosition;
                scan.position = v;
                scan.parentPosition = currentNode;
                if (currentScan != null) {
                    if (currentScan == scan) {
                        pos = v;
                    }
                } else {
                    if (pos == null) {
                        pos = v;
                    }
                }

                scan.ScanDataChanged += OnScanDataChanged;
            }

            if (scans.Count > 0) {
                ExpandToRow(pos);
                SelectRow(pos);
            }

            LoadPreviewsAsync(scans);
        }
Exemple #18
0
        public Project(string filePath)
        {
            scanCollection = new ScanCollection();

            if (!string.IsNullOrEmpty(filePath)) {
                Open(filePath);
            }
        }
Exemple #19
0
        /// <summary>
        /// Open the specified file.
        /// </summary>
        /// <param name="filePath">File path.</param>
        public bool Open(string filePath)
        {
            Project.ProjectFile = Path.GetFullPath(filePath);

            if (File.Exists(ProjectFile)) {
                bool ret = (bool) RequestZipAccess(new ZipUsageCallback(delegate(ZipFile zipFile) {
                    ZipEntry metadata = zipFile.GetEntry("metadata.xml");
                    if (metadata == null) {
                        return false;
                    }

                    Stream metadataStream = zipFile.GetInputStream(metadata);

                    using (XmlTextReader xmlReader = new XmlTextReader(metadataStream)) {
                        Project p;

                        try {
                            XmlSerializer deserializer = new XmlSerializer(this.GetType());
                            p = (Project) deserializer.Deserialize(xmlReader);
                        } catch (Exception e) {
                            Console.WriteLine(e);
                            Console.WriteLine(e.Message);
                            Console.WriteLine(e.InnerException.Message);
                            ErrorMessage = e.Message + "\n" + e.InnerException.Message;
                            Log.Add(LogLevel.Error, this.GetType().Name, "Failed to deserialize save file.\n" + ErrorMessage);
                            return false;
                        }

                        version = p.version;
                        LoadedPipelines.Clear();
                        LoadedPipelines = p.LoadedPipelines;

                        Dictionary<int, MarkerNode> allNodes = new Dictionary<int, MarkerNode>();
                        int noNodes = 0;
                        foreach (PipelineNodeWrapper wrapper in LoadedPipelines) {
                            foreach (PipelineNode pNode in wrapper.pNodes) {
                                pNode.InitializeNodes(this);

                                foreach (BaseOption option in pNode.InternOptions) {
                                    var localOption = option;
                                    BaseOption targetOption =
                                        pNode.algorithm.Options.Find((BaseOption o) => o.Name == localOption.Name);
                                    if (targetOption != null) {
                                        targetOption.Value =
                                            Convert.ChangeType(option.Value, targetOption.Value.GetType());
                                    }
                                }

                                foreach (MarkerNode mNode in pNode.mNodes) {
                                    if (!allNodes.ContainsKey(mNode.ID)) {
                                        allNodes.Add(mNode.ID, mNode);
                                    }
                                }

                                noNodes++;
                            }
                        }

                        foreach (PipelineNodeWrapper wrapper in LoadedPipelines) {
                            foreach (PipelineNode pNode in wrapper.pNodes) {
                                foreach (MarkerNode mNode in pNode.mNodes) {
                                    foreach (Edge edge in mNode.Edges) {
                                        edge.to = allNodes[edge.ToNodeID];
                                    }
                                }
                            }
                        }

                        if (p.scanCollection != null) {
                            scanCollection.AddRange(p.scanCollection);
                            foreach (BaseScan scan in this.scanCollection) {
                                if (zipFile.FindEntry(scan.Mask.MaskFilename, false) != -1) {
                                    scan.HasMask = true;
                                }
                                scan.OnXmlDeserializeFinish();
                            }
                        } else {
                            this.scanCollection = new ScanCollection();
                        }

                        if (projectChanged != null) {
                            projectChanged(this, new ProjectChangedEventArgs(true));
                        }

                        Log.Add(LogLevel.Info, this.GetType().Name,
                            string.Format("\"{0}\" was loaded successfully. #Scans: {1}; #Worksheets: {2}; #Nodes: {3}",
                                Path.GetFileName(filePath), scanCollection.Count, LoadedPipelines.Count, noNodes));

                        return true;
                    }
                }));

                if (!ret) {
                    Log.Add(LogLevel.Error, this.GetType().Name,
                        string.Format(
                            "Opening file \"{0}\" failed!" + (string.IsNullOrEmpty(ErrorMessage) ? "": "\n{1}")
                            , ProjectFile, ErrorMessage));
                    return false;
                }
            } else {
                ErrorMessage = "File not found";
                Log.Add(LogLevel.Error, this.GetType().Name,
                                string.Format("Opening failed. File \"{0}\" not found.", ProjectFile));
                return false;
            }

            StringCollection last = Settings.Default.LastOpenedProjects;
            if (last == null) {
                last = new StringCollection();
                Settings.Default.LastOpenedProjects = last;
            } else {
                if (last.Contains(ProjectFile)) {
                    last.Remove(ProjectFile);
                } else if (last.Count >= MaxLastOpenedProject) {
                    last.RemoveAt(0);
                }
            }

            last.Add(ProjectFile);
            Settings.Default.LastOpenedProjects = last;
            Settings.Default.Save();

            return true;
        }
Exemple #20
0
        void UpdateFiberTypes(ScanCollection scanCollection)
        {
            HashSet<string> hash = new HashSet<string>();
            foreach (BaseScan scan in scanCollection) {
                foreach (string scantype in scan.AvailableScanTypes()) {
                    hash.Add(scantype);
                }
            }

            if (hash.Count == 0) {
                hash.Add("Unknown");
            }

            scanTypeComboBox.Values = hash.ToArray();
        }
Exemple #21
0
 public Writer(PipelineNode parent, ScanCollection scanCollection)
     : base(parent, scanCollection)
 {
     input.Add(new Compatible("in", typeof(IType)));
 }