/// <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(); }
/// <summary> /// Get function to check if image has elements (labels, segments or classifications). /// </summary> /// <param name="labelMode">Mode of navigation</param> /// <returns>Function to get information if elements are avaiable</returns> private static Func <ImageLabel, bool> HasElements(ELabelMode labelMode) { switch (labelMode) { case ELabelMode.ObjectDetection: return(o => o.HasLabels); } throw new NotImplementedException(); }
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)); }
/// <summary> /// Get information if imagelabels without segments or labels exists after current imagelabel. /// </summary> /// <param name="imageLabels">List of imagelabels</param> /// <param name="imageLabel">Imagelabel to find position for</param> /// <param name="labelMode">Mode of labels</param> /// <returns>TRUE if next imagelabels without segments or labels are avaiable, otherwise FALSE</returns> public static bool HasNextBlank(this IList <ImageLabel> imageLabels, ImageLabel imageLabel, ELabelMode labelMode) { #region validation if (imageLabels == null) { throw new ArgumentNullException(nameof(imageLabels)); } if (imageLabel == null) { throw new ArgumentNullException(nameof(imageLabel)); } #endregion return(imageLabels.HasNext(imageLabel, HasNoElements(labelMode))); }
/// <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> /// Get function to check if image has no elements (labels, segments or classifications). /// </summary> /// <param name="labelMode">Mode of navigation</param> /// <returns></returns> private static Func <ImageLabel, bool> HasNoElements(ELabelMode labelMode) { return(o => !HasElements(labelMode).Invoke(o)); }
private ImageNavigationResult CreateImageNavigationResult(Topic topic, ImageLabel image, IList <ImageLabel> images, ELabelMode labelMode) { // no image found for navigation request, return null if (image == null) { return(null); } // get fullfilled image structure return(new ImageNavigationResult { ImageLabel = ImageRepository.GetImageLabelById(topic, image.Id), ImageCount = images.Count, HasNextBlank = images.HasNextBlank(image, labelMode), HasNext = image.Index < images.Count - 1, HasPrevious = image.Index > 0, HasPreviousBlank = images.HasPreviousBlank(image, labelMode) }); }
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)); }