Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            MyImage img = new MyImage("taxi.bmp");

            img.RedFilter();
            img.Save("taxi.bmp");
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an histogram based on the image
        /// </summary>
        /// <param name="filename">specify the folder and filename</param>
        /// <returns>
        /// returns a string with the filename
        /// itcan vary because of existing file in the folder
        /// </returns>
        public string Histogram(string filename)
        {
            imageType        = "BM";
            offsetSize       = 54;
            int[,] histogram = this.histogram;
            int max = 0;

            foreach (int n in histogram)
            {
                if (n > max)
                {
                    max = n;
                }
            }
            float ratio = 100f / (float)max;

            Pixel[,] imageTemp = new Pixel[100, 256];
            for (int i = 0; i < imageTemp.GetLength(1); i++)
            {
                for (int j = 0; j < imageTemp.GetLength(0); j++)
                {
                    imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1] = Pixel.Black;
                    if (histogram[0, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddRed();
                    }
                    if (histogram[1, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddGreen();
                    }
                    if (histogram[2, i] * ratio >= j)
                    {
                        imageTemp[imageTemp.GetLength(0) - j - 1, imageTemp.GetLength(1) - i - 1].AddBlue();
                    }
                }
            }
            MyImage histo = new MyImage(imageTemp);

            string[] split = filename.Split('\\');
            filename = "";
            for (int i = 0; i < split.Length - 1; i++)
            {
                filename += split[i] + '\\';
            }
            filename += "histogram-" + split.Last();
            return(histo.Save(filename));
        }