Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var config = Config.LoadConfig(args[0]);

            String inputFolder      = config.Get("input_folder");
            String path             = inputFolder + config.Get("image_file");
            String outPath          = inputFolder + "output_file.png";
            bool   saveAsGrayScale  = config.Bool("save_input_as_grayscale", false);
            float  threshold        = config.Float("threshold", 0.99f);
            int    numTrainings     = config.Int("num_trainings", 100);
            int    numLabels        = config.Int("num_labels", 20);
            int    numSeedPositions = config.Int("num_seed_positions", 100);

            Bitmap bm = LoadImage(path);

            if (true)
            {
                Bitmap mp = ConvertToGrayScale(bm);
                SaveImage(mp, outPath + "input_as_grayscale.png");
            }

            List <float[]> data         = LoadImageAsGrayScale(bm);
            Data           cellData     = new Data(data);
            List <int>     labels       = cellData.SeedValues(numLabels, numSeedPositions);
            float          maxIntensity = cellData.GetMaxIntensity();
            CA             ca           = new CA(maxIntensity, threshold);

            DebugSeedPositions(cellData, labels);
            DebugLabels(labels);

            for (int i = 0; i < numTrainings; i++)
            {
                IterateCells(ca, cellData, labels, threshold);

                "Iteration: {0} Num state transitions: {1}".Cout(i, ca.NumStateTransitions);
                if (ca.NumStateTransitions == 0)
                {
                    break;
                }
                ca.NumStateTransitions = 0;
            }

            DebugSeedPositions(cellData, labels);
            DebugLabels(labels);
            SaveOutputImage(cellData, labels, outPath);
        }
Ejemplo n.º 2
0
        public static Data IterateCells(CA ca, Data cellData, List <int> labels, float threshold)
        {
            var imageData = cellData.GetData();

            int y = 0;

            foreach (float[] row in imageData)
            {
                int x = 0;
                foreach (float pixel_value in row)
                {
                    int[] fp = new int[2];
                    fp[0] = x;
                    fp[1] = y;
                    Position  p = new Position(fp);
                    CellState s = cellData.GetCellState(p);
                    ca.ProcessCell(cellData, labels, p, s);
                    x++;
                }
                y++;
            }
            return(cellData);
        }
Ejemplo n.º 3
0
        public CellState[][] Train(List <float[]> data, float threshold)
        {
            Data       d            = new Data(data);
            float      maxIntensity = d.GetMaxIntensity();
            CA         ca           = new CA(maxIntensity, threshold);
            List <int> labels       = d.SeedValues(20, 40);

            for (int i = 0; i < 400; i++)
            {
                int y = 0;
                foreach (float[] row in data)
                {
                    int x = 0;
                    foreach (float pixel_value in row)
                    {
                        int[] fp = new int[2];
                        fp[0] = x;
                        fp[1] = y;
                        Position  p = new Position(fp);
                        CellState s = d.GetCellState(p);
                        ca.ProcessCell(d, labels, p, s);
                        x++;
                    }
                    y++;
                }

                "Iteration: {0} Num state transitions: {1}".Cout(i, ca.NumStateTransitions);

                if (ca.NumStateTransitions == 0)
                {
                    break;
                }
                ca.NumStateTransitions = 0;
            }
            return(d.CellStates);
        }