Beispiel #1
0
        /// <summary>
        /// Sorts the image by saturation
        /// </summary>
        /// <param name="toSort">Image that is to be sorted</param>
        /// <param name="addOps">Additional operations that are selected</param>
        /// <param name="selectedSort">The selected sorting method</param>
        /// <returns></returns>
        private Bitmap SortBySaturation(Bitmap toSort, AdditionalOptionsEnum addOps, SortingMethodsEnum selectedSort, double lower, double upper)
        {
            // If spiral wasn't selected, then run the following code
            if (addOps != AdditionalOptionsEnum.Spiral)
            {
                for (int i = 0; i < toSort.Height; ++i)
                {
                    pixels.Clear();
                    for (int j = 0; j < toSort.Width; ++j)
                    {
                        pixels.Add(toSort.GetPixel(j, i));
                    }
                    pixels = SaturationSortWithBounds(pixels, lower, upper);

                    for (int j = 0; j < pixels.Count; ++j)
                    {
                        toSort.SetPixel(j, i, pixels[j]);
                    }
                }
            }

            // if spiral was selected, then run SortBySpiral
            else
            {
                toSort = SortBySpiral(toSort, selectedSort, lower, upper, RGBEnum.Blue);
            }

            // returns the sorted image
            return(toSort);
        }
Beispiel #2
0
        /// <summary>
        /// Sorts the bitmap using the float value provided by Color.GetHue(). This usually goes in
        /// the order of red - orange - yellow - green - blue - purple - red
        /// </summary>
        /// <param name="toSort">Bitmap that needs to be sorted</param>
        /// <returns></returns>
        public Bitmap SortByHue(Bitmap toSort, AdditionalOptionsEnum addOps, SortingMethodsEnum selectedSort, double lower, double upper)
        {
            // If spiral wasn't selected, then run the following code
            if (addOps != AdditionalOptionsEnum.Spiral)
            {
                // Iterate through each row of the image, sort that row according to HueSort, and then replace the unsorted row with the sorted row
                for (int i = 0; i < toSort.Height; ++i)
                {
                    pixels.Clear();
                    for (int j = 0; j < toSort.Width; ++j)
                    {
                        pixels.Add(toSort.GetPixel(j, i));
                    }
                    pixels = HueSortWithBounds(pixels, lower, upper);

                    for (int j = 0; j < pixels.Count; ++j)
                    {
                        toSort.SetPixel(j, i, pixels[j]);
                    }
                }
            }

            // if spiral was selected, then run SortBySpiral
            else
            {
                toSort = SortBySpiral(toSort, selectedSort, lower, upper, RGBEnum.Blue);
            }

            return(toSort);
        }
Beispiel #3
0
        /// <summary>
        /// This will sort the passed in image by moving from the exterior perimeter to the interior and sorting the perimeter as though it was one singular line
        /// </summary>
        /// <param name="image">The image to be sorted</param>
        /// <param name="selectedSort">The selected sorting method</param>
        /// <param name="lower">The lower bound (used for brightness sorting)</param>
        /// <param name="upper">The upper bound (used for brightness sorting)</param>
        /// <param name="color">The selected color (used for RGB sorting)</param>
        /// <returns>Returns a sorted image</returns>
        private Bitmap SortBySpiral(Bitmap image, SortingMethodsEnum selectedSort, double lower, double upper, RGBEnum color)
        {
            //Sets the intial boundaries for the min and max values of Width and Height
            int endWidth    = image.Width - 1;
            int endHeight   = image.Height - 1;
            int startWidth  = 0;
            int startHeight = 0;

            // Iteratively moves in from the exterior to the center and sorts the collected pixels from the perimeter
            while (endWidth >= startWidth && endHeight >= startHeight)
            {
                // Clear pixels and add the pixels from the perimeter to it
                pixels.Clear();
                for (int i = startWidth; i < endWidth; ++i)
                {
                    pixels.Add(image.GetPixel(i, startHeight));
                }
                for (int i = startHeight; i < endHeight; ++i)
                {
                    pixels.Add(image.GetPixel(endWidth, i));
                }
                for (int i = endWidth; i > startWidth; --i)
                {
                    pixels.Add(image.GetPixel(i, endHeight));
                }
                for (int i = endHeight; i > startHeight; --i)
                {
                    pixels.Add(image.GetPixel(startWidth, i));
                }

                // Sort pixels with respect to bounds by Brightness
                if (selectedSort == SortingMethodsEnum.Brightness)
                {
                    pixels = BrightSortWithBounds(pixels, lower, upper);
                }

                // Sort pixels by Hue
                if (selectedSort == SortingMethodsEnum.Hue)
                {
                    pixels = HueSortWithBounds(pixels, lower, upper);
                }

                // Sort pixels by Saturation
                if (selectedSort == SortingMethodsEnum.Saturation)
                {
                    pixels = SaturationSortWithBounds(pixels, lower, upper);
                }

                // Sort pixels with respect to RGB
                if (selectedSort == SortingMethodsEnum.RGB)
                {
                    pixels = RGBSortWithBounds(pixels, lower, upper, color);
                }

                // Put the pixels that were sorted back into the perimeter of the image
                int count = 0;

                for (int i = startWidth; i < endWidth; ++i)
                {
                    image.SetPixel(i, startHeight, pixels[count]);
                    count++;
                }
                for (int i = startHeight; i < endHeight; ++i)
                {
                    pixels.Add(image.GetPixel(endWidth, i));
                    image.SetPixel(endWidth, i, pixels[count]);
                    count++;
                }
                for (int i = endWidth; i > startWidth; --i)
                {
                    image.SetPixel(i, endHeight, pixels[count]);
                    count++;
                }
                for (int i = endHeight; i > startHeight; --i)
                {
                    pixels.Add(image.GetPixel(startWidth, i));
                    image.SetPixel(startWidth, i, pixels[count]);
                    count++;
                }

                ++startWidth;
                ++startHeight;
                --endWidth;
                --endHeight;
            }

            // image is returned
            return(image);
        }
Beispiel #4
0
        /// <summary>
        /// Sorts the image by the Color.Brightness() float value. Can be filtered with the passed
        /// in lower and upper values
        /// </summary>
        /// <param name="toSort">Bitmap that needs to be sorted</param>
        /// <param name="lower">Lower bound for the brightness values</param>
        /// <param name="upper">Upper bound for the brightness values</param>
        /// <returns></returns>
        public Bitmap SortByBrightness(Bitmap toSort, double lower, double upper, AdditionalOptionsEnum addOps, SortingMethodsEnum selectedSort)
        {
            // Ensures that upper > lower
            if (upper < lower)
            {
                double mid = upper;
                upper = lower;
                lower = mid;
            }

            // Sets upper and lower so that neither is outside of the bounds of 0.0 and 1.0
            if (upper > 1.0)
            {
                upper = 1.0;
            }
            if (lower < 0.0)
            {
                lower = 0.0;
            }

            // If spiral wasn't selected, then run the following code
            if (addOps != AdditionalOptionsEnum.Spiral)
            {
                // loops through the height of the image
                for (int i = 0; i < toSort.Height; ++i)
                {
                    // clears pixels every time
                    pixels.Clear();

                    // Adds each row to pixels
                    for (int j = 0; j < toSort.Width; ++j)
                    {
                        pixels.Add(toSort.GetPixel(j, i));
                    }

                    // Sort pixels with respect to bounds
                    pixels = BrightSortWithBounds(pixels, lower, upper);

                    // place each pixel from pixels into the correct row of the image
                    for (int j = 0; j < pixels.Count; ++j)
                    {
                        toSort.SetPixel(j, i, pixels[j]);
                    }
                }
            }

            // if spiral was selected, then run SortBySpiral
            else
            {
                toSort = SortBySpiral(toSort, selectedSort, lower, upper, RGBEnum.Blue);
            }

            // return the image
            return(toSort);
        }
Beispiel #5
0
        /// <summary>
        /// Default method to be used for a new sorting instance
        /// </summary>
        /// <param name="path">Path of the image that will be processed</param>
        /// <param name="selectedSort">Enum of the selected sorting method to be used</param>
        /// <param name="lower">lower bounds for the brightness sort</param>
        /// <param name="upper">upper bounds for the brightness sort</param>
        /// <returns></returns>
        public Bitmap Sort(string path, SortingMethodsEnum selectedSort, double lower, double upper, int hP, int vP, RGBEnum colorChecked, AdditionalOptionsEnum addOps, DirectionEnum directionChecked)
        {
            // if path is null or "", return null
            if (path == null || path.Equals(""))
            {
                return(null);
            }

            // creates two Bitmaps of the same image, handy for keeping the original width/height
            // and other data
            Bitmap image     = new Bitmap(@path);
            Bitmap origImage = new Bitmap(@path);

            image     = RotateImage(image, directionChecked);
            origImage = RotateImage(origImage, directionChecked);

            // if Extend is clicked, ExtendSort the image
            if (addOps == AdditionalOptionsEnum.Extend)
            {
                image = ExtendSort(image);
            }

            // If the number of horizontal or vertical partitions is greater than or equal to the
            // width or height of the image, don't partition the image and sort with the whole image instead
            if (hP >= image.Width || vP >= image.Height)
            {
                // Switch statement for using the correct sort based on the selected method
                switch (selectedSort)
                {
                case SortingMethodsEnum.Brightness:
                    image = SortByBrightness(image, lower, upper, addOps, selectedSort);
                    break;

                case SortingMethodsEnum.Hue:
                    image = SortByHue(image, addOps, selectedSort, lower, upper);
                    break;

                case SortingMethodsEnum.Saturation:
                    image = SortBySaturation(image, addOps, selectedSort, lower, upper);
                    break;

                case SortingMethodsEnum.RGB:
                    image = SortByRGB(image, colorChecked, addOps, selectedSort, lower, upper);
                    break;

                default:
                    break;
                }
            }
            // If the number of partitions wanted is within the image's width/height, split the
            // image into (horizontal partitions + 1) * (vertical partitions + 1), sort the
            // paritions, and then stitch them back together
            else
            {
                int modx = image.Width % (1 + hP);
                int mody = image.Height % (1 + vP);
                image = RotateImageBack(image, directionChecked);
                List <Bitmap> partitions = PartitionImage(image, hP, vP, modx, mody);

                for (int i = 0; i < partitions.Count; ++i)
                {
                    partitions[i] = RotateImage(partitions[i], directionChecked);
                    switch (selectedSort)
                    {
                    case SortingMethodsEnum.Brightness:
                        partitions[i] = SortByBrightness(partitions[i], lower, upper, addOps, selectedSort);
                        partitions[i] = RotateImageBack(partitions[i], directionChecked);
                        continue;

                    case SortingMethodsEnum.Hue:
                        partitions[i] = SortByHue(partitions[i], addOps, selectedSort, lower, upper);
                        partitions[i] = RotateImageBack(partitions[i], directionChecked);
                        continue;

                    case SortingMethodsEnum.Saturation:
                        partitions[i] = SortBySaturation(partitions[i], addOps, selectedSort, lower, upper);
                        partitions[i] = RotateImageBack(partitions[i], directionChecked);
                        continue;

                    case SortingMethodsEnum.RGB:
                        partitions[i] = SortByRGB(partitions[i], colorChecked, addOps, selectedSort, lower, upper);
                        partitions[i] = RotateImageBack(partitions[i], directionChecked);
                        continue;

                    default:
                        partitions[i] = RotateImageBack(partitions[i], directionChecked);
                        continue;
                    }
                }

                image = Recombine(partitions, hP + 1);
                image = RotateImage(image, directionChecked);
            }

            // if Extending was selected, then put the image back together so it's no longer a single line of pixels
            if (addOps == AdditionalOptionsEnum.Extend)
            {
                image = UnExtendSort(image, origImage);
            }

            image = RotateImageBack(image, directionChecked);

            // return the image to the user
            return(image);
        }