Exemplo n.º 1
0
 /// <summary>
 /// Navigate through list of imagelabels for segments.
 /// </summary>
 /// <param name="imageLabels">List of imagelabels to navigate.</param>
 /// <param name="navigationDirection">Direction of navigation</param>
 /// <param name="currentIndex">Current index</param>
 /// <returns>Imagelabel of navigation</returns>
 public static ImageLabel Navigate(this IList <ImageLabel> imageLabels, ENavigationDirection navigationDirection, int currentIndex)
 {
     return(imageLabels.NavigateLabels(navigationDirection, currentIndex));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Navigate through list of imagelabels for labels.
        /// </summary>
        /// <param name="imageLabels">List of imagelabels to navigate.</param>
        /// <param name="navigationDirection">Direction of navigation</param>
        /// <param name="currentIndex">Current index</param>
        /// <returns>Imagelabel of navigation</returns>
        private static ImageLabel NavigateLabels(this IList <ImageLabel> imageLabels, ENavigationDirection navigationDirection, int currentIndex)
        {
            switch (navigationDirection)
            {
            case ENavigationDirection.Direct:
                return(imageLabels.ElementAtOrDefault(currentIndex));

            case ENavigationDirection.Blank:
            case ENavigationDirection.NextBlank:
                return(imageLabels.NextUnlabeled(currentIndex));

            case ENavigationDirection.Next:
                return(imageLabels.ElementAtOrDefault(currentIndex + 1));

            case ENavigationDirection.Previous:
                return(imageLabels.ElementAtOrDefault(currentIndex - 1));

            case ENavigationDirection.PreviousBlank:
                return(imageLabels.PreviousUnlabeled(currentIndex));

            case ENavigationDirection.LastBlank:
                int?lastLabeledIndex = imageLabels.LastLabeledIndex();
                return(imageLabels.ElementAtOrDefault(lastLabeledIndex.HasValue ? lastLabeledIndex.Value + 1 : 0));
            }
            throw new NotImplementedException();
        }
Exemplo n.º 3
0
 public static IEnumerable <ImageLabel> ShrinkToBlankList(this IList <ImageLabel> imageLabels, ENavigationDirection navigationDirection, int currentIndex)
 {
     return(imageLabels.ShrinkToUnlabeledList(navigationDirection, currentIndex));
 }
Exemplo n.º 4
0
        private static IEnumerable <ImageLabel> ShrinkToUnlabeledList(this IList <ImageLabel> imageLabels, ENavigationDirection navigationDirection, int currentIndex)
        {
            switch (navigationDirection)
            {
            case ENavigationDirection.Blank:
                return(imageLabels.Where(o => !o.HasLabels));

            case ENavigationDirection.NextBlank:
                return(imageLabels.Skip(currentIndex + 1).Where(o => !o.HasLabels));

            case ENavigationDirection.PreviousBlank:
                return(imageLabels.Take(currentIndex).Where(o => !o.HasLabels));
            }
            throw new NotImplementedException();
        }
        /// <summary>
        /// Shrink given list to list of images without additional elements (depends on labelmode).
        /// For example: Shrink image list to list of images without labels in labelmode objectdetection.
        /// </summary>
        /// <param name="imageLabels">List of labels</param>
        /// <param name="labelMode">Mode of navigation</param>
        /// <param name="navigationDirection">Direction of navigation</param>
        /// <param name="currentIndex">Current index of navigation</param>
        /// <returns>Shrinked list</returns>
        public static IEnumerable <ImageLabel> ShrinkToBlankList(this IEnumerable <ImageLabel> imageLabels, ELabelMode labelMode, ENavigationDirection navigationDirection, int currentIndex)
        {
            #region validation

            if (imageLabels == null)
            {
                throw new ArgumentNullException(nameof(imageLabels));
            }

            #endregion

            switch (navigationDirection)
            {
            case ENavigationDirection.Blank:
                return(imageLabels.Where(HasNoElements(labelMode)));

            case ENavigationDirection.NextBlank:
                return(imageLabels.Skip(currentIndex + 1).Where(HasNoElements(labelMode)));

            case ENavigationDirection.PreviousBlank:
                return(imageLabels.Take(currentIndex).Where(HasNoElements(labelMode)));
            }
            throw new NotImplementedException();
        }
        /// <summary>
        /// Navigate through list of imagelabels for segments.
        /// </summary>
        /// <param name="imageLabels">List of imagelabels to navigate.</param>
        /// <param name="navigationDirection">Direction of navigation</param>
        /// <param name="labelMode">Label mode</param>
        /// <param name="currentIndex">Current index</param>
        /// <returns>Imagelabel of navigation</returns>
        public static ImageLabel Navigate(this IList <ImageLabel> imageLabels, ELabelMode labelMode, ENavigationDirection navigationDirection, int currentIndex)
        {
            #region validation

            if (imageLabels == null)
            {
                throw new ArgumentNullException(nameof(imageLabels));
            }

            #endregion

            switch (navigationDirection)
            {
            case ENavigationDirection.Direct:
                return(imageLabels.ElementAtOrDefault(currentIndex));

            case ENavigationDirection.Blank:
            case ENavigationDirection.NextBlank:
                return(imageLabels.Next(currentIndex, HasNoElements(labelMode)));

            case ENavigationDirection.Next:
                return(imageLabels.ElementAtOrDefault(currentIndex + 1));

            case ENavigationDirection.Previous:
                return(imageLabels.ElementAtOrDefault(currentIndex - 1));

            case ENavigationDirection.PreviousBlank:
                return(imageLabels.Previous(currentIndex, HasNoElements(labelMode)));

            case ENavigationDirection.LastBlank:
                int?lastIndex = imageLabels.LastIndex(HasElements(labelMode));
                return(imageLabels.ElementAtOrDefault(lastIndex.HasValue ? lastIndex.Value + 1 : 0));
            }
            throw new NotImplementedException();
        }
Exemplo n.º 7
0
        private ImageNavigationResultView GetImageLabelNavigationResult(Topic topic, NavigationParameter navigationParameter, ENavigationDirection navigationDirection)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // fill imagelabel-structure of image label
            ImageNavigationResult image = NavigationService.Navigate(topic, navigationParameter.Index, navigationParameter.LabelMode, navigationDirection);


            // default navigation if not label was found on navigation to blank
            if (image == null && (navigationDirection == ENavigationDirection.Blank || navigationDirection == ENavigationDirection.LastBlank))
            {
                image = NavigationService.Navigate(topic, navigationParameter.Index, navigationParameter.LabelMode, ENavigationDirection.Direct);
            }

            if (image == null)
            {
                // return http-404 if no label found
                return(null);
            }

            // create naviation result
            ImageNavigationResultView navigationResult = ImageNavigationResultFactory.CreateView(image);

            switch (navigationParameter.LabelMode)
            {
            case ELabelMode.ObjectDetection:
                if (image.ImageLabel.HasLabels)
                {
                    IEnumerable <Label> labels = LabelService.GetLabels(topic, image.ImageLabel);
                    navigationResult.ImageLabel.Labels = labels.Select(LabelFactory.CreateView);
                }
                break;
            }

            sw.Stop();
            Log.Information($"Navigation takes {sw.ElapsedMilliseconds} ms");

            return(navigationResult);
        }
Exemplo n.º 8
0
        private ActionResult Navigate(Topic topic, NavigationParameter navigationParameter, ENavigationDirection navigationDirection)
        {
            #region validation

            CheckMandatoryParameter(nameof(navigationParameter), navigationParameter);

            #endregion

            // create naviation result
            ImageNavigationResultView result = GetImageLabelNavigationResult(topic, navigationParameter, navigationDirection);
            if (result != null)
            {
                return(Ok(result));
            }
            return(NotFound(Messages.ImageNotFound((uint)navigationParameter.Index)));
        }
Exemplo n.º 9
0
        private ImageLabelNavigationResult GetImageLabelNavigationResult(Topic topic, NavigationParameter navigationParameter, ENavigationDirection navigationDirection)
        {
            // get list of all image labels
            List <ImageLabel> imageLabels = this.ImageService.GetImageLabels(topic).ToList();

            // fill imagelabel-structure of image label
            ImageLabel navigationImageLabel = imageLabels.Navigate(navigationDirection, navigationParameter.Index);

            if (navigationImageLabel == null)
            {
                // return http-404 if no label found
                return(null);
            }

            // create naviation result
            return(new ImageLabelNavigationResult
            {
                ImageLabel = this.ImageService.Navigate(topic, (uint)navigationImageLabel.Index),
                ImageCount = imageLabels.Count,
                HasNextBlank = imageLabels.HasNextBlank(navigationImageLabel),
                HasNext = imageLabels.HasNext(navigationImageLabel),
                HasPrevious = imageLabels.HasPrevious(navigationImageLabel),
                HasPreviousBlank = imageLabels.HasPreviousBlank(navigationImageLabel)
            });
        }
Exemplo n.º 10
0
        public ImageNavigationResult Navigate(Topic topic, long startIndex, ELabelMode labelMode, ENavigationDirection navigationDirection)
        {
            #region valdiation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (!Enum.IsDefined(typeof(ELabelMode), labelMode))
            {
                throw new ArgumentException(nameof(labelMode));
            }

            if (!Enum.IsDefined(typeof(ENavigationDirection), navigationDirection))
            {
                throw new ArgumentException(nameof(navigationDirection));
            }

            #endregion

            return(ImageLabelNavigationRepository.GetNavigationResult(topic, startIndex, labelMode, navigationDirection));
        }
Exemplo n.º 11
0
        public ImageNavigationResult GetNavigationResult(Topic topic, long startIndex, ELabelMode labelMode, ENavigationDirection navigationDirection)
        {
            #region valdiation

            if (topic == null)
            {
                throw new ArgumentNullException(nameof(topic));
            }

            if (!Enum.IsDefined(typeof(ELabelMode), labelMode))
            {
                throw new ArgumentException(nameof(labelMode));
            }

            if (!Enum.IsDefined(typeof(ENavigationDirection), navigationDirection))
            {
                throw new ArgumentException(nameof(navigationDirection));
            }

            #endregion

            // get list of all image labels
            IList <ImageLabel> images = ImageRepository.GetImages(topic);

            // fill imagelabel-structure of image label
            ImageLabel image = images.Navigate(labelMode, navigationDirection, (int)startIndex);

            return(CreateImageNavigationResult(topic, image, images, labelMode));
        }