コード例 #1
0
ファイル: Enhance.cs プロジェクト: avencherus/digiCamControl
 public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
 {
     var conf = new EnhanceViewModel(configData);
     dest = Path.Combine(Path.GetDirectoryName(dest), Path.GetFileNameWithoutExtension(dest) + ".jpg");
     using (MagickImage image = new MagickImage(infile))
     {
         if (conf.Normalize)
             image.Normalize();
         if (conf.AutoGamma)
             image.AutoGamma();
         image.BrightnessContrast(new Percentage(conf.Brightness), new Percentage(conf.Contrast));
         if (conf.SContrast > 0)
             image.SigmoidalContrast(true, conf.SContrast);
         if (conf.Edge)
             image.AdaptiveSharpen();
         if (conf.Sharpen > 0)
             image.Unsharpmask(1.5, 1.5, conf.Sharpen/100.0, 0.2);
         image.Format = MagickFormat.Jpeg;
         image.Write(dest);
     }
     return dest;
 }
コード例 #2
0
        public void GenerateCache(FileItem fileItem)
        {
            bool deleteFile = false;
            if (fileItem == null)
                return;
            if (!File.Exists(fileItem.FileName))
                return;

            if ((File.Exists(fileItem.LargeThumb) && File.Exists(fileItem.SmallThumb)) && File.Exists(fileItem.InfoFile))
                return;

            if (fileItem.Loading)
                return;

            fileItem.Loading = true;

            PhotoUtils.WaitForFile(fileItem.FileName);
            string filename = fileItem.FileName;
            if (fileItem.IsMovie)
            {
                try
                {
                    string ffmpeg_exe = Path.Combine(Settings.ApplicationFolder, "ffmpeg.exe");
                    if (File.Exists(ffmpeg_exe))
                    {
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        PhotoUtils.RunAndWait(ffmpeg_exe, String.Format("-i \"{0}\" -ss 00:00:01.000 -f image2 -vframes 1 \"{1}\"", fileItem.FileName, thumb));
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get video thumb", exception);
                }
            }
            if (fileItem.IsRaw)
            {
                try
                {
                    string dcraw_exe = Path.Combine(Settings.ApplicationFolder, "dcraw.exe");
                    if (File.Exists(dcraw_exe))
                    {
                        PhotoUtils.RunAndWait(dcraw_exe, string.Format(" -e \"{0}\"", fileItem.FileName));
                        string thumb = Path.Combine(Path.GetDirectoryName(fileItem.FileName),
                            Path.GetFileNameWithoutExtension(fileItem.FileName) + ".thumb.jpg");
                        if (File.Exists(thumb))
                        {
                            deleteFile = true;
                            filename = thumb;
                        }
                    }
                }
                catch (Exception exception)
                {
                    Log.Error("Error get dcraw thumb", exception);
                }
            }

            GetMetadata(fileItem);
            try
            {
                using (MagickImage image = new MagickImage(filename))
                {
                    fileItem.FileInfo.SetSize(image.Width, image.Height);

                    double dw = (double)LargeThumbSize / image.Width;
                    image.FilterType = FilterType.Box;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));
                    image.Unsharpmask(1, 1, 0.5, 0.1);
                    PhotoUtils.CreateFolder(fileItem.LargeThumb);
                    image.Write(fileItem.LargeThumb);
                    fileItem.IsLoaded = true;
                    fileItem.Loading = false;

                    dw = (double)SmallThumbSize / image.Width;
                    image.Thumbnail((int)(image.Width * dw), (int)(image.Height * dw));
                    image.Unsharpmask(1, 1, 0.5, 0.1);
                    PhotoUtils.CreateFolder(fileItem.SmallThumb);
                    image.Write(fileItem.SmallThumb);

                    fileItem.Thumbnail = LoadImage(fileItem.SmallThumb);
                }
                fileItem.SaveInfo();
                SetImageInfo(fileItem);
                if (deleteFile)
                    File.Delete(filename);
                OnMetaDataUpdated(fileItem);
            }
            catch (Exception exception)
            {
                Log.Error("Error generating cache " + fileItem.FileName, exception);
            }
            fileItem.Loading = false;
        }
コード例 #3
0
ファイル: MagickImage.cs プロジェクト: levesque/Magick.NET
 private void ExecuteUnsharpmask(XmlElement element, MagickImage image)
 {
   Hashtable arguments = new Hashtable();
   foreach (XmlAttribute attribute in element.Attributes)
   {
     if (attribute.Name == "amount")
       arguments["amount"] = Variables.GetValue<double>(attribute);
     else if (attribute.Name == "channels")
       arguments["channels"] = Variables.GetValue<Channels>(attribute);
     else if (attribute.Name == "radius")
       arguments["radius"] = Variables.GetValue<double>(attribute);
     else if (attribute.Name == "sigma")
       arguments["sigma"] = Variables.GetValue<double>(attribute);
     else if (attribute.Name == "threshold")
       arguments["threshold"] = Variables.GetValue<double>(attribute);
   }
   if (OnlyContains(arguments, "radius", "sigma"))
     image.Unsharpmask((double)arguments["radius"], (double)arguments["sigma"]);
   else if (OnlyContains(arguments, "radius", "sigma", "amount", "threshold"))
     image.Unsharpmask((double)arguments["radius"], (double)arguments["sigma"], (double)arguments["amount"], (double)arguments["threshold"]);
   else if (OnlyContains(arguments, "radius", "sigma", "amount", "threshold", "channels"))
     image.Unsharpmask((double)arguments["radius"], (double)arguments["sigma"], (double)arguments["amount"], (double)arguments["threshold"], (Channels)arguments["channels"]);
   else if (OnlyContains(arguments, "radius", "sigma", "channels"))
     image.Unsharpmask((double)arguments["radius"], (double)arguments["sigma"], (Channels)arguments["channels"]);
   else
     throw new ArgumentException("Invalid argument combination for 'unsharpmask', allowed combinations are: [radius, sigma] [radius, sigma, amount, threshold] [radius, sigma, amount, threshold, channels] [radius, sigma, channels]");
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: dynamicdeploy/ReceiptOCR
        private Bitmap processImgForScanning(Bitmap imgInput)
        {
            using (MemoryStream memstream = new MemoryStream())
            {
                imgInput.Save(memstream, ImageFormat.Tiff);
                MagickImage img = new MagickImage(memstream.ToArray());

                if (sharpen)
                {
                    img.Sharpen((int)sharpenIntX.Value, (int)sharpenIntY.Value, Channels.All);
                }

                if (autoGamma)
                {
                    img.AutoGamma();
                }

                if (enhance)
                {
                    img.Enhance();
                }

                if (contrast)
                {
                    img.Contrast();
                }

                if (autoLevel)
                {
                    img.AutoLevel();
                }

                if (autoOrient)
                {
                    img.AutoOrient();
                }

                if (despeckle)
                {
                    img.Despeckle();
                }

                if (medianFilter)
                {
                    img.MedianFilter((int)medianInt.Value);
                }

                if (unsharpmask)
                {
                    img.Unsharpmask(6.8, 4, 4,0);
                }

                if (wtThreshold)
                {
                    img.LinearStretch((float)0.9, 0.1);
                    //img.WhiteThreshold((int)wtThresInt.Value);
                    //img.ReduceNoise();
                    //img.Grayscale(PixelIntensityMethod.Brightness);
                }

                if (invert)
                {
                    img.Negate();
                }

                return img.ToBitmap();
            }
        }