Example #1
0
        private void buttonHDR_Click(object sender, RoutedEventArgs e)
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            labelOutput.Content = "";

            OpenFileDialog dialog = new OpenFileDialog
            {
                Filter      = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif) | *.jpg; *.jpeg; *.jpe; *.jfif",
                Title       = "Please select image",
                Multiselect = true
            };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                // Load images
                MyImage[] images = loadImages(dialog.FileNames);

                // Get parameters
                int smoothfactor = (int)getParamater(textboxSmoothFactor);
                int samples      = (int)getParamater(textboxSample);

                // Display images
                drawImages(images);

                // Process images
                HDResult hdrResult = ImageProcessing.HDR(images, smoothfactor, samples);

                // Draw response graphs
                drawReponsesGraph(hdrResult.response);

                // Save HDR image
                HDRImage = hdrResult.HDR;

                MyImage tempImage = HDRImage.ToMyImage();

                // Show HDR image
                processedImage.Source = Utils.getSource(tempImage.GetBitmap());

                // Create histograms
                displayHistograms(tempImage);
            }

            watch.Stop();
            string timeTaken = String.Format(" HDR {0} ms", watch.ElapsedMilliseconds.ToString());

            Console.WriteLine(timeTaken);
            labelOutput.Content += timeTaken;
        }
Example #2
0
        // ============================================
        // HDR
        // ============================================

        public static HDResult HDR(MyImage[] images, int smoothfactor, int samples)
        {
            // Prepare data
            int imagesCount = images.Length;
            int width       = images[0].width;
            int height      = images[0].height;
            int numCh       = images[0].numCh;

            // Create random points for samples
            Random random = new Random();

            int[] randomX = new int[samples];
            int[] randomY = new int[samples];
            for (int i = 0; i < samples; ++i)
            {
                randomX[i] = random.Next(width);
                randomY[i] = random.Next(height);
            }

            // Get sample pixels and exposure time
            Pixel[][] imagesSamples = new Pixel[imagesCount][];
            double[]  exposureTime  = new double[imagesCount];
            for (int i = 0; i < imagesCount; ++i)
            {
                imagesSamples[i] = images[i].getSamples(samples, randomX, randomY);
                exposureTime[i]  = images[i].exposureTime;
            }

            // Process each channel
            HDResult hdrResult = new HDResult(new MyImageDouble(width, height, numCh));

            Parallel.For(0, numCh, ch =>
            {
                hdrResult.response[ch]     = GSolve(imagesSamples, exposureTime, smoothfactor, ch);
                hdrResult.HDR.bitplane[ch] = RadianceMap(getChannelFromimages(images, ch), hdrResult.response[ch], width, height, numCh);
            });

            hdrResult.HDR.log();
            hdrResult.HDR.normalize();
            hdrResult.HDR.divide(hdrResult.HDR.findMax());
            hdrResult.HDR.multiply(255.0);

            return(hdrResult);
        }