Brightness adjusting using luminance value of HSL color space
Inheritance: IFilter, IInPlaceFilter
コード例 #1
0
        public override void ThreadMethod(object poThreadParameter)
        {
            // This is the code that is going to be run by the thread
            // It has access to all the instance variable of this class
            // It receives the instance as a parameter
            // We must typecast poThreadParameter to BrightnessAdjustmentPiece (inherited from ParallelAlgorithmPiece)
            // to gain access to its members
            BrightnessAdjustmentPiece loPiece;

            loPiece = (BrightnessAdjustmentPiece)poThreadParameter;

            // Retrieve the thread number received in object poThreadParameter, in piThreadNumber property
            long liPieceNumber = loPiece.piThreadNumber;

            //Format the image according to AForge.NET needs to apply the filter
            AForge.Imaging.Image.FormatImage(ref proBitmap);
            // Create an instance of the brightness correction filter
            AForge.Imaging.Filters.BrightnessCorrection loBrightnessCorrection = new AForge.Imaging.Filters.BrightnessCorrection(priBrightnessDelta);
            // Process the image (correct the brightness)
            loBrightnessCorrection.ApplyInPlace(proBitmap);

            // Code added in the WaitHandle.WaitAll version
            // The thread finished its work. Signal that the work item has finished.
            poAutoResetEvent.Set();
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: adadams111/codexemporium
        private void button4_Click(object sender, EventArgs e)
        {
            System.Drawing.Bitmap image = new Bitmap(picSource.BackgroundImage);
            // create filter
            AForge.Imaging.Filters.BrightnessCorrection filter = new AForge.Imaging.Filters.BrightnessCorrection(-50);
            // apply filter
            System.Drawing.Bitmap newImage = filter.Apply(image);

            picOutput.BackgroundImage = newImage;
        }
コード例 #3
0
ファイル: ImageProcess.cs プロジェクト: linuxbank/PLOCR
        // 밝게
        public static Bitmap bright(Bitmap source)
        {
            ///////////// ini 객체 생성 시작 /////////////////////////////////////////////////////
            //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe
            FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe");
            string pathini = exefileinfo.Directory.FullName.ToString();  //프로그램 실행되고 있는데 path 가져오기
            string fileName = @"\PLOCRconfig.ini";  // 환경설정 파일명
            string filePath = pathini + fileName;   //ini 파일 경로
            PLOCR.IniUtil ini = new PLOCR.IniUtil(filePath);   // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌)
            //////////// ini 객체 생성 끝 /////////////////////////////////////////////////////////

            int order = int.Parse(ini.GetIniValue("밝기값", "밝게횟수"));

            for (int i = 0; i < order; i++)
            {
                // create filter
                BrightnessCorrection filter = new BrightnessCorrection(+10);
                // apply the filter
                filter.ApplyInPlace(source);
            }

            return source;
        }
コード例 #4
0
        public override void GetLiveImage()
        {
            try
            {
                LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
            }
            catch (Exception)
            {
                return;
            }

            if (LiveViewData == null || LiveViewData.ImageData == null)
                return;
            MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                   LiveViewData.ImageDataPosition,
                                                   LiveViewData.ImageData.Length -
                                                   LiveViewData.ImageDataPosition);
            using (var bmp = new Bitmap(stream))
            {
                Bitmap res = bmp;
                var preview = BitmapFactory.ConvertToPbgra32Format(BitmapSourceConvert.ToBitmapSource(res));
                var zoow = preview.Crop((int)(CentralPoint.X - (StarWindowSize / 2)), (int)(CentralPoint.Y - (StarWindowSize / 2)),
                        StarWindowSize, StarWindowSize);
                CalculateStarSize(zoow);
                zoow.Freeze();
                StarWindow = zoow;

                preview.Freeze();
                Preview = preview;


                if (Brightness != 0)
                {
                    BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                    res = filter.Apply(res);
                }
                if (EdgeDetection)
                {
                    var filter = new FiltersSequence(
                        Grayscale.CommonAlgorithms.BT709,
                        new HomogenityEdgeDetector()
                        );
                    res = filter.Apply(res);
                }

                var _bitmap = BitmapFactory.ConvertToPbgra32Format(BitmapSourceConvert.ToBitmapSource(res));
                DrawGrid(_bitmap);

                if (ZoomFactor > 1)
                {
                    double d = _bitmap.PixelWidth/(double) ZoomFactor;
                    double h = _bitmap.PixelHeight/(double) ZoomFactor;
                    _bitmap = _bitmap.Crop((int) (CentralPoint.X - (d/2)), (int) (CentralPoint.Y - (h/2)),
                        (int) d, (int) h);
                }

                _bitmap.Freeze();
                Bitmap = _bitmap;
            }

        }
コード例 #5
0
ファイル: Shader.cs プロジェクト: noxryan/Claro-Shader
 private static Bitmap changeHSL(Bitmap bmp, int h, double s, double l, bool keepBW, bool keepGray, int grayTolerance)
 {
     s = Math.Round(s / 100, 2);
     l = Math.Round(l / 100, 2);
     HueModifierRelative hue = new HueModifierRelative(h, keepBW);
     SaturationCorrection saturation = new SaturationCorrection(s, keepBW, keepGray, grayTolerance);
     BrightnessCorrection bright = new BrightnessCorrection(l, keepBW, keepGray, grayTolerance);
     hue.ApplyInPlace(bmp);
     saturation.ApplyInPlace(bmp);
     bright.ApplyInPlace(bmp);
     return bmp;
 }
コード例 #6
0
        public virtual void GetLiveImage()
        {
            if (_operInProgress)
                return;
            
            if (DelayedStart)
                return;

            _operInProgress = true;
            _totalframes++;
            if ((DateTime.Now - _framestart).TotalSeconds > 0)
                Fps = (int) (_totalframes/(DateTime.Now - _framestart).TotalSeconds);
            try
            {
                LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
            }
            catch (Exception)
            {
                _retries++;
                _operInProgress = false;
                return;
            }

            if (LiveViewData == null )
            {
                _retries++;
                _operInProgress = false;
                return;
            }

            if (!LiveViewData.IsLiveViewRunning)
            {
                DelayedStart = true;
                _restartTimerStartTime = DateTime.Now;
                _restartTimer. Start();
                _operInProgress = false;
                return;
            }

            if (LiveViewData.ImageData == null)
            {
                _retries++;
                _operInProgress = false;
                return;
            }

            Recording = LiveViewData.MovieIsRecording;
            try
            {
                WriteableBitmap preview;
                if (LiveViewData != null && LiveViewData.ImageData != null)
                {
                    MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                        LiveViewData.
                            ImageDataPosition,
                        LiveViewData.ImageData.
                            Length -
                        LiveViewData.
                            ImageDataPosition);

                    using (var res = new Bitmap(stream))
                    {
                        Bitmap bmp = res;
                        if (DetectMotion)
                        {
                            ProcessMotionDetection(bmp);
                        }

                        if (_totalframes % DesiredFrameRate == 0 && ShowHistogram)
                        {
                            ImageStatisticsHSL hslStatistics =
                                new ImageStatisticsHSL(bmp);
                            LuminanceHistogramPoints =
                                ConvertToPointCollection(
                                    hslStatistics.Luminance.Values);
                            ImageStatistics statistics = new ImageStatistics(bmp);
                            RedColorHistogramPoints = ConvertToPointCollection(
                                statistics.Red.Values);
                            GreenColorHistogramPoints = ConvertToPointCollection(
                                statistics.Green.Values);
                            BlueColorHistogramPoints = ConvertToPointCollection(
                                statistics.Blue.Values);
                        }

                        if (HighlightUnderExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(0, 5);
                            filtering.Red = new IntRange(0, 5);
                            filtering.Green = new IntRange(0, 5);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(System.Drawing.Color.Blue);
                            filtering.ApplyInPlace(bmp);
                        }

                        if (HighlightOverExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(250, 255);
                            filtering.Red = new IntRange(250, 255);
                            filtering.Green = new IntRange(250, 255);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(System.Drawing.Color.Red);
                            filtering.ApplyInPlace(bmp);
                        }

                        if (Brightness != 0)
                        {
                            BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                            bmp = filter.Apply(bmp);
                        }

                        preview =
                            BitmapFactory.ConvertToPbgra32Format(
                                BitmapSourceConvert.ToBitmapSource(bmp));
                        DrawFocusPoint(preview);
                        Bitmap newbmp = bmp;
                        if (EdgeDetection)
                        {
                            var filter = new FiltersSequence(
                                Grayscale.CommonAlgorithms.BT709,
                                new HomogenityEdgeDetector()
                                );
                            newbmp = filter.Apply(bmp);
                        }

                        WriteableBitmap writeableBitmap;

                        if (BlackAndWhite)
                        {
                            Grayscale filter = new Grayscale(0.299, 0.587, 0.114);
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(
                                        filter.Apply(newbmp)));
                        }
                        else
                        {
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(newbmp));
                        }
                        DrawGrid(writeableBitmap);
                        if (RotationIndex != 0)
                        {
                            switch (RotationIndex)
                            {
                                case 1:
                                    writeableBitmap = writeableBitmap.Rotate(90);
                                    break;
                                case 2:
                                    writeableBitmap = writeableBitmap.Rotate(180);
                                    break;
                                case 3:
                                    writeableBitmap = writeableBitmap.Rotate(270);
                                    break;
                                case 4:
                                    if (LiveViewData.Rotation != 0)
                                        writeableBitmap =
                                            writeableBitmap.RotateFree(
                                                LiveViewData.Rotation, false);
                                    break;
                            }
                        }
                        if (CameraDevice.LiveViewImageZoomRatio.Value == "All")
                        {
                            preview.Freeze();
                            Preview = preview;
                            if (ShowFocusRect)
                                DrawFocusPoint(writeableBitmap);
                        }

                        writeableBitmap.Freeze();
                        Bitmap = writeableBitmap;

                        if (_totalframes%DesiredWebFrameRate == 0)
                            ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(writeableBitmap);
                    }
                    stream.Close();
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                _retries++;
                _operInProgress = false;
            }
            _retries = 0;
            _operInProgress = false;
        }
コード例 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public GameLogic ScrapeBoardFromImage(Bitmap img)
        {
            // filter board's color to better identify tiles
            Blur blur = new Blur();
            blur.Threshold = 1;
            blur.ApplyInPlace(img);
            BrightnessCorrection brightness_filter = new BrightnessCorrection(-30);
            brightness_filter.ApplyInPlace(img);
            HSLFiltering luminance_filter = new HSLFiltering();
            luminance_filter.Luminance = new Range(0.50f, 1);
            luminance_filter.ApplyInPlace(img);
            img.Save("c:\\users\\breiche\\pictures\\filtered.bmp", ImageFormat.Bmp);

            DetectBlobsInImage(img);
            img.Save("c:\\users\\breiche\\pictures\\blobs.bmp", ImageFormat.Bmp);

            return new GameLogic(0, 0);
        }
コード例 #8
0
ファイル: Form1.cs プロジェクト: linuxbank/DocumentAnalysis
        // 밝기값 밝게 하기, 횟수 기록
        private void button32_Click(object sender, EventArgs e)
        {
            ///////////// ini 객체 생성 시작 /////////////////////////////////////////////////////
            //현재 프로그램이 실행되고 있는정보 가져오기: 디버깅 모드라면 bin/debug/프로그램명.exe
            FileInfo exefileinfo = new FileInfo(@"C:\Program Files\PLOCR\PLOCR.exe");
            string pathini = exefileinfo.Directory.FullName.ToString();  //프로그램 실행되고 있는데 path 가져오기
            string fileName = @"\PLOCRconfig.ini";  // 환경설정 파일명
            string filePath = pathini + fileName;   //ini 파일 경로
            DocumentAnalysis.IniUtil ini = new DocumentAnalysis.IniUtil(filePath);   // 만들어 놓았던 iniUtil 객체 생성(생성자 인자로 파일경로 정보 넘겨줌)
            //////////// ini 객체 생성 끝 /////////////////////////////////////////////////////////

            //Bitmap source = (Bitmap)pictureBox1.Image;

            Bitmap source = Global.source;

            // create filter
            BrightnessCorrection filter = new BrightnessCorrection(+10);
            // apply the filter
            filter.ApplyInPlace(source);

            Global.source = source;

            pictureBox1.Image = Global.source;
            pictureBox1.Invalidate();

            textBox22.Text = (int.Parse(textBox22.Text) + 1).ToString();
            ini.SetIniValue("밝기값", "밝게횟수", textBox22.Text.ToString());

            //string path = calculator.CreateFileCheck("C:\\Program Files\\PLOCR\\prescription.png");
            //pictureBox1.Image.Save(path);
        }
コード例 #9
0
ファイル: PictureView.cs プロジェクト: selfwalker/dicom
 internal void ReapplyFilters()
 {
     if (this.currentDicomElement != null)
     {
         Bitmap bmp = this.visibleImage.Clone() as Bitmap;
         if (!imageSettings.IsDefaultBrightness())
         {
             BrightnessCorrection filter = new BrightnessCorrection(imageSettings.Brightness);
             bmp = filter.Apply(bmp);
         }
         if (!imageSettings.IsDefaultContrast())
         {
             ContrastCorrection filter = new ContrastCorrection(imageSettings.Contrast);
             // apply filter
             bmp = filter.Apply(bmp);
         }
         previewBox.Image = bmp;
     }
 }
コード例 #10
0
ファイル: Home.xaml.cs プロジェクト: mezox/PhotoEditor
        private void Brightness_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            BrightnessLabel.Content = Brightness.Value;
            brightness = (int)Brightness.Value;

            if (mainPhoto != null)
            {
                bc = new BrightnessCorrection(brightness);
                System.Drawing.Bitmap tmp = bc.Apply((System.Drawing.Bitmap)mainPhoto.Clone());
                //BitmapImage tmpBmpIs = ToBitmapImage(tmp);

                Photography.Source = ToBitmapImage(tmp);

                UpdateHistograms(tmp);
                UpdateChannelPreviews(tmp);
            }
        }
コード例 #11
0
        public void ProcessLiveView(Bitmap bmp)
        {
            if (PreviewTime > 0 && (DateTime.Now - _photoCapturedTime).TotalSeconds <= PreviewTime)
            {
                var bitmap = ServiceProvider.Settings.SelectedBitmap.DisplayImage.Clone();
                // flip image only if the prview not fliped 
                if (FlipImage && !ServiceProvider.Settings.FlipPreview)
                    bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                bitmap.Freeze();
                ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(bitmap);
                Bitmap = bitmap;
                return;
            }
            if (DetectMotion)
            {
                ProcessMotionDetection(bmp);
            }

            if (_totalframes%DesiredFrameRate == 0 && ShowHistogram)
            {
                ImageStatisticsHSL hslStatistics =
                    new ImageStatisticsHSL(bmp);
                LuminanceHistogramPoints =
                    ConvertToPointCollection(
                        hslStatistics.Luminance.Values);
                ImageStatistics statistics = new ImageStatistics(bmp);
                RedColorHistogramPoints = ConvertToPointCollection(
                    statistics.Red.Values);
                GreenColorHistogramPoints = ConvertToPointCollection(
                    statistics.Green.Values);
                BlueColorHistogramPoints = ConvertToPointCollection(
                    statistics.Blue.Values);
            }

            if (HighlightUnderExp)
            {
                ColorFiltering filtering = new ColorFiltering();
                filtering.Blue = new IntRange(0, 5);
                filtering.Red = new IntRange(0, 5);
                filtering.Green = new IntRange(0, 5);
                filtering.FillOutsideRange = false;
                filtering.FillColor = new RGB(Color.Blue);
                filtering.ApplyInPlace(bmp);
            }

            if (HighlightOverExp)
            {
                ColorFiltering filtering = new ColorFiltering();
                filtering.Blue = new IntRange(250, 255);
                filtering.Red = new IntRange(250, 255);
                filtering.Green = new IntRange(250, 255);
                filtering.FillOutsideRange = false;
                filtering.FillColor = new RGB(Color.Red);
                filtering.ApplyInPlace(bmp);
            }

            var preview = BitmapFactory.ConvertToPbgra32Format(
                BitmapSourceConvert.ToBitmapSource(bmp));
            DrawFocusPoint(preview, true);

            if (Brightness != 0)
            {
                BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                bmp = filter.Apply(bmp);
            }


            Bitmap newbmp = bmp;
            if (EdgeDetection)
            {
                var filter = new FiltersSequence(
                    Grayscale.CommonAlgorithms.BT709,
                    new HomogenityEdgeDetector()
                    );
                newbmp = filter.Apply(bmp);
            }

            WriteableBitmap writeableBitmap;

            if (BlackAndWhite)
            {
                Grayscale filter = new Grayscale(0.299, 0.587, 0.114);
                writeableBitmap =
                    BitmapFactory.ConvertToPbgra32Format(
                        BitmapSourceConvert.ToBitmapSource(
                            filter.Apply(newbmp)));
            }
            else
            {
                writeableBitmap =
                    BitmapFactory.ConvertToPbgra32Format(
                        BitmapSourceConvert.ToBitmapSource(newbmp));
            }
            DrawGrid(writeableBitmap);
            switch (RotationIndex)
            {
                case 0:
                    Rotation = 0;
                    break;
                case 1:
                    Rotation = 90;
                    break;
                case 2:
                    Rotation = 180;
                    break;
                case 3:
                    Rotation = 270;
                    break;
                case 4:
                    Rotation = LiveViewData.Rotation;
                    break;
            }

            if (CameraDevice.LiveViewImageZoomRatio.Value == "All")
            {
                preview.Freeze();
                Preview = preview;
                if (ShowFocusRect)
                    DrawFocusPoint(writeableBitmap);
            }

            if (FlipImage)
            {
                writeableBitmap = writeableBitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
            }
            if (CropRatio > 0)
            {
                CropOffsetX = (int) ((writeableBitmap.PixelWidth/2.0)*CropRatio/100);
                CropOffsetY = (int) ((writeableBitmap.PixelHeight/2.0)*CropRatio/100);
                writeableBitmap = writeableBitmap.Crop(CropOffsetX, CropOffsetY,
                    writeableBitmap.PixelWidth - (2*CropOffsetX),
                    writeableBitmap.PixelHeight - (2*CropOffsetY));
            }
            writeableBitmap.Freeze();
            Bitmap = writeableBitmap;

            //if (_totalframes%DesiredWebFrameRate == 0)
            ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(writeableBitmap);
        }
コード例 #12
0
        private void GetLiveImage()
        {
            if (_operInProgress)
                return;

            try
            {
                LiveViewData = SelectedCameraDevice.GetLiveViewImage();
            }
            catch (Exception ex)
            {
                Log.Error("Error geting lv", ex);
                _operInProgress = false;
                return;
            }

            if (LiveViewData == null)
            {
                _operInProgress = false;
                return;
            }

            try
            {
                if (PreviewTime > 0 && (DateTime.Now - _photoCapturedTime).TotalSeconds <= PreviewTime)
                {
                    Bitmap = ServiceProvider.Settings.SelectedBitmap.DisplayImage;
                    _operInProgress = false;
                    Console.WriteLine("Previeving");
                    return;
                }

                if (LiveViewData != null && LiveViewData.ImageData != null)
                {
                    MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                        LiveViewData.
                            ImageDataPosition,
                        LiveViewData.ImageData.
                            Length -
                        LiveViewData.
                            ImageDataPosition);

                    LevelAngle = (int)LiveViewData.LevelAngleRolling;
                    AngleLevelPitching = LiveViewData.LevelAnglePitching;
                    AngleLevelYawing = LiveViewData.LevelAngleYawing;


                    using (var res = new Bitmap(stream))
                    {
                        Bitmap bmp = res;
                        if (_totalframes%DesiredFrameRate == 0 && ShowHistogram)
                        {
                            ImageStatisticsHSL hslStatistics =
                                new ImageStatisticsHSL(bmp);
                            LuminanceHistogramPoints =
                                ConvertToPointCollection(
                                    hslStatistics.Luminance.Values);
                            ImageStatistics statistics = new ImageStatistics(bmp);
                            RedColorHistogramPoints = ConvertToPointCollection(
                                statistics.Red.Values);
                            GreenColorHistogramPoints = ConvertToPointCollection(
                                statistics.Green.Values);
                            BlueColorHistogramPoints = ConvertToPointCollection(
                                statistics.Blue.Values);
                        }

                        if (HighlightUnderExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(0, 5);
                            filtering.Red = new IntRange(0, 5);
                            filtering.Green = new IntRange(0, 5);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(System.Drawing.Color.Blue);
                            filtering.ApplyInPlace(bmp);
                        }

                        if (HighlightOverExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(250, 255);
                            filtering.Red = new IntRange(250, 255);
                            filtering.Green = new IntRange(250, 255);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(System.Drawing.Color.Red);
                            filtering.ApplyInPlace(bmp);
                        }

                        var preview = BitmapFactory.ConvertToPbgra32Format(
                            BitmapSourceConvert.ToBitmapSource(bmp));

                        if (Brightness != 0)
                        {
                            BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                            bmp = filter.Apply(bmp);
                        }


                        Bitmap newbmp = bmp;
                        if (EdgeDetection)
                        {
                            var filter = new FiltersSequence(
                                Grayscale.CommonAlgorithms.BT709,
                                new HomogenityEdgeDetector()
                                );
                            newbmp = filter.Apply(bmp);
                        }

                        WriteableBitmap writeableBitmap;

                        if (BlackAndWhite)
                        {
                            Grayscale filter = new Grayscale(0.299, 0.587, 0.114);
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(
                                        filter.Apply(newbmp)));
                        }
                        else
                        {
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(newbmp));
                        }
                        DrawGrid(writeableBitmap);
                        DrawFocusPoint(writeableBitmap);
                        writeableBitmap.Freeze();
                        Bitmap = writeableBitmap;
                        _operInProgress = false;
                    }
                    return;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error geting lv", ex);
                _operInProgress = false;
                return;
            }
        }
コード例 #13
0
ファイル: ImageFunctions.cs プロジェクト: ppucik/DOZP
        public static bool ColorCorrections(string fileName, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (String.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");

            bool result = false;

            using (var ms = new MemoryStream(File.ReadAllBytes(fileName)))
            {
                using (Bitmap bmp = new Bitmap(ms))
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                        result = true;
                    }

                    bmp.Save(fileName);
                }
            }

            return result;
        }
コード例 #14
0
ファイル: ImageFunctions.cs プロジェクト: ppucik/DOZP
        public static BitmapSource ColorCorrections(BitmapSource source, int brightness, int contrast, double gamma, int hue, float saturation)
        {
            if (source == null) throw new ArgumentNullException("source");

            BitmapSource output = null;

            if (source.Format == PixelFormats.Bgr32 && gamma != 1D)
            {
                source = new FormatConvertedBitmap(source, PixelFormats.Bgr24, null, 0);
            }

            using (Bitmap bmp = Convert(source))
            {
                int bpp = source.Format.BitsPerPixel;

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-255, +255] default 10
                    if (brightness >= -255 && brightness != 0 && brightness <= 255)
                    {
                        BrightnessCorrection filter = new BrightnessCorrection(brightness);
                        filter.ApplyInPlace(bmp);
                    }

                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-127, +127] default 10
                    if (contrast >= -127 && contrast != 0 && contrast <= 127)
                    {
                        ContrastCorrection filter = new ContrastCorrection(contrast);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24)
                {
                    //The filter accepts 8 bpp grayscale and 24 bpp color images for processing, value [0.1, 5.0] default 1.0
                    if (gamma >= 0.1D && gamma != 1D && gamma <= 5D)
                    {
                        GammaCorrection filter = new GammaCorrection(gamma);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 8 || bpp == 24 || bpp == 32)
                {
                    //The filter accepts 8 bpp grayscale and 24/32 bpp color images for processing, value [-180, +180] default 0
                    if (hue >= -180 && hue != 0 && hue <= 180)
                    {
                        HueModifier filter = new HueModifier(hue);
                        filter.ApplyInPlace(bmp);
                    }
                }

                if (bpp == 24 || bpp == 32)
                {
                    //The filter accepts 24 and 32 bpp color images for processing, value specified percentage [-1, +1] default 0.1
                    if (saturation >= -100f && saturation != 0f && saturation <= 100f)
                    {
                        SaturationCorrection filter = new SaturationCorrection(saturation / 100);
                        filter.ApplyInPlace(bmp);
                    }
                }

                output = Convert(bmp);
            }

            return CloneImage(output);
        }
コード例 #15
0
        public virtual void GetLiveImage()
        {
            if (_operInProgress)
            {
               // Log.Error("OperInProgress");
                return;
            }

            if (DelayedStart)
            {
                //Log.Error("Start is delayed");
                return;
            }

            if (FreezeImage)
                return;

            _operInProgress = true;
            _totalframes++;
            if ((DateTime.Now - _framestart).TotalSeconds > 0)
                Fps = (int)(_totalframes / (DateTime.Now - _framestart).TotalSeconds);
            try
            {
                LiveViewData = LiveViewManager.GetLiveViewImage(CameraDevice);
            }
            catch (Exception ex)
            {
                Log.Error("Error geting lv", ex);
                _operInProgress = false;
                return;
            }

            if (LiveViewData == null)
            {
                _operInProgress = false;
                return;
            }

            if (!LiveViewData.IsLiveViewRunning && !IsFocusStackingRunning)
            {
                DelayedStart = true;
                _restartTimerStartTime = DateTime.Now;
                _restartTimer.Start();
                _operInProgress = false;
                return;
            }

            if (LiveViewData.ImageData == null)
            {
               // Log.Error("LV image data is null !");
                _operInProgress = false;
                return;
            }

            Recording = LiveViewData.MovieIsRecording;
            try
            {
                if (LiveViewData != null && LiveViewData.ImageData != null)
                {
                    MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                        LiveViewData.
                            ImageDataPosition,
                        LiveViewData.ImageData.
                            Length -
                        LiveViewData.
                            ImageDataPosition);
                    LevelAngle = (int)LiveViewData.LevelAngleRolling;
                    SoundL = LiveViewData.SoundL;
                    SoundR = LiveViewData.SoundR;
                    PeakSoundL = LiveViewData.PeakSoundL;
                    PeakSoundR = LiveViewData.PeakSoundR;
                    HaveSoundData = LiveViewData.HaveSoundData;
                    MovieTimeRemain = decimal.Round(LiveViewData.MovieTimeRemain, 2);

                    if (NoProcessing)
                    {
                        BitmapImage bi = new BitmapImage();
                        bi.BeginInit();
                        bi.CacheOption = BitmapCacheOption.OnLoad;
                        bi.StreamSource = stream;
                        bi.EndInit();
                        bi.Freeze();
                        Bitmap = bi;
                        ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = stream.ToArray();
                        _operInProgress = false;
                        return;
                    }

                    using (var res = new Bitmap(stream))
                    {
                        Bitmap bmp = res;
                        if (PreviewTime > 0 && (DateTime.Now - _photoCapturedTime).TotalSeconds <= PreviewTime)
                        {
                            var bitmap = ServiceProvider.Settings.SelectedBitmap.DisplayImage.Clone();
                            //var dw = (double)bmp.Width / bitmap.PixelWidth;
                            //bitmap = bitmap.Resize((int)(bitmap.PixelWidth * dw), (int)(bitmap.PixelHeight * dw),
                            //    WriteableBitmapExtensions.Interpolation.NearestNeighbor);
                            // flip image only if the prview not fliped
                            if (FlipImage && !ServiceProvider.Settings.FlipPreview)
                                bitmap = bitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                            bitmap.Freeze();
                            ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(bitmap);
                            Bitmap = bitmap;
                            return;
                        }
                        if (DetectMotion)
                        {
                            ProcessMotionDetection(bmp);
                        }

                        if (_totalframes % DesiredFrameRate == 0 && ShowHistogram)
                        {
                            ImageStatisticsHSL hslStatistics =
                                new ImageStatisticsHSL(bmp);
                            LuminanceHistogramPoints =
                                ConvertToPointCollection(
                                    hslStatistics.Luminance.Values);
                            ImageStatistics statistics = new ImageStatistics(bmp);
                            RedColorHistogramPoints = ConvertToPointCollection(
                                statistics.Red.Values);
                            GreenColorHistogramPoints = ConvertToPointCollection(
                                statistics.Green.Values);
                            BlueColorHistogramPoints = ConvertToPointCollection(
                                statistics.Blue.Values);
                        }

                        if (HighlightUnderExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(0, 5);
                            filtering.Red = new IntRange(0, 5);
                            filtering.Green = new IntRange(0, 5);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(Color.Blue);
                            filtering.ApplyInPlace(bmp);
                        }

                        if (HighlightOverExp)
                        {
                            ColorFiltering filtering = new ColorFiltering();
                            filtering.Blue = new IntRange(250, 255);
                            filtering.Red = new IntRange(250, 255);
                            filtering.Green = new IntRange(250, 255);
                            filtering.FillOutsideRange = false;
                            filtering.FillColor = new RGB(Color.Red);
                            filtering.ApplyInPlace(bmp);
                        }

                        var preview = BitmapFactory.ConvertToPbgra32Format(
                            BitmapSourceConvert.ToBitmapSource(bmp));
                        DrawFocusPoint(preview, true);

                        if (Brightness != 0)
                        {
                            BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                            bmp = filter.Apply(bmp);
                        }

                        Bitmap newbmp = bmp;
                        if (EdgeDetection)
                        {
                            var filter = new FiltersSequence(
                                Grayscale.CommonAlgorithms.BT709,
                                new HomogenityEdgeDetector()
                                );
                            newbmp = filter.Apply(bmp);
                        }

                        WriteableBitmap writeableBitmap;

                        if (BlackAndWhite)
                        {
                            Grayscale filter = new Grayscale(0.299, 0.587, 0.114);
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(
                                        filter.Apply(newbmp)));
                        }
                        else
                        {
                            writeableBitmap =
                                BitmapFactory.ConvertToPbgra32Format(
                                    BitmapSourceConvert.ToBitmapSource(newbmp));
                        }
                        DrawGrid(writeableBitmap);
                        switch (RotationIndex)
                        {
                            case 0:
                                Rotation = 0;
                                break;
                            case 1:
                                Rotation = 90;
                                break;
                            case 2:
                                Rotation = 180;
                                break;
                            case 3:
                                Rotation = 270;
                                break;
                            case 4:
                                Rotation = LiveViewData.Rotation;
                                break;
                        }

                        if (CameraDevice.LiveViewImageZoomRatio.Value == "All")
                        {
                            preview.Freeze();
                            Preview = preview;
                            if (ShowFocusRect)
                                DrawFocusPoint(writeableBitmap);
                        }

                        if (FlipImage)
                        {
                            writeableBitmap = writeableBitmap.Flip(WriteableBitmapExtensions.FlipMode.Vertical);
                        }
                        if (CropRatio > 0)
                        {
                            CropOffsetX = (int) ((writeableBitmap.PixelWidth/2.0)*CropRatio/100);
                            CropOffsetY = (int) ((writeableBitmap.PixelHeight/2.0)*CropRatio/100);
                            writeableBitmap = writeableBitmap.Crop(CropOffsetX, CropOffsetY,
                                writeableBitmap.PixelWidth - (2*CropOffsetX),
                                writeableBitmap.PixelHeight - (2*CropOffsetY));
                        }
                        writeableBitmap.Freeze();
                        Bitmap = writeableBitmap;

                        //if (_totalframes%DesiredWebFrameRate == 0)
                        ServiceProvider.DeviceManager.LiveViewImage[CameraDevice] = SaveJpeg(writeableBitmap);
                    }
                    stream.Close();
                }
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                _operInProgress = false;
            }
            finally
            {
                _operInProgress = false;
            }
            _operInProgress = false;
        }
コード例 #16
0
 internal void Lightness(int p)
 {
     if (!this.HasImage)
       {
     return;
       }
       brightnessAdjValue += p * 5;
       //brightnessAdjValue = brightnessAdjValue > 1 ? 1 : brightnessAdjValue;
       //brightnessAdjValue = brightnessAdjValue < -1 ? -1 : brightnessAdjValue;
       //BrightnessCorrection
       Console.WriteLine("brightnessAdjValue->" + brightnessAdjValue);
       BrightnessCorrection bc = new BrightnessCorrection(brightnessAdjValue);
       currentImageHandler.ColorFitler.ExecuteFitler(bc);
 }
コード例 #17
0
        /// <summary>
        /// Modifica el brillo y contraste de la imagen que aparece en pantalla
        /// </summary>
        private void Filtrar()
        {
            Bitmap temp = new Bitmap(padre.actual.datacuboHigh.dataCube[trackElementos.Value - 1].bmp);

            AForge.Imaging.Filters.BrightnessCorrection brillo = new AForge.Imaging.Filters.BrightnessCorrection(Convert.ToInt32(trackBrillo.Value));
            AForge.Imaging.Filters.ContrastCorrection contraste = new AForge.Imaging.Filters.ContrastCorrection(Convert.ToInt32(trackContraste.Value));

            contraste.ApplyInPlace(temp);
            brillo.ApplyInPlace(temp);

            pictElemento.Image = temp;

            //pictElemento.Invalidate();
        }
コード例 #18
0
        private void DisplayLiveView()
        {
            if (LiveViewData == null || LiveViewData.ImageData == null)
                return;
            MemoryStream stream = new MemoryStream(LiveViewData.ImageData,
                                                   LiveViewData.ImageDataPosition,
                                                   LiveViewData.ImageData.Length -
                                                   LiveViewData.ImageDataPosition);
            using (var bmp = new Bitmap(stream))
            {
                Bitmap res = bmp;
                if (Brightness != 0)
                {
                    BrightnessCorrection filter = new BrightnessCorrection(Brightness);
                    res = filter.Apply(res);
                }

                DisplayBitmap = BitmapFactory.ConvertToPbgra32Format(BitmapSourceConvert.ToBitmapSource(res));
                DrawGrid(DisplayBitmap);
                DisplayBitmap.Freeze();
                live_view_image.Source = DisplayBitmap;
            }
        }
コード例 #19
0
ファイル: Form1.cs プロジェクト: dshakaa2/old-projects
        private void ReadAndDisplayDicomFile(string fileName, string fileNameOnly)
        {
            dd.DicomFileName = fileName;
            bool result = dd.dicomFileReadSuccess;

            if (result == true)
            {
                imageWidth  = dd.width;
                imageHeight = dd.height;
                bitDepth    = dd.bitsAllocated;
                winCentre   = dd.windowCentre;
                winWidth    = dd.windowWidth;


                StatusLabel1.Text  = fileName + ": " + imageWidth.ToString() + " X " + imageHeight.ToString();
                StatusLabel1.Text += "  " + bitDepth.ToString() + " bits per pixel";

                userControl11.NewImage = true;
                Text = "DICOM Image Viewer: " + fileNameOnly;


                if (bitDepth == 16)
                {
                    pixels16.Clear();
                    pixels8.Clear();
                    dd.GetPixels16(ref pixels16);
                    byte[]        buffer = new byte[pixels16.Count * 2];
                    byte[]        temp;
                    ByteConverter d = new ByteConverter();
                    int           j = 0;
                    for (int i = 0; i < pixels16.Count; i++)
                    {
                        temp        = System.BitConverter.GetBytes(pixels16[i]);
                        buffer[j++] = temp[0];
                        buffer[j++] = temp[1];
                    }

                    if (winCentre == 0 && winWidth == 0)
                    {
                        winWidth  = 4095;
                        winCentre = 4095 / 2;
                    }
                    string index = "";
                    foreach (string s in dd.dicomInfo)
                    {
                        if (s.Contains("Image Number"))
                        {
                            index = s;
                        }
                    }



                    userControl11.SetParameters(ref pixels16, imageWidth, imageHeight, winWidth, winCentre, true, this);


                    if (processI && int.Parse(index.Split(':')[1]) > 9)
                    {
                        AForge.Imaging.Filters.Grayscale            g1 = new Grayscale(0.2125, 0.7154, 0.0721);
                        AForge.Imaging.Filters.BrightnessCorrection bC = new AForge.Imaging.Filters.BrightnessCorrection(brightness);
                        bC.ApplyInPlace(userControl11.bmp);
                        Bitmap image = g1.Apply(userControl11.bmp);
                        thresholding = (int)((dd.windowWidth - dd.windowCentre) * 255 / dd.windowWidth) - trackBar2.Value;
                        label1.Text  = thresholding.ToString();
                        AForge.Imaging.Filters.Threshold thf = new AForge.Imaging.Filters.Threshold(thresholding);
                        Bitmap          ther        = thf.Apply(image);
                        BlobCounter     blobCounter = new BlobCounter(ther);
                        Blob[]          blobs       = blobCounter.GetObjects(ther, false);
                        ImageStatistics img;
                        AForge.Imaging.Filters.GrayscaleToRGB d1 = new GrayscaleToRGB();
                        Bitmap   bm      = d1.Apply(image);
                        Edges    s       = new Edges();
                        Graphics gg      = Graphics.FromImage(bm);
                        string   ss      = null;
                        Bitmap   myImage = null;
                        Blob     b;
                        int      count = 0;
                        listView1.Items.Clear();
                        mylesions.Clear();
                        Crop   cut;
                        Bitmap Ilesion = null;

                        //System.Threading.Tasks.Parallel.ForEach(blobs, blob =>
                        foreach (Blob blob in blobs)
                        {
                            img = new ImageStatistics(blob.Image);
                            double perc = ((double)img.PixelsCountWithoutBlack / (double)img.PixelsCount) * 100;
                            textBox2.Text = perc.ToString();
                            if (blob.Image.Size.Height > 20 && blob.Image.Size.Width > 20 && perc > 35)
                            {
                                b       = blob;
                                cut     = new Crop(b.Rectangle);
                                Ilesion = g1.Apply(cut.Apply(userControl11.bmp));

                                ImageStatistics st = new ImageStatistics(b.Image);

                                Bitmap           pp = s.Apply(b.Image);
                                ChannelFiltering c  = new ChannelFiltering(new IntRange(0, 255), new IntRange(0, 0), new IntRange(0, 0));

                                Bitmap pp2 = d1.Apply(pp);
                                c.ApplyInPlace(pp2);

                                pp2.MakeTransparent(Color.Black);



                                gg.DrawImage(pp2, b.Rectangle);
                                gg.Flush();

                                myImage = userControl11.bmp.Clone(b.Rectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                                ss = ((double)(st.PixelsCountWithoutBlack) * (double)dd.pixelHeight * dd.pixelWidth).ToString();
                                ListViewItem lv = new ListViewItem(count.ToString());
                                lv.SubItems.Add(ss);
                                lv.SubItems.Add(b.Rectangle.Location.X.ToString() + "," + b.Rectangle.Location.Y.ToString());
                                listView1.Items.Add(lv);

                                Add    adder    = new Add(pp);
                                Bitmap undashes = (Bitmap)Ilesion.Clone();
                                adder.ApplyInPlace(Ilesion);
                                string locc = (b.Rectangle.Location.X * dd.pixelWidth).ToString() + "mm," + (b.Rectangle.Location.Y * dd.pixelHeight).ToString() + "mm";
                                mylesions.Add(new lesion((Bitmap)Ilesion.Clone(), ss, b.Rectangle.Location, locc, undashes));

                                count++;
                            }
                        }
                        textBox1.Text = "tumor size= " + ss + " mm² *" + dd.pixelDepth.ToString() + "mm";

                        // host.NewDocument(bmp);

                        // pictureBox2.Image = myImage;
                        pictureBox1.Image = bm;
                        pictureBox2.Image = Ilesion;
                    }
                    else
                    {
                        pictureBox1.Image = userControl11.bmp;
                    }
                    pictureBox1.Invalidate();
                }

                //userControl11.increasecontrast(200);
            }
            else
            {
                if (dd.dicmFound == false)
                {
                    MessageBox.Show("This does not seem to be a DICOM 3.0 file. Sorry, I can't open this.");
                }
                else if (dd.dicomDir == true)
                {
                    MessageBox.Show("This seems to be a DICOMDIR file, and does not contain an image.");
                }
                else
                {
                    MessageBox.Show("Sorry, I can't read a DICOM file with this Transfer Syntax\n" +
                                    "You may view the initial tags instead.");
                }



                //userControl11.SetParameters(ref pixels8, imageWidth, imageHeight,
                //    winWidth, winCentre, true, this);
            }
        }