Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }