public EditableOperationBatch(DataImage resultImage)
 {
     steps = new List<EditableOperationBatchStep>();
     stepsDict = new Dictionary<string, EditableOperationBatchStep>();
     imageResult = resultImage;
     images = new Dictionary<string, DataImage>();
     imagesList = new List<DataImage>();
     CalculateSteps();
 }
예제 #2
0
    public int processImage(String name, int W, int H, int[] data)
    {
        //return 0;

        //Console.Out.WriteLine("processImage(" + name + "," + W.ToString() + "," + H.ToString() + ")");
        //Console.Out.Flush();
        currentImage = TopCoderMarathon2.ImageRetriever.GetData(name, W, H, data);
        //Console.Out.WriteLine("currentImage: " + currentImage.ToString());
        //Console.Out.Flush();
        AnalyzeData(currentImage);
        //Get
        return 0;
    }
        public static Cluster DetectCluster(DataImage resultImage, int xOrigin, int yOrigin, byte minColor, byte maxColor)
        {
            result = resultImage;
            data = result.data;
            pixelsChecked = new bool[data.Length];
            colorMin = minColor;
            colorMax = maxColor;
            height = result.Height;
            width = result.Width;

            ranges = new RangeQueue();
            currentCluster = new Cluster(resultImage);

            //////
            if (!(result[xOrigin, yOrigin] >= minColor && result[xOrigin, yOrigin] <= maxColor))
                throw new InvalidOperationException("Point is not within color range");
            /////\
            LinearDetect(ref xOrigin, ref yOrigin);

            while (ranges.size > 0)
            {
                DetectionRange range = ranges.Dequeue();

                int upY = range.y - 1;
                int downY = range.y + 1;

                int downIndex = resultImage.GetDataIndex(range.x1, downY);
                int upIndex = resultImage.GetDataIndex(range.x1, upY);

                int currentIndex;

                for (int x = range.x1; x <= range.x2; x++)
                {
                    currentIndex = result.GetDataIndex(x, upY);
                    if (range.y > 0 && (!pixelsChecked[upIndex]) && PixelIsWithinColorRange(ref currentIndex))
                        LinearDetect(ref x, ref upY);

                    currentIndex = result.GetDataIndex(x, downY);
                    if (range.y < (height - 1) && (!pixelsChecked[downIndex]) && PixelIsWithinColorRange(ref currentIndex))
                        LinearDetect(ref x, ref downY);
                    downIndex += height;
                    upIndex += height;
                }
            }
            Array.Resize<int>(ref currentCluster.indexes, currentCluster.Length);
            Array.Sort(currentCluster.Indexes);
            return currentCluster;
        }
        static DataImage GetDataImage(byte[] pixelData)
        {
            DataImage image = new DataImage(pixelData);

            return image;
        }
 /// <summary>
 /// Detects a cluster at the specified index and excludes it if the total area is below threshhold
 /// </summary>
 /// <param name="data"></param>
 /// <param name="i"></param>
 private Cluster DetectCluster(DataImage image, int dataIndex)
 {
     currentCluster = new Cluster(image);
     int x, y;
     image.GetDataCoordinates(dataIndex, out x, out y);
     return ClusterDetect.DetectCluster(image, x, y, mincolor, maxcolor);
 }
 public virtual void Analyze(DataImage image)
 {
     //image.Normalize();
     image.Save();
 }
 public DataImageLRO(DataImage dataImage)
     : base(dataImage)
 {
 }
 private void InitializeEditor(DataImage currentImage)
 {
     batch = new EditableOperationBatch(currentImage);
     LoadChooseStep();
     imageFixedResult.CurrentImage = batch.ImageResult;
 }
        //Recursive
        EditableOperationBatchStep AddBatchStep(DataImage image)
        {
            EditableOperationBatchStep step = new EditableOperationBatchStep(this, image);
            if (steps.Contains(step))
                return null; //already added

            if (image.ResultOf == null)
            {
                imageSource = image;
                return null; //do not add step for first image since there is no step for first image
            }

            EditableOperationBatchStep stepTemp = AddBatchStep(image.ResultOf.Source);
            if (stepTemp != null)
                steps.Add(stepTemp);

            //if (typeof(DualImageOperator).IsAssignableFrom(image.ResultOf.GetType()))
            //{
                try
                {
                    DualImageOperator d = (DualImageOperator)image.ResultOf;
                    stepTemp = AddBatchStep(((DualImageOperator)image.ResultOf).Source2);
                    if (stepTemp != null)
                        steps.Add(stepTemp);
                }
                catch (Exception)
                {
                }
               // }

            return step;
        }
 void TagImage(DataImage image)
 {
     if (!batch.ImagesList.Contains(image))
     {
         batch.ImagesList.Add(image);
         batch.Images.Add((batch.ImagesList.Count - 1).ToString(), image);
     }
 }
 string GetImageString(DataImage image)
 {
     return batch.ImagesList.IndexOf(image).ToString();
 }
        public EditableOperationBatchStep(EditableOperationBatch batch, DataImage image)
        {
            this.batch = batch;
            TagImage(image);

            this.operationResult = GetImageString(image);
            if (image.ResultOf != null)
            {
                TagImage(image.ResultOf.Source);
                this.source1 = GetImageString(image.ResultOf.Source);

                this.imageOperation = image.ResultOf.ImageOperation;
                try
                {

                    //if (typeof(DualImageOperation).IsAssignableFrom(imageOperation.GetType()))
                    //{
                        DualImageOperation d = (DualImageOperation)imageOperation;
                        TagImage(d.imageSource2);
                        this.source2 = GetImageString(d.imageSource2);
                    //}
                }
                catch (Exception)
                {
                }
            }
        }
        //Removes all no-op operations from the image graph
        bool RemoveNOOPs(DataImage image)
        {
            bool noopRemoved = false;
            if (image.ResultOf != null && image.ResultOf.ImageOperation.IsNOOP() && image.Parent != null)
            {
                RemoveNOOPImage(image);
                return true;
            }

            bool done = false;
            int counter = 0;
            int count = image.Children.Count;
            while (!done && image.Children.Count > 0)
            {
                DataImage c = image.Children[counter];
                noopRemoved = noopRemoved || RemoveNOOPs(c);
                if (count != image.Children.Count)
                    count = image.Children.Count;
                else
                    counter++;
                if (counter == image.Children.Count)
                    done = true;
            }
            return noopRemoved;
        }
 //Removes the image from the graph and updates parent/children
 void RemoveNOOPImage(DataImage image)
 {
     if (image == imageResult)
         ImageResult = image.Parent;
     while (image.Children.Count > 0)
     {
         image.Children[0].Parent = image.Parent;
     }
     image.Parent.Children.Remove(image);
 }
        private void ProcessSerializedStep(string entry)
        {
            // Console.Out.WriteLine("Processing Step: " + entry);
               // Console.Out.Flush();
            //R#:S1#:S2#:FUNC%PARAM1%PARAM2
            string[] parts = entry.Split(':');
            //////
            if (parts.Length != 4)
                throw new InvalidOperationException();
            /////\
            string resultKey = parts[0];
            string op = parts[3];

            if (op == "SRC")
            {
                DataImage imageSource = new DataImage(EditableOperationBatch.currentSourceData);
                this.imageSource = imageSource;
                images.Add(resultKey, imageSource);
            }
            else
            {
                EditableOperationBatchStep step = EditableOperationBatchStep.FromSerialization(entry);
                stepsDict.Add(step.Name, step);
                steps.Add(step);
            }
        }
 public override void Analyze(DataImage image)
 {
     base.Analyze(image);
 }
        private void LoadImage(DataImagePanel imagePanel, DataImage image)
        {
            Control c = imagePanel.Parent.Parent.Parent;
            if (c.GetType() == typeof(MonoControlContainer))
            {
                //Ensure that operator is properly set up
                MonoImageOperator op = new MonoImageOperator();
                MonoControlContainer mono = (MonoControlContainer)c;
                mono.imageOperator = op;
                mono.monoControlPanel1.CurrentControl = new NormalizeControl();
                mono.imageOperator.ImageOperation = mono.monoControlPanel1.CurrentControl.UnderlyingWidget;
                op.Source = image;
                imagePanel.CurrentImage = op.Result;
            }

            //Set up result panel
            if (mono1.dataImagePanel1.CurrentImage != null && mono2.dataImagePanel1.CurrentImage != null)
            {
                if (result.mono.CurrentControl == null)
                {
                    result.mono.CurrentControl = new NormalizeControl();
                    result.imageOperatorMono.ImageOperation = result.mono.CurrentControl.UnderlyingWidget;
                }
                if (result.dual.CurrentControl == null)
                {
                    result.dual.CurrentControl = new DualSubtractionControl();
                    result.imageOperatorDual.ImageOperation = result.dual.CurrentControl.UnderlyingWidget;
                }

                this.result.imageOperatorDual.Source = mono1.dataImagePanel1.CurrentImage;
                this.result.imageOperatorDual.Source2 = mono2.dataImagePanel1.CurrentImage;
                this.result.imageOperatorMono.Source = this.result.imageOperatorDual.Result;
                this.result.dataImagePanel1.CurrentImage = this.result.imageOperatorDual.Result;
                this.result.dataImagePanel1.labelImage.Text = this.result.dataImagePanel1.CurrentImage.Name;
            }

            imagePanel.labelImage.Text = imagePanel.CurrentImage.Name;
            CurrentControlChanged_Trigger();
        }
 public DataImageA15(DataImage dataImage)
     : base(dataImage)
 {
 }