コード例 #1
0
ファイル: Tracker.cs プロジェクト: djjosse/Foosbot
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="imagingData">Common Use Imaging Data</param>
 /// <param name="preprocessor">Image Preprocessor Unit [Default is nu will be created]</param>
 /// <param name="motionInspector">Motion Detection Unit [Default is nu will be created]</param>
 public Tracker(IImageData imagingData, IImagePreparation preprocessor = null, IMotionDetector motionInspector = null)
 {
     ComputerVisionMonitors = new Dictionary<eComputerVisionMonitor, IComputerVisionMonitor>();
     ImagingData = imagingData;
     MotionInspector = motionInspector ?? new MotionDetector(ImagingData);
     PreProcessor = preprocessor ?? new ImagePreProcessor();
 }
コード例 #2
0
ファイル: BallTracker.cs プロジェクト: djjosse/Foosbot
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="imagingData">Common imaging data for all Image Processing Unit</param>
 /// <param name="streamer">Frame Streamer used to check if we received new frames</param>
 /// <param name="preprocessor">Image Preparation unit [default is null - will be created]</param>
 /// <param name="motionInspector">Motion Detection unit [default is null - will be created</param>
 public BallTracker(IImageData imagingData, FramePublisher streamer, IImagePreparation preprocessor = null, IMotionDetector motionInspector = null)
     : base(imagingData, preprocessor, motionInspector)
 {
     _streamer = streamer;
     CannyThreshold = DEFAULT_CANNY_THRESHOLD;
     CircleAccumulator = DEFAULT_CIRCLE_ACCUMULATOR_THRESHOLD;
     InverseRatio = DEFAULT_INVERSE_RATIO;
 }
コード例 #3
0
 private void Configure(IImageData baseImage)
 {
     _bufferRectangle = new Rectangle(0, 0, baseImage.Width, baseImage.Height);
     _bufferExtent = baseImage.Bounds.Extent;
     base.IsVisible = true;
     MyExtent = baseImage.Extent;
     base.LegendText = Path.GetFileName(baseImage.Filename);
     OnFinishedLoading();
 }
コード例 #4
0
ファイル: ImagingProcess.cs プロジェクト: djjosse/Foosbot
        /// <summary>
        /// Constructor for abstract image processing unit
        /// </summary>
        /// <param name="streamer">Publisher to get frames from</param>
        /// <param name="imagingData">Imaging Data [default is null - will be created inside this class]</param>
        public ImagingProcess(FramePublisher streamer, IImageData imagingData = null) : base(streamer) 
        {
            ImagingData = (imagingData != null) ? imagingData : new ImageData();
            BallLocationUpdater = new BallPublisher(ImagingData);

            //create computer vision monitor to display image processing data
            ImageProcessingMonitorA = new ComputerVisionFramesPublisher();
            ImageProcessingMonitorB = new ComputerVisionFramesPublisher();
            ImageProcessingMonitorC = new ComputerVisionFramesPublisher();
            ImageProcessingMonitorD = new ComputerVisionFramesPublisher();
        }
コード例 #5
0
    /// <summary>
    /// Generates a grayscale depthmap with a given alpha, by converting the iisu image to a Unity Texture2D.
    /// </summary>
    public bool generateDepthMap(IImageData image, ref Texture2D destinationImage,float alpha)
    {
        if(image == null)
            return false;

        if (image.Raw == IntPtr.Zero)
            return false;

        if (_colored_image == null || _colored_image.Length != image.ImageInfos.BytesRaw / 2)
        {
            _colored_image = new Color[_width*_height];
            imageRaw = new byte[image.ImageInfos.BytesRaw];
        }

        uint byte_size = (uint)image.ImageInfos.BytesRaw;

        // copy image content into managed array
        Marshal.Copy(image.Raw, imageRaw, 0, (int)byte_size);

        int destinationU, destinationV;
        int sourceU, sourceV;
        int sourceIndex;

        int imageWidth = (int)image.ImageInfos.Width;
        int imageHeight = (int)image.ImageInfos.Height;

        //build op the Unity Texture2D
        for(int destinationIndex = 0; destinationIndex<_colored_image.Length; ++destinationIndex)
        {
            //get the UV coordinates of the destination texture
            getUV(destinationIndex, _width, _height, out destinationU, out destinationV);

            //get the UV coordinates from the original iisu image, remapped to the destination textures widh and height
            getUVEquivalent(_width, _height, destinationU, destinationV, imageWidth, imageHeight, out sourceU, out sourceV, out sourceIndex);

            // reconstruct ushort value from 2 bytes (low indian)
            ushort value = (ushort)(imageRaw[sourceIndex * 2] + (imageRaw[sourceIndex * 2 + 1] << 8));

            //normalize depth value in millimeter so that 5m <-> color 255
            value = (ushort)(value * 255/(5000));
            if (value > 255) value = 255;

            //apply a grayscale color indicating the depth to the current pixel
            _colored_image[destinationIndex].r = value * floatConvertor;
            _colored_image[destinationIndex].g = value * floatConvertor;
            _colored_image[destinationIndex].b = value * floatConvertor;
            _colored_image[destinationIndex].a = alpha;
        }

        destinationImage.SetPixels(_colored_image);
        destinationImage.Apply();

        return true;
    }
コード例 #6
0
 private void Configure(IImageData baseImage)
 {
     
     _baseImage = baseImage;
     _bufferRectangle = new Rectangle(0, 0, _baseImage.Width, _baseImage.Height);
     RasterBounds rb = _baseImage.Bounds;
     _bufferExtent = _baseImage.Bounds.Envelope.Copy();
     base.IsVisible = true;
     Envelope = _baseImage.Bounds.Envelope;
     base.LegendText = System.IO.Path.GetFileName(baseImage.Filename);
     OnFinishedLoading();
 }
コード例 #7
0
 /// <summary>
 /// Export data from an image layer.
 /// </summary>
 /// <param name="e"></param>
 public void ExportData(IImageData e)
 {
     using (var sfd = new SaveFileDialog
         {
             Filter = DataManager.DefaultDataManager.RasterWriteFilter
         })
     {
         if (ShowDialog(sfd) == DialogResult.OK)
         {
             e.SaveAs(sfd.FileName);
         }
     }
 }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapImageLayer"/> class.
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer.</param>
 /// <param name="container">The Layers collection that keeps track of the image layer.</param>
 public MapImageLayer(IImageData baseImage, ICollection <ILayer> container)
     : base(baseImage, container)
 {
 }
コード例 #9
0
 internal MagickScriptHandler(MagickWebSettings settings, IImageData imageData, IScriptData scriptResolver)
     : base(settings, imageData)
 {
     _ScriptResolver = scriptResolver;
 }
コード例 #10
0
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public MapImageLayer(IImageData baseImage)
     : base(baseImage)
 {
     Configure(baseImage);
 }
コード例 #11
0
ファイル: Canvas.cs プロジェクト: freethenation/OpenGL-Canvas
 public void PutImageData(IImageData imagedata, float dx, float dy)
 {
     throw new System.NotImplementedException();
 }
コード例 #12
0
 public override bool TryGetThumbnail(ThumbnailDescriptor descriptor, Size size, out IImageData thumbnail)
 {
     thumbnail = null;
     return false;
 }
コード例 #13
0
ファイル: ImageData.cs プロジェクト: ExRam/DotSpatial-PCL
 /// <summary>
 /// Copies the values from the specified source image.
 /// </summary>
 /// <param name="source">The source image to copy values from.</param>
 public virtual void CopyValues(IImageData source)
 {
 }
コード例 #14
0
        private void Test_ProcessRequest(IImageData imageData)
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                string tempDir = directory.FullName;

                string config = $@"<magick.net.web cacheDirectory=""{tempDir}"" tempDirectory=""{tempDir}"" useOpenCL=""true""/>";

                MagickWebSettings settings = TestSectionLoader.Load(config);

                HttpRequest request = new HttpRequest("foo", "https://bar", string.Empty);

                string outputFile = Path.Combine(tempDir, "output");

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                Assert.AreEqual(0, new FileInfo(outputFile).Length);
                Assert.AreEqual(1, tempDir.GetFiles().Count());

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    request.SetHeaders("Accept-Encoding", "invalid");
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                Assert.AreEqual(0, new FileInfo(outputFile).Length);
                Assert.AreEqual(1, tempDir.GetFiles().Count());

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    request.SetHeaders("Accept-Encoding", "gzip");
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                byte[] imageBytes = imageData.GetBytes();
                Assert.IsTrue(new FileInfo(outputFile).Length < imageBytes.Length);
                Assert.AreEqual(2, tempDir.GetFiles().Count());

                File.Delete(outputFile);

                FileInfo cacheFile = tempDir.GetFiles().First();
                File.WriteAllText(cacheFile.FullName, string.Empty);

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    request.SetHeaders("Accept-Encoding", "gzip");
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                Assert.AreEqual(0, File.ReadAllBytes(outputFile).Count());
                Assert.AreEqual(2, tempDir.GetFiles().Count());

                cacheFile.LastWriteTimeUtc = new DateTime(1979, 11, 19);

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    request.SetHeaders("Accept-Encoding", "gzip");
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                Assert.AreNotEqual(0, File.ReadAllBytes(cacheFile.FullName).Count());
                Assert.AreEqual(2, tempDir.GetFiles().Count());

                using (StreamWriter writer = new StreamWriter(outputFile))
                {
                    request.SetHeaders("Accept-Encoding", "deflate");
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    GzipHandler handler = new GzipHandler(settings, imageData);
                    handler.ProcessRequest(context);
                }

                Assert.IsTrue(new FileInfo(outputFile).Length < imageBytes.Length);
                Assert.AreEqual(3, tempDir.GetFiles().Count());
            }
        }
コード例 #15
0
 /// <summary>
 /// Creates a new instance of a GeoImageLayer
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer</param>
 /// <param name="container">The Layers collection that keeps track of the image layer</param>
 public ImageLayer(IImageData baseImage, ICollection <ILayer> container)
     : base(container)
 {
     DataSet = baseImage;
     Configure();
 }
コード例 #16
0
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public ImageLayer(IImageData baseImage)
 {
     DataSet = baseImage;
     Configure();
 }
コード例 #17
0
 public int Compare(IImageData a, IImageData b)
 {
     return(CalculateDifference(a, b));
 }
コード例 #18
0
        /// <summary>
        /// Resamples one VML or DrawingML image
        /// </summary>
        private static bool ResampleCore(IImageData imageData, SizeF shapeSizeInPoints, int ppi, int jpegQuality)
        {
            // The are actually several shape types that can have an image (picture, ole object, ole control), let's skip other shapes.
            if (imageData == null)
            {
                return(false);
            }

            // An image can be stored in the shape or linked from somewhere else. Let's skip images that do not store bytes in the shape.
            byte[] originalBytes = imageData.ImageBytes;
            if (originalBytes == null)
            {
                return(false);
            }

            // Ignore metafiles, they are vector drawings and we don't want to resample them.
            ImageType imageType = imageData.ImageType;

            if (imageType.Equals(ImageType.Wmf) || imageType.Equals(ImageType.Emf))
            {
                return(false);
            }

            try
            {
                double shapeWidthInches  = ConvertUtil.PointToInch(shapeSizeInPoints.Width);
                double shapeHeightInches = ConvertUtil.PointToInch(shapeSizeInPoints.Height);

                // Calculate the current PPI of the image.
                ImageSize imageSize   = imageData.ImageSize;
                double    currentPpiX = imageSize.WidthPixels / shapeWidthInches;
                double    currentPpiY = imageSize.HeightPixels / shapeHeightInches;

                Console.Write("Image PpiX:{0}, PpiY:{1}. ", (int)currentPpiX, (int)currentPpiY);

                // Let's resample only if the current PPI is higher than the requested PPI (e.g. we have extra data we can get rid of).
                if ((currentPpiX <= ppi) || (currentPpiY <= ppi))
                {
                    Console.WriteLine("Skipping.");
                    return(false);
                }

                using (Image srcImage = imageData.ToImage())
                {
                    // Create a new image of such size that it will hold only the pixels required by the desired ppi.
                    int dstWidthPixels  = (int)(shapeWidthInches * ppi);
                    int dstHeightPixels = (int)(shapeHeightInches * ppi);
                    using (Bitmap dstImage = new Bitmap(dstWidthPixels, dstHeightPixels))
                    {
                        // Drawing the source image to the new image scales it to the new size.
                        using (Graphics gr = Graphics.FromImage(dstImage))
                        {
                            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            gr.DrawImage(srcImage, 0, 0, dstWidthPixels, dstHeightPixels);
                        }

                        // Create JPEG encoder parameters with the quality setting.
                        ImageCodecInfo    encoderInfo   = GetEncoderInfo(ImageFormat.Jpeg);
                        EncoderParameters encoderParams = new EncoderParameters();
                        encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, jpegQuality);

                        // Save the image as JPEG to a memory stream.
                        MemoryStream dstStream = new MemoryStream();
                        dstImage.Save(dstStream, encoderInfo, encoderParams);

                        // If the image saved as JPEG is smaller than the original, store it in the shape.
                        Console.WriteLine("Original size {0}, new size {1}.", originalBytes.Length, dstStream.Length);
                        if (dstStream.Length < originalBytes.Length)
                        {
                            dstStream.Position = 0;
                            imageData.SetImage(dstStream);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Catch an exception, log an error and continue if cannot process one of the images for whatever reason.
                Console.WriteLine("Error processing an image, ignoring. " + e.Message);
            }

            return(false);
        }
コード例 #19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="coordinatesPublisher">Coordinates Publisher (Image processing Unit)</param>
        /// <param name="imagingData">Image Data from Image Processing Unit</param>
        public VectorCalculationUnit(Publisher <BallCoordinates> coordinatesPublisher, IImageData imagingData) :
            base(coordinatesPublisher)
        {
            vectorUtils = new RicochetCalc();
            vectorUtils.Initialize();

            _imagingData = imagingData;

            _coordinatesUpdater       = new BallCoordinatesUpdater();
            LastBallLocationPublisher = new BallLocationPublisher(_coordinatesUpdater);

            _storedBallCoordinates        = new BallCoordinates(DateTime.Now);
            _storedBallCoordinates.Vector = new Vector2D();

            D_ERR     = Configuration.Attributes.GetValue <double>(Configuration.Names.VECTOR_CALC_DISTANCE_ERROR);
            ALPHA_ERR = Configuration.Attributes.GetValue <double>(Configuration.Names.VECTOR_CALC_ANGLE_ERROR);
        }
コード例 #20
0
 public bool TryGetThumbnail(ThumbnailDescriptor descriptor, Size size, out IImageData bitmap)
 {
     return(_repository.TryGetThumbnail(descriptor, size, out bitmap));
 }
コード例 #21
0
ファイル: ImageLayer.cs プロジェクト: ExRam/DotSpatial-PCL
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public ImageLayer(IImageData baseImage)
 {
     DataSet = baseImage;
     Configure();
 }
コード例 #22
0
 public RgbHistogramFillFilterStrategy(IImageData hole, int tolerance)
     : base(new HistogramComparer(), hole, tolerance)
 {
 }
コード例 #23
0
 public void CopyValues(IImageData source)
 {
     throw new System.NotImplementedException();
 }
コード例 #24
0
ファイル: TiledImage.cs プロジェクト: rajGSC/DotSpatial
 /// <inheritdoc />
 public void CopyValues(IImageData source)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
ファイル: Canvas.cs プロジェクト: freethenation/OpenGL-Canvas
 public IImageData CreateImageData(IImageData imagedata)
 {
     throw new System.NotImplementedException();
 }
コード例 #26
0
        private void Test_ProcessRequest(IImageData imageData, TestScriptData scriptData)
        {
            using (TemporaryDirectory directory = new TemporaryDirectory())
            {
                string tempDir = directory.FullName;

                string config = $@"<magick.net.web cacheDirectory=""{tempDir}"" tempDirectory=""{tempDir}"" useOpenCL=""true""/>";

                MagickWebSettings settings = TestSectionLoader.Load(config);

                HttpRequest request = new HttpRequest("foo", "https://bar", string.Empty);

                string outputFile = Path.Combine(tempDir, "output.png");

                using (StreamWriter writer = new StreamWriter(outputFile, false, Encoding))
                {
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    MagickScriptHandler handler = new MagickScriptHandler(settings, imageData, scriptData);
                    handler.ProcessRequest(context);
                }

                using (IMagickImage image = new MagickImage(outputFile))
                {
                    Assert.AreEqual(MagickFormat.Png, image.Format);
                    Assert.AreEqual(62, image.Width);
                    Assert.AreEqual(59, image.Height);
                }

                Assert.AreEqual(2, tempDir.GetFiles().Count());

                File.Delete(outputFile);

                FileInfo cacheFile = tempDir.GetFiles().First();
                File.WriteAllText(cacheFile.FullName, string.Empty);

                using (StreamWriter writer = new StreamWriter(outputFile, false, Encoding))
                {
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    MagickScriptHandler handler = new MagickScriptHandler(settings, imageData, scriptData);
                    handler.ProcessRequest(context);
                }

                Assert.AreEqual(0, File.ReadAllBytes(outputFile).Count());
                Assert.AreEqual(2, tempDir.GetFiles().Count());

                cacheFile.LastWriteTimeUtc = new DateTime(1979, 11, 19);

                using (StreamWriter writer = new StreamWriter(outputFile, false, Encoding))
                {
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    MagickScriptHandler handler = new MagickScriptHandler(settings, imageData, scriptData);
                    handler.ProcessRequest(context);
                }

                Assert.AreNotEqual(0, File.ReadAllBytes(cacheFile.FullName).Count());
                Assert.AreEqual(2, tempDir.GetFiles().Count());

                using (IMagickImage image = new MagickImage(outputFile))
                {
                    Assert.AreEqual(MagickFormat.Png, image.Format);
                    Assert.AreEqual(62, image.Width);
                    Assert.AreEqual(59, image.Height);
                }

                scriptData.OutputFormat = MagickFormat.Tiff;

                outputFile = Path.Combine(tempDir, "output.tiff");

                using (StreamWriter writer = new StreamWriter(outputFile, false, Encoding))
                {
                    HttpResponse response = new HttpResponse(writer);
                    HttpContext  context  = new HttpContext(request, response);

                    MagickScriptHandler handler = new MagickScriptHandler(settings, imageData, scriptData);
                    handler.ProcessRequest(context);
                }

                Assert.AreEqual(4, tempDir.GetFiles().Count());

                using (IMagickImage image = new MagickImage(outputFile))
                {
                    Assert.AreEqual(MagickFormat.Tiff, image.Format);
                    Assert.AreEqual(62, image.Width);
                    Assert.AreEqual(59, image.Height);
                }
            }
        }
コード例 #27
0
 /// <summary>
 /// Creates a new PictureSymbol given an existing imageData object.
 /// </summary>
 /// <param name="imageData">The imageData object to use.</param>
 public PictureSymbol(IImageData imageData)
 {
     base.SymbolType = SymbolTypes.Picture;
     _opacity = 1F;
     _image = imageData.GetBitmap();
     _original = _image;
     _imageFilename = imageData.Filename;
 }
コード例 #28
0
 public abstract bool TryGetThumbnail(ThumbnailDescriptor descriptor, Size size, out IImageData thumbnail);
コード例 #29
0
ファイル: AllImageStatistics.cs プロジェクト: daleghent/NINA
 public async static Task <AllImageStatistics> Create(IImageData imageData)
 {
     return(new AllImageStatistics(imageData.Properties, imageData.Statistics.Task, imageData.StarDetectionAnalysis));
 }
コード例 #30
0
ファイル: ImageLayer.cs プロジェクト: hanchao/DotSpatial
 protected virtual void OnDataSetChanged(IImageData value)
 {
     IsVisible = value != null;
     // Change legendText only if image data refers to real file
     if (value != null && File.Exists(value.Filename))
     {
         LegendText = Path.GetFileName(value.Filename);
     }
 }
コード例 #31
0
 public TestMagickHandler(MagickWebSettings settings, IImageData imageData)
     : base(settings, imageData)
 {
     FileName = Files.MagickNETIconPNG;
 }
コード例 #32
0
ファイル: MapImageLayer.cs プロジェクト: joelmuzz/DotSpatial
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public MapImageLayer(IImageData baseImage)
     : base(baseImage)
 {
     
 }
コード例 #33
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapImageLayer"/> class.
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer.</param>
 public MapImageLayer(IImageData baseImage)
     : base(baseImage)
 {
 }
コード例 #34
0
ファイル: MapImageLayer.cs プロジェクト: joelmuzz/DotSpatial
        protected override void OnDataSetChanged(IImageData value)
        {
            base.OnDataSetChanged(value);

            BufferRectangle = value == null? Rectangle.Empty : new Rectangle(0, 0, value.Width, value.Height);
            BufferExtent = value == null? null : value.Bounds.Extent;
            MyExtent =  value == null? null : value.Extent;
            OnFinishedLoading();
        }
コード例 #35
0
 public override bool TryGetThumbnail(ThumbnailDescriptor descriptor, Size size, out IImageData thumbnail)
 {
     thumbnail = null;
     return(false);
 }
コード例 #36
0
        ///////////////////////////////////////////////////////////////////////
        // Perform the actual transformation
        ///////////////////////////////////////////////////////////////////////
        public void Transform(IImageData data, int roi)
        {
            // Hint use locals (accessing on Interface forces boundary crossing)
            // that will be unbearably slow.
            int dW = data.Width;    // Boundary Crossing
            int dH = data.Height;   // Boundary Crossing

            switch (data.Format)
            {
            case ImageDataFormat.MonochromeUnsigned16:
            {
                ushort[] ptr = (ushort[])data.GetData();             // Input Data

                // Loop Width & Height(Quick and Dirty Padding Of 2)
                // This Avoids a lot of boundary checking or reflection and increases speed
                for (int xx = 2; xx < dW - 2; xx++)
                {
                    for (int yy = 2; yy < dH - 2; yy++)
                    {
                        double GY = 0, GX = 0;
                        // Compute the X and Y Components
                        for (int i = 0; i < 9; i++)
                        {
                            int idx = indexBuffers_[roi][xx, yy, i];
                            GY += ptr[idx] * gy[i];
                            GX += ptr[idx] * gx[i];
                        }
                        // Magnitude
                        double G = Math.Sqrt(GX * GX + GY * GY);

                        // Put the Magnitude into the output buffer
                        retDataUs_[roi][yy * dW + xx] = (ushort)G;
                    }
                }
                // Write the output buffer to the IImageData
                // Boundary Crossing
                data.SetData(retDataUs_[roi]);
            }
            break;

            case ImageDataFormat.MonochromeUnsigned32:
            {
                uint[] ptr = (uint[])data.GetData();             // Input Data

                // Loop Width & Height(Quick and Dirty Padding Of 2)
                // This Avoids a lot of boundary checking or reflection and increases speed
                for (int xx = 2; xx < dW - 2; xx++)
                {
                    for (int yy = 2; yy < dH - 2; yy++)
                    {
                        double GY = 0, GX = 0;
                        // Compute the X and Y Components
                        for (int i = 0; i < 9; i++)
                        {
                            int idx = indexBuffers_[roi][xx, yy, i];
                            GY += ptr[idx] * gy[i];
                            GX += ptr[idx] * gx[i];
                        }
                        // Magnitude
                        double G = Math.Sqrt(GX * GX + GY * GY);

                        // Put the Magnitude into the output buffer
                        retDataI_[roi][yy * dW + xx] = (uint)G;
                    }
                }
                // Write the output buffer to the IImageData
                // Boundary Crossing
                data.SetData(retDataI_[roi]);
            }
            break;

            case ImageDataFormat.MonochromeFloating32:
            {
                float[] ptr = (float[])data.GetData();             // Input Data

                // Loop Width & Height(Quick and Dirty Padding Of 2)
                // This Avoids a lot of boundary checking or reflection and increases speed
                for (int xx = 2; xx < dW - 2; xx++)
                {
                    for (int yy = 2; yy < dH - 2; yy++)
                    {
                        double GY = 0, GX = 0;
                        // Compute the X and Y Components
                        for (int i = 0; i < 9; i++)
                        {
                            int idx = indexBuffers_[roi][xx, yy, i];
                            GY += ptr[idx] * gy[i];
                            GX += ptr[idx] * gx[i];
                        }
                        // Magnitude
                        double G = Math.Sqrt(GX * GX + GY * GY);

                        // Put the Magnitude into the output buffer
                        retDataF_[roi][yy * dW + xx] = (float)G;
                    }
                }
                // Write the output buffer to the IImageData
                // Boundary Crossing
                data.SetData(retDataF_[roi]);
            }
            break;
            }
        }
コード例 #37
0
ファイル: ImageLayer.cs プロジェクト: hanchao/DotSpatial
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public ImageLayer(IImageData baseImage)
 {
     DataSet = baseImage;
 }
コード例 #38
0
        void ShowFrame(string fileName)
        {
            var filemgr = application_.FileManager;

            if (filemgr != null)
            {
                IImageDataSet dataSet = filemgr.OpenFile(fileName, FileAccess.Read);
                IImageData    d       = dataSet.GetFrame(0, 0);

                // Convert IImageData To Bitmap
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(d.Width, d.Height);
                ushort[] data             = new ushort[bmp.Width * bmp.Height];

                // convert them all to the smallest (simple example for now)
                var pixels = bmp.Width * bmp.Height;
                switch (d.Format)
                {
                case ImageDataFormat.MonochromeFloating32:
                {
                    float[] ptr = (float[])d.GetData();
                    for (int k = 0; k < pixels; k++)
                    {
                        data[k] = (ushort)ptr[k];
                    }
                }
                break;

                case ImageDataFormat.MonochromeUnsigned16:
                {
                    ushort[] ptr = (ushort[])d.GetData();
                    for (int k = 0; k < pixels; k++)
                    {
                        data[k] = (ushort)ptr[k];
                    }
                }
                break;

                case ImageDataFormat.MonochromeUnsigned32:
                {
                    uint[] ptr = (uint[])d.GetData();
                    for (int k = 0; k < pixels; k++)
                    {
                        data[k] = (ushort)ptr[k];
                    }
                }
                break;
                }

                short rgb_value = 0;
                int   i         = 0;
                for (int y = 0; y < bmp.Height; y++)
                {
                    for (int x = 0; x < bmp.Width; x++)
                    {
                        rgb_value = (short)((ushort)data[i] / (ushort)256);
                        bmp.SetPixel(x, y, System.Drawing.Color.FromArgb(rgb_value, rgb_value, rgb_value));
                        i++;
                    }
                }
                // Convert To WPF Bitmap
                System.Windows.Media.Imaging.BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
                                                                                                                                      System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());

                // Set the source
                image1.Source = bitmapSource;

                // Show the image in a new display viewer
                viewer_.DisplayViewer.Display("Sample Display", dataSet);
            }
        }
コード例 #39
0
ファイル: MapImageLayer.cs プロジェクト: joelmuzz/DotSpatial
 /// <summary>
 /// Creates a new instance of a GeoImageLayer
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer</param>
 /// <param name="transparent">The color to make transparent when drawing the image.</param>
 public MapImageLayer(IImageData baseImage, Color transparent)
     : base(baseImage)
 {
     this.transparent = transparent;
 }
コード例 #40
0
ファイル: InRamImageData.cs プロジェクト: rprouse/DotSpatial
 /// <summary>
 /// Copies the values from the specified source image.
 /// </summary>
 /// <param name="source">The source image to copy values from.</param>
 public override void CopyValues(IImageData source)
 {
     Values        = (byte[])source.Values.Clone();
     NumBands      = source.NumBands;
     BytesPerPixel = source.BytesPerPixel;
 }
コード例 #41
0
 /// <summary>
 /// Initializes a new instance of the ImageDataEventArgs class.
 /// </summary>
 /// <param name="imageData">The IImageData that is involved in this event.</param>
 public ImageDataEventArgs(IImageData imageData)
 {
     _imageData = imageData;
 }
コード例 #42
0
        public async Task <FlatWizardUserPromptVMResponse> EvaluateUserPromptResultAsync(IImageData imageData, double exposureTime, string message, FlatWizardFilterSettingsWrapper wrapper)
        {
            var imageStatistics       = await imageData.Statistics.Task;
            var flatsWizardUserPrompt = new FlatWizardUserPromptVM(
                message,
                imageStatistics.Mean,
                CameraBitDepthToAdu(wrapper.BitDepth),
                wrapper,
                exposureTime);
            await WindowService.ShowDialog(flatsWizardUserPrompt, Locale["LblFlatUserPromptFailure"], System.Windows.ResizeMode.NoResize, System.Windows.WindowStyle.ToolWindow);

            if (flatsWizardUserPrompt.Reset)
            {
                ClearDataPoints();
            }

            return(new FlatWizardUserPromptVMResponse()
            {
                Continue = flatsWizardUserPrompt.Continue,
                NextExposureTime = flatsWizardUserPrompt.Reset ? wrapper.Settings.MinFlatExposureTime : exposureTime
            });
        }
コード例 #43
0
ファイル: ImageLayer.cs プロジェクト: ExRam/DotSpatial-PCL
 /// <summary>
 /// Creates a new instance of a GeoImageLayer
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer</param>
 /// <param name="container">The Layers collection that keeps track of the image layer</param>
 public ImageLayer(IImageData baseImage, ICollection<ILayer> container)
     : base(container)
 {
     DataSet = baseImage;
     Configure();
 }
コード例 #44
0
 /// <summary>
 /// Initializes a new instance of the ImageDataEventArgs class.
 /// </summary>
 /// <param name="imageData">The IImageData that is involved in this event.</param>
 public ImageDataEventArgs(IImageData imageData)
 {
     _imageData = imageData;
 }
コード例 #45
0
        /// <summary>
        /// Resamples one VML or DrawingML image
        /// </summary>
        private static bool ResampleCore(IImageData imageData, SizeF shapeSizeInPoints, int ppi, int jpegQuality)
        {
            // The are actually several shape types that can have an image (picture, ole object, ole control), let's skip other shapes.
            if (imageData == null)
                return false;

            // An image can be stored in the shape or linked from somewhere else. Let's skip images that do not store bytes in the shape.
            byte[] originalBytes = imageData.ImageBytes;
            if (originalBytes == null)
                return false;

            // Ignore metafiles, they are vector drawings and we don't want to resample them.
            ImageType imageType = imageData.ImageType;
            if (imageType.Equals(ImageType.Wmf) || imageType.Equals(ImageType.Emf))
                return false;

            try
            {
                double shapeWidthInches = ConvertUtil.PointToInch(shapeSizeInPoints.Width);
                double shapeHeightInches = ConvertUtil.PointToInch(shapeSizeInPoints.Height);

                // Calculate the current PPI of the image.
                ImageSize imageSize = imageData.ImageSize;
                double currentPpiX = imageSize.WidthPixels / shapeWidthInches;
                double currentPpiY = imageSize.HeightPixels / shapeHeightInches;

                Console.Write("Image PpiX:{0}, PpiY:{1}. ", (int)currentPpiX, (int)currentPpiY);

                // Let's resample only if the current PPI is higher than the requested PPI (e.g. we have extra data we can get rid of).
                if ((currentPpiX <= ppi) || (currentPpiY <= ppi))
                {
                    Console.WriteLine("Skipping.");
                    return false;
                }

                using (Image srcImage = imageData.ToImage())
                {
                    // Create a new image of such size that it will hold only the pixels required by the desired ppi.
                    int dstWidthPixels = (int)(shapeWidthInches * ppi);
                    int dstHeightPixels = (int)(shapeHeightInches * ppi);
                    using (Bitmap dstImage = new Bitmap(dstWidthPixels, dstHeightPixels))
                    {
                        // Drawing the source image to the new image scales it to the new size.
                        using (Graphics gr = Graphics.FromImage(dstImage))
                        {
                            gr.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            gr.DrawImage(srcImage, 0, 0, dstWidthPixels, dstHeightPixels);
                        }

                        // Create JPEG encoder parameters with the quality setting.
                        ImageCodecInfo encoderInfo = GetEncoderInfo(ImageFormat.Jpeg);
                        EncoderParameters encoderParams = new EncoderParameters();
                        encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, jpegQuality);

                        // Save the image as JPEG to a memory stream.
                        MemoryStream dstStream = new MemoryStream();
                        dstImage.Save(dstStream, encoderInfo, encoderParams);

                        // If the image saved as JPEG is smaller than the original, store it in the shape.
                        Console.WriteLine("Original size {0}, new size {1}.", originalBytes.Length, dstStream.Length);
                        if (dstStream.Length < originalBytes.Length)
                        {
                            dstStream.Position = 0;
                            imageData.SetImage(dstStream);
                            return true;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                // Catch an exception, log an error and continue if cannot process one of the images for whatever reason.
                Console.WriteLine("Error processing an image, ignoring. " + e.Message);
            }

            return false;
        }
コード例 #46
0
 /// <summary>
 /// Creates a new instance of GeoImageLayer
 /// </summary>
 public MapImageLayer(IImageData baseImage)
     : base(baseImage)
 {
     Configure(baseImage);
 }
コード例 #47
0
 public abstract bool TryGetThumbnail(ThumbnailDescriptor descriptor, Size size, out IImageData thumbnail);
コード例 #48
0
 internal GzipHandler(MagickWebSettings settings, IImageData imageData)
     : base(settings, imageData)
 {
 }
コード例 #49
0
 /// <summary>
 /// Image Processing Unit Constructor
 /// </summary>
 /// <param name="streamer">Streamer to get frames from</param>
 /// <param name="ballTracker">Ball Tracker [default is null - will be created]</param>
 /// <param name="imagingData">Imaging data [default is null - will be created]</param>
 /// <param name="analyzerTool">Statistics Tool [default is null - will be created]</param>
 public FrameProcessingUnit(FramePublisher streamer, Tracker ballTracker = null, IImageData imagingData = null, IDetectionAnalyzer analyzerTool = null)
     : base(streamer, imagingData) 
 {
     _ballTracker = ballTracker ?? new BallTracker(ImagingData, streamer);
     AnalyzerTool = analyzerTool ?? new DetectionStatisticAnalyzer();
     _lastFrameTimeStamp = DateTime.Now;
 }
コード例 #50
0
 public AverageDarkFillFilterStrategy(IImageData hole, int tolerance)
     : base(new AverageGreyComparer(), hole, tolerance)
 {
 }
コード例 #51
0
ファイル: Canvas.cs プロジェクト: freethenation/OpenGL-Canvas
 public void DrawImage(IImageData image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
 {
     throw new System.NotImplementedException();
 }
コード例 #52
0
 public ImagesDetailsModel(IImageData imageData)
 {
     this.imageData = imageData;
 }
コード例 #53
0
ファイル: Canvas.cs プロジェクト: freethenation/OpenGL-Canvas
 public void PutImageData(IImageData imagedata, float dx, float dy, float dirtyX, float dirtyY, float dirtyWidth, float dirtyHeight)
 {
     throw new System.NotImplementedException();
 }
コード例 #54
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MapImageLayer"/> class.
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer</param>
 /// <param name="transparent">The color to make transparent when drawing the image.</param>
 public MapImageLayer(IImageData baseImage, Color transparent)
     : base(baseImage)
 {
     _transparent = transparent;
 }
コード例 #55
0
ファイル: GalleryItem.cs プロジェクト: m-berkani/ClearCanvas
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
                return;

            if (_imageData == null)
                return;

            _imageData.Dispose();
            _imageData = null;
        }
コード例 #56
0
ファイル: ImageData.cs プロジェクト: wangscript007/Fusee
        /// <summary>
        /// Copies a rectangular block of pixel data from a source image to a this image (Blt = BlockTransfer).
        /// </summary>
        /// <param name="xDst">The x destination coordinate (where to place the block within dst).</param>
        /// <param name="yDst">The y destination coordinate (where to place the block within dst).</param>
        /// <param name="src">The source image.</param>
        /// <param name="xSrc">The x source coordinate (where to start copying from within src).</param>
        /// <param name="ySrc">The y source coordinate (where to start copying from within src).</param>
        /// <param name="width">The width of the block to copy. (default is src.Width).</param>
        /// <param name="height">The height of the block to copy (default is src.Height).</param>
        /// <remarks>
        ///     All specified parameters are clipped to avoid out-of-bounds indices. No warnings or exceptions are issued
        ///     in case clipping results in a smaller or an empty block.
        /// </remarks>
        public void Blt(int xDst, int yDst, IImageData src, int xSrc = 0, int ySrc = 0, int width = 0, int height = 0)
        {
            if (width == 0)
            {
                width = src.Width;
            }
            if (height == 0)
            {
                height = src.Height;
            }

            ClipBlt(ref xDst, Width, ref xSrc, src.Width, ref width);
            ClipBlt(ref yDst, Height, ref ySrc, src.Height, ref height);

            if (width <= 0 || height <= 0)
            {
                return;
            }

            CopyFunc copyLine;

            if (PixelFormat.ColorFormat.Equals(src.PixelFormat.ColorFormat))
            {
                // Case: same color space, just loop over scanlines from src and copy line-wise into this ImageData
                copyLine = delegate(byte[] srcScanLineBytes, int destinationIndex)
                {
                    Array.Copy(srcScanLineBytes, 0, PixelData, destinationIndex, srcScanLineBytes.Length);
                };
            }
            else
            {
                // Wee need to perform pixel-conversion while copying. -> still GetLineBytes and then perform pixel conversion

                switch (PixelFormat.ColorFormat)
                {
                case ColorFormat.RGBA:
                    switch (src.PixelFormat.ColorFormat)
                    {
                    case ColorFormat.RGB:
                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i += 3)         // jump 3 units per loop because we want to copy src RGB to dst RGBA
                            {
                                PixelData[destinationIndex + i + 0] = srcLineBytes[i + 0];
                                PixelData[destinationIndex + i + 1] = srcLineBytes[i + 1];
                                PixelData[destinationIndex + i + 2] = srcLineBytes[i + 2];
                                PixelData[destinationIndex + i + 3] = byte.MaxValue;
                            }
                        };
                        break;

                    case ColorFormat.Intensity:
                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i++)         // jump 1 unit per loop because we want to copy src Intensity to dst RGBA
                            {
                                PixelData[destinationIndex + i + 0] = srcLineBytes[i];
                                PixelData[destinationIndex + i + 1] = srcLineBytes[i];
                                PixelData[destinationIndex + i + 2] = srcLineBytes[i];
                                PixelData[destinationIndex + i + 3] = byte.MaxValue;
                            }
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(src), "Unknown source pixel format to copy to RGBA");
                    }
                    break;

                case ColorFormat.RGB:
                    switch (src.PixelFormat.ColorFormat)
                    {
                    case ColorFormat.RGBA:

                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i += 4)         // jump 4 units per loop because we want to copy src RGBA to dst RGB
                            {
                                PixelData[destinationIndex + i + 0] = srcLineBytes[i + 0];
                                PixelData[destinationIndex + i + 1] = srcLineBytes[i + 1];
                                PixelData[destinationIndex + i + 2] = srcLineBytes[i + 2];
                                // skip source alpha
                            }
                        };

                        break;

                    case ColorFormat.Intensity:
                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i++)         // jump 1 unit per loop because we want to copy src Intensity to dst RGB
                            {
                                PixelData[destinationIndex + i + 0] = srcLineBytes[i];
                                PixelData[destinationIndex + i + 1] = srcLineBytes[i];
                                PixelData[destinationIndex + i + 2] = srcLineBytes[i];
                            }
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(src), "Unknown source pixel format to copy to RGB");
                    }
                    break;

                case ColorFormat.Intensity:
                    switch (src.PixelFormat.ColorFormat)
                    {
                    case ColorFormat.RGB:
                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i += 3)         // jump 3 units per loop because we want to copy src RGB to dst Intensity
                            {
                                // Quick integer Luma conversion (not accurate)
                                // See http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
                                int r = srcLineBytes[destinationIndex + i + 0];
                                int g = srcLineBytes[destinationIndex + i + 1];
                                int b = srcLineBytes[destinationIndex + i + 2];
                                PixelData[destinationIndex + i] = (byte)((r + r + b + g + g + g) / 6);
                            }
                        };
                        break;

                    case ColorFormat.RGBA:
                        copyLine = delegate(byte[] srcLineBytes, int destinationIndex)
                        {
                            for (int i = 0; i < srcLineBytes.Length; i += 4)         // jump 4 units per loop because we want to copy src RGBA to dst Intensity
                            {
                                // Quick integer Luma conversion (not accurate)
                                // See http://stackoverflow.com/questions/596216/formula-to-determine-brightness-of-rgb-color
                                int r = srcLineBytes[destinationIndex + i + 0];
                                int g = srcLineBytes[destinationIndex + i + 1];
                                int b = srcLineBytes[destinationIndex + i + 2];
                                PixelData[destinationIndex + i] = (byte)((r + r + b + g + g + g) / 6);
                            }
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(src), "Unknown source pixel format to copy to RGB");
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(ToString(), "Unknown destination pixel format");
                } // end switch
            }     // end else block

            // loop over the ScanLineEnumerator and call CopyLine delegate
            var srcEnumerator = src.ScanLines(xSrc, ySrc, width, height);

            while (srcEnumerator.MoveNext())
            {
                var srcScanLine = srcEnumerator.Current;
                if (srcScanLine != null)
                {
                    byte[] srcScanLineBytes = srcScanLine.GetScanLineBytes();
                    int    destinationIndex = yDst * PixelFormat.BytesPerPixel * Width + xDst * PixelFormat.BytesPerPixel; // move down by yDst and add (move right) xDst
                    copyLine(srcScanLineBytes, destinationIndex);
                    yDst++;                                                                                                // increment yDst == move to the next line
                }
            }
        }
コード例 #57
0
 /// <summary>
 /// Creates a new instance of a GeoImageLayer
 /// </summary>
 /// <param name="baseImage">The image to draw as a layer</param>
 /// <param name="container">The Layers collection that keeps track of the image layer</param>
 public MapImageLayer(IImageData baseImage, ICollection<ILayer> container)
     : base(baseImage, container)
 {
     Configure(baseImage);
 }
コード例 #58
0
ファイル: ImageData.cs プロジェクト: osome/DotSpatial
 /// <summary>
 /// Copies the values from the specified source image.
 /// </summary>
 /// <param name="source">The source image to copy values from.</param>
 public virtual void CopyValues(IImageData source)
 {
 }
コード例 #59
0
 /// <summary>
 /// Copies the values from the specified source image.
 /// </summary>
 /// <param name="source">
 /// The source image to copy values from.
 /// </param>
 public override void CopyValues(IImageData source)
 {
     Values = (byte[])source.Values.Clone();
     NumBands = source.NumBands;
     BytesPerPixel = source.BytesPerPixel;
 }
コード例 #60
0
 /// <summary>
 /// Find the image
 /// </summary>
 /// <param name="image"></param>
 /// <param name="FindOnlyOne"></param>
 /// <param name="matchRadius"></param>
 /// <returns></returns>
 public abstract List <Point> FindImage(IImageData image, bool FindOnlyOne, double matchRadius, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null);