A union of curiosity and data science

Knowledgebase and brain dump of a database engineer


Resize Images in C# - Extreme Compression

 

Method for resizing images in C#

 

  public static void resizeImage(Image image, string save_path)
        {
            ImageCodecInfo myImageCodecInfo;
            System.Drawing.Imaging.Encoder myEncoder;
            EncoderParameter myEncoderParameter;
            EncoderParameters myEncoderParameters;

            int new_width = Convert.ToInt32(image.Width*.4281);
            int new_height = Convert.ToInt32(image.Height*.4281);

            Bitmap new_image = new Bitmap(new_width, new_height);
            Graphics g = Graphics.FromImage((Image)new_image);
            g.InterpolationMode = InterpolationMode.High;
            g.DrawImage(image, 0, 0, new_width, new_height);

            //Quality encoding. 
            myImageCodecInfo = GetEncoderInfo("image/jpeg");

            myEncoder = System.Drawing.Imaging.Encoder.Quality;

            myEncoderParameters = new EncoderParameters(1);

            //// EXTREME COMPRESSION Save the bitmap as a JPEG file with quality level 25.
            //myEncoderParameter = new EncoderParameter(myEncoder, 25L);
            //myEncoderParameters.Param[0] = myEncoderParameter;
            //new_image.Save(save_path, myImageCodecInfo, myEncoderParameters);

            //// Save the bitmap as a JPEG file with quality level 50.
            //myEncoderParameter = new EncoderParameter(myEncoder, 50L);
            //myEncoderParameters.Param[0] = myEncoderParameter;
            //new_image.Save(save_path, myImageCodecInfo, myEncoderParameters);

            // Save the bitmap as a JPEG file with quality level 75.
            myEncoderParameter = new EncoderParameter(myEncoder, 90L);
            myEncoderParameters.Param[0] = myEncoderParameter;
            new_image.Save(save_path, myImageCodecInfo, myEncoderParameters);


            // new_image.Save(save_path);
            // return new_image;
        }

        private static ImageCodecInfo GetEncoderInfo(String mimeType)
        {
            int j;
            ImageCodecInfo[] encoders;
            encoders = ImageCodecInfo.GetImageEncoders();
            for (j = 0; j < encoders.Length; ++j)
            {
                if (encoders[j].MimeType == mimeType)
                    return encoders[j];
            }
            return null;
        }

 

 

 

 

 

Predict stock prices with SQL Server Analysis Services Mining Models

Predictive analytics and supervised machine learning with SSAS and C#.

 

In this demo I use MS Time Series Mining structure to predict stock prices using the Auto Regressive Integrated Moving Average (ARIMA) method. 

  1. Data Mining and Machine Learning have been available in SQL Server since 2000.
  2. You don't need Cubes to use the mining structures.
  3. Accessing the models with C# and SSMS is easy

It's a basic mining structure example to demonstrate what SQL Server has been capable of. Please leave a comment if it helped or if you have any suggestions. 

The walk through consist of:

Creating a model:

Querying a model:

Querying a prediction from the model with a C# application: