working on it ...

Filters

Explore Public Snippets

Sort by

Found 98 snippets matching: image-processing

    public by antlong  489216  15  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by sherazam  4270  3  5  0

    How to Crop EMF Image using Shifts or Rectangle Approaches in .NET Applications

    This technical tip explains how .NET developers can Crop an EMF Image inside their .NET applications. Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used to cut out some portion of an image to increase the focus on a particular area. Aspose.Imaging for .Net API supports
    // Enter here the actual content of the snippet.            // Cropping by Shifts
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfBezier.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
      using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
      {
        //Based on the shift values, apply the cropping on image
        //Crop method will shift the image bounds toward the center of image
        image.Crop(30, 40, 50, 60);
    
        // Set height and width
        pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
        pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
        //Save the results to disk
        image.Save(outputStream, pdfOptions);
      }
    }
     
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfBezier.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Based on the shift values, apply the cropping on image
    		'Crop method will shift the image bounds toward the center of image
    		image.Crop(30, 40, 50, 60)
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    // Cropping by Rectangle
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfExtPen.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
        using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
        {
            //Create an instance of Rectangle class with desired size
            //Perform the crop operation on object of Rectangle class
            image.Crop(new Aspose.Imaging.Rectangle(30, 50, 100, 150));
    
            // Set height and width
            pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
            pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
            //Save the results to disk
            image.Save(outputStream, pdfOptions);
        }
    }
    
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfExtPen.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Create an instance of Rectangle class with desired size
    		'Perform the crop operation on object of Rectangle class
    		image.Crop(New Aspose.Imaging.Rectangle(30, 50, 100, 150))
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    

    public by sherazam  4181  1  6  0

    How to Combine Two or Multiple Images into a Single Image inside .NET Apps

    This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface us
    // Enter here the actual content of the snippet.            
    // Combining Images using Graphics Class
    
    //[C# Code Sample]
    
    //Create an instance of JpegOptions and set its various properties
    Aspose.Imaging.ImageOptions.JpegOptions ImageOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
    
    //Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"two_images_result.jpeg", false);
    
    //Create an instance of Image and define canvas size
    using (var image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600))
    {
          //Create and initialize an instance of Graphics
          var graphics = new Aspose.Imaging.Graphics(image);
    
          //Clear the image surface with white color
          graphics.Clear(Aspose.Imaging.Color.White);
    
          // Draw Image
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input1.jpg"), 0, 0, 600, 300);
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input2.jpg"), 0, 300, 600, 300);
                    
          // Call save method to save the resultant image.
          image.Save();
    }
     
    //[VB.NET Code Sample]
    
    'Create an instance of JpegOptions and set its various properties
    Dim ImageOptions As New Aspose.Imaging.ImageOptions.JpegOptions()
    
    'Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = New Aspose.Imaging.Sources.FileCreateSource("two_images_result.jpeg", False)
    
    'Create an instance of Image and define canvas size
    Using image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600)
    	'Create and initialize an instance of Graphics
    	Dim graphics = New Aspose.Imaging.Graphics(image)
    
    	'Clear the image surface with white color
    	graphics.Clear(Aspose.Imaging.Color.White)
    
    	' Draw Image
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input1.jpg"), 0, 0, 600, 300)
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input2.jpg"), 0, 300, 600, 300)
    
    	' Call save method to save the resultant image.
    	image.Save()
    End Using
    
    

    public by sherazam  3006  0  6  1

    How to Create Thumbnails from PSD Files inside .NET Applications

    // Enter here the actual content of the snippet.         
    // Creating Thumbnails from PSD Files
    
    //[C# Code Sample]
    
    //Load a PSD in an instance of PsdImage
    using (Aspose.Imaging.FileFormats.Psd.PsdImage image = (Aspose.Imaging.FileFormats.Psd.PsdImage)Aspose.Imaging.Image.Load(sourceFilePath))
    {
        //Iterate over the PSD resources
        foreach (var resource in image.ImageResources)
        {
            //Check if the resource is of thumbnail type
            if (resource is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
            {
                //Retrieve the ThumbnailResource
                var thumbnail = (Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)resource;
                //Check the format of the ThumbnailResource
                if (thumbnail.Format == Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB)
                {
                    //Create a new BmpImage by specifying the width and heigh
                    Aspose.Imaging.FileFormats.Bmp.BmpImage thumnailImage = new Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height);
                    //Store the pixels of thumbnail on to the newly created BmpImage
                    thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData);
                    //Save thumbnail on disc
                    thumnailImage.Save("D:\\test.bmp");
                }
            }
        }
    }
     
    //[VB.NET Code Sample]
    
    'Load a PSD in an instance of PsdImage
    Using image As Aspose.Imaging.FileFormats.Psd.PsdImage = CType(Aspose.Imaging.Image.Load(sourceFilePath), Aspose.Imaging.FileFormats.Psd.PsdImage)
    	'Iterate over the PSD resources
    	For Each resource In image.ImageResources
    		'Check if the resource is of thumbnail type
    		If TypeOf resource Is Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource Then
    			'Retrieve the ThumbnailResource
    			Dim thumbnail = CType(resource, Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailResource)
    			'Check the format of the ThumbnailResource
    			If thumbnail.Format = Aspose.Imaging.FileFormats.Psd.Resources.ThumbnailFormat.kJpegRGB Then
    				'Create a new BmpImage by specifying the width and heigh
    				Dim thumnailImage As New Aspose.Imaging.FileFormats.Bmp.BmpImage(thumbnail.Width, thumbnail.Height)
    				'Store the pixels of thumbnail on to the newly created BmpImage
    				thumnailImage.SavePixels(thumnailImage.Bounds, thumbnail.ThumbnailData)
    				'Save thumbnail on disc
    				thumnailImage.Save("D:\test.bmp")
    			End If
    		End If
    	Next resource
    End Using
    
    

    public by sherazam  2709  0  6  1

    How to Read and Write XMP Data to Images inside .NET Apps

    // Enter here the actual content of the snippet.//Create XMP Metadata, Write It And Read From File
    
    //[C# Code Sample]
    
    // Specify the size of image by defining a Rectangle 
    Aspose.Imaging.Rectangle rect = new Aspose.Imaging.Rectangle(0, 0, 100, 200);
    
    TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRGB);
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack;
    tiffOptions.BitsPerSample = new ushort[] { 8 };
    
    // create the brand new image just for sample purposes
    using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height)))
    {
          // create an instance of XMP-Header
          Aspose.Imaging.Xmp.XmpHeaderPi xmpHeader = new Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString());
    
          // create an instance of Xmp-TrailerPi 
          Aspose.Imaging.Xmp.XmpTrailerPi xmpTrailer = new Aspose.Imaging.Xmp.XmpTrailerPi(true);
    
          // create an instance of XMPmeta class to set different attributes
          Aspose.Imaging.Xmp.XmpMeta xmpMeta = new Aspose.Imaging.Xmp.XmpMeta();
          xmpMeta.AddAttribute("Author", "Mr Smith");
          xmpMeta.AddAttribute("Description", "The fake metadata value");
    
          // create an instance of XmpPacketWrapper that contains all metadata
          Aspose.Imaging.Xmp.XmpPacketWrapper xmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
    
          // create an instacne of Photoshop package and set photoshop attributes
          Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage photoshopPackage = new Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage();
          photoshopPackage.SetCity("London");
          photoshopPackage.SetCountry("England");
          photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb);
          photoshopPackage.SetCreatedDate(DateTime.UtcNow);
    
          // add photoshop package into XMP metadata
          xmpData.AddPackage(photoshopPackage);
    
          // create an instacne of DublinCore package and set dublinCore attributes
          Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage dublinCorePackage = new Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage();
          dublinCorePackage.SetAuthor("Charles Bukowski");
          dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts");
          dublinCorePackage.AddValue("dc:movie", "Barfly");
    
          // add dublinCore Package into XMP metadata
          xmpData.AddPackage(dublinCorePackage);
    
          using (var ms = new MemoryStream())
          {
                        // update XMP metadata into image
                        image.XmpData = xmpData;
    
                        // Save image on the disk or in memory stream
                        image.Save(ms);
    
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
    
                        // Load the image from moemory stream or from disk to read/get the metadata
                        using (var img = (TiffImage)Aspose.Imaging.Image.Load(ms))
                        {
                            // getting the XMP metadata
                            Aspose.Imaging.Xmp.XmpPacketWrapper imgXmpData = img.XmpData;
                            foreach (Aspose.Imaging.Xmp.XmpPackage package in imgXmpData.Packages)
                            {
                                // use package data ...
                            }
                        }
         }
    }
     
    //[VB.NET Code Sample]
    
    ' Specify the size of image by defining a Rectangle 
    Dim rect As New Aspose.Imaging.Rectangle(0, 0, 100, 200)
    
    Dim tiffOptions As New TiffOptions(TiffExpectedFormat.TiffJpegRGB)
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack
    tiffOptions.BitsPerSample = New UShort() {8}
    
    ' create the brand new image just for sample purposes
    Using image = New TiffImage(New TiffFrame(tiffOptions, rect.Width, rect.Height))
    	' create an instance of XMP-Header
    	Dim xmpHeader As New Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString())
    
    	' create an instance of Xmp-TrailerPi 
    	Dim xmpTrailer As New Aspose.Imaging.Xmp.XmpTrailerPi(True)
    
    	' create an instance of XMPmeta class to set different attributes
    	Dim xmpMeta As New Aspose.Imaging.Xmp.XmpMeta()
    	xmpMeta.AddAttribute("Author", "Mr Smith")
    	xmpMeta.AddAttribute("Description", "The fake metadata value")
    
    	' create an instance of XmpPacketWrapper that contains all metadata
    	Dim xmpData As New Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta)
    
    	' create an instacne of Photoshop package and set photoshop attributes
    	Dim photoshopPackage As New Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage()
    	photoshopPackage.SetCity("London")
    	photoshopPackage.SetCountry("England")
    	photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb)
    	photoshopPackage.SetCreatedDate(DateTime.UtcNow)
    
    	' add photoshop package into XMP metadata
    	xmpData.AddPackage(photoshopPackage)
    
    	' create an instacne of DublinCore package and set dublinCore attributes
    	Dim dublinCorePackage As New Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage()
    	dublinCorePackage.SetAuthor("Charles Bukowski")
    	dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts")
    	dublinCorePackage.AddValue("dc:movie", "Barfly")
    
    	' add dublinCore Package into XMP metadata
    	xmpData.AddPackage(dublinCorePackage)
    
    	Using ms = New MemoryStream()
    		' update XMP metadata into image
    		image.XmpData = xmpData
    
    		' Save image on the disk or in memory stream
    		image.Save(ms)
    
    		ms.Seek(0, System.IO.SeekOrigin.Begin)
    
    		' Load the image from moemory stream or from disk to read/get the metadata
    		Using img = DirectCast(Aspose.Imaging.Image.Load(ms), TiffImage)
    			' getting the XMP metadata
    			Dim imgXmpData As Aspose.Imaging.Xmp.XmpPacketWrapper = img.XmpData
    					' use package data ...
    			For Each package As Aspose.Imaging.Xmp.XmpPackage In imgXmpData.Packages
    			Next
    		End Using
    	End Using
    End Using
    
    

    public by sherazam  2626  0  6  0

    How to Add Watermark to an Image inside .NET Applications

    // Enter here the actual content of the snippet.            
    // Adding a Watermark
    
    //[C# Code Sample]
    
    //Load an existing JPG image
    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(myDir + "sample.jpg"))
    {
    
        //Declare a String object with Watermark Text
        String theString = "45 Degree Rotated Text";
    
        //Create and initialize an instance of Graphics class
        Aspose.Imaging.Graphics graphics = new Aspose.Imaging.Graphics(image);
    
        //Initialize an object of SizeF to store image Size
        Aspose.Imaging.SizeF sz = graphics.Image.Size;
    
        //Creates an instance of Font, initialize it with Font Face, Size and Style
        Aspose.Imaging.Font font = new Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold);
    
        //Create an instance of SolidBrush and set its various properties
        Aspose.Imaging.Brushes.SolidBrush brush = new Aspose.Imaging.Brushes.SolidBrush();
        brush.Color = Aspose.Imaging.Color.Red;
        brush.Opacity = 0;
    
        //Initialize an object of StringFormat class and set its various properties
        Aspose.Imaging.StringFormat format = new Aspose.Imaging.StringFormat();
        format.Alignment = Aspose.Imaging.StringAlignment.Center;
        format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces;
    
        //Create an object of Matrix class for transformation
        Aspose.Imaging.Matrix matrix = new Aspose.Imaging.Matrix();
        //First a translation
        matrix.Translate(sz.Width / 2, sz.Height / 2);
        //Then a rotation
        matrix.Rotate(-45.0f);
    
        //Set the Transformation through Matrix
        graphics.Transform = matrix;
    
        //Draw the string on Image
        graphics.DrawString(theString, font, brush, 0, 0, format);
    
        //Save output to disk
        image.Save(myDir + "output.jpg");
    }
     
    //[VB.NET Code Sample]
    
    'Load an existing JPG image
    Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load(myDir & "sample.jpg")
    
    	'Declare a String object with Watermark Text
    	Dim theString As String = "45 Degree Rotated Text"
    
    	'Create and initialize an instance of Graphics class
    	Dim graphics As New Aspose.Imaging.Graphics(image)
    
    	'Initialize an object of SizeF to store image Size
    	Dim sz As Aspose.Imaging.SizeF = graphics.Image.Size
    
    	'Creates an instance of Font, initialize it with Font Face, Size and Style
    	Dim font As New Aspose.Imaging.Font("Times New Roman", 20, FontStyle.Bold)
    
    	'Create an instance of SolidBrush and set its various properties
    	Dim brush As New Aspose.Imaging.Brushes.SolidBrush()
    	brush.Color = Aspose.Imaging.Color.Red
    	brush.Opacity = 0
    
    	'Initialize an object of StringFormat class and set its various properties
    	Dim format As New Aspose.Imaging.StringFormat()
    	format.Alignment = Aspose.Imaging.StringAlignment.Center
    	format.FormatFlags = Aspose.Imaging.StringFormatFlags.MeasureTrailingSpaces
    
    	'Create an object of Matrix class for transformation
    	Dim matrix As New Aspose.Imaging.Matrix()
    	'First a translation
    	matrix.Translate(sz.Width / 2, sz.Height / 2)
    	'Then a rotation
    	matrix.Rotate(-45.0f)
    
    	'Set the Transformation through Matrix
    	graphics.Transform = matrix
    
    	'Draw the string on Image
    	graphics.DrawString(theString, font, brush, 0, 0, format)
    
    	'Save output to disk
    	image.Save(myDir & "output.jpg")
    End Using
    
    

    public by sherazam  2496  0  5  0

    How to Convert GIFF Image Frame to WebP Image inside .NET Applications

    // Enter here the actual content of the snippet.            
    // Converting GIFF Image Frame to WebP Image
    //[C# Code Sample]
    
    // Load GIFF image into the instance of image class.
    using (Aspose.Imaging.Image image = Aspose.Imaging.Image.Load(@"D:\animation.gif"))
    {
          // Create an instance of GIFF image class.
          Aspose.Imaging.FileFormats.Gif.GifImage gif = image as Aspose.Imaging.FileFormats.Gif.GifImage;
    
          if (gif == null) return;
    
          // Load an existing WebP image into the instance of WebPImage class.
          using (Aspose.Imaging.FileFormats.Webp.WebPImage webp = new Aspose.Imaging.FileFormats.Webp.WebPImage(image.Width, image.Height, null))
          {
                 // Loop through the GIFF frames
                 for (int i = 0; i < gif.Blocks.Length; i++)
                 {
                        // Convert GIFF block to GIFF Frame
                        Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock gifBlock = gif.Blocks[i] as Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock;
                        if (gifBlock == null)
                        {
                                continue;
                        }
    
                        // Create an instance of WebP Frame instance by passing GIFF frame to class constructor.
                        Aspose.Imaging.FileFormats.Webp.WebPFrameBlock block = new Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(gifBlock)
                        {
                                Top = (short)gifBlock.Top,
                                Left = (short)gifBlock.Left,
                               Duration = (short)gifBlock.ControlBlock.DelayTime
                        };
    
                        // Add WebP frame to WebP image block list
                        webp.AddBlock(block);
                }
    
                // Set Properties of WebP image.
                webp.Options.AnimBackgroundColor = 0xff; //black
                webp.Options.AnimLoopCount = 0; //infinity
                webp.Options.Quality = 50;
                webp.Options.Lossless = false;
    
                // Save WebP image.
                webp.Save(@"D:\saveAnimation.webp");
          }
    }
     
    //[VB.NET Code Sample]
    
    ' Load GIFF image into the instance of image class.
    Using image As Aspose.Imaging.Image = Aspose.Imaging.Image.Load("D:\animation.gif")
    
    	' Create an instance of GIFF image class.
    	Dim gif As Aspose.Imaging.FileFormats.Gif.GifImage = TryCast(image, Aspose.Imaging.FileFormats.Gif.GifImage)
    
    	If gif Is Nothing Then
    		Return
    	End If
    
    	' Load an existing WebP image into the instance of WebPImage class.
    	Using webp As New Aspose.Imaging.FileFormats.Webp.WebPImage(image.Width, image.Height, Nothing)
    		' Loop through the GIFF frames
    		For i As Integer = 0 To gif.Blocks.Length - 1
    			' Convert GIFF block to GIFF Frame
    			Dim gifBlock As Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock = TryCast(gif.Blocks(i), Aspose.Imaging.FileFormats.Gif.Blocks.GifFrameBlock)
    			If gifBlock Is Nothing Then
    				Continue For
    			End If
    
    			' Create an instance of WebP Frame instance by passing GIFF frame to class constructor.
    			Dim block As New Aspose.Imaging.FileFormats.Webp.WebPFrameBlock(gifBlock) With { _
    				Key .Top = CShort(gifBlock.Top), _
    				Key .Left = CShort(gifBlock.Left), _
    				Key .Duration = CShort(gifBlock.ControlBlock.DelayTime) _
    			}
       
                            ' Add WebP frame to WebP image block list
    			webp.AddBlock(block)
    		Next
    
    		' Set Properties of WebP image.
    		webp.Options.AnimBackgroundColor = &Hff
    		'black
    		webp.Options.AnimLoopCount = 0
    		'infinity
    		webp.Options.Quality = 50
    		webp.Options.Lossless = False
    
    		' Save WebP image.
    		webp.Save("D:\saveAnimation.webp")
    	End Using
    End Using
    
    

    public by Geometry  949  0  5  0

    CalculateThreshold: Calculate binarization threshold for the given image.

    Calculate binarization threshold for the given image. Image to calculate binarization threshold for. Rectangle to calculate binarization threshold for. Returns binarization threshold. The method is used to calculate binarization threshold only. The threshold later may be applied to the image using image processing filter. Sourc
    /// <summary>
    /// Calculate binarization threshold for the given image.
    /// </summary>
    /// 
    /// <param name="image">Image to calculate binarization threshold for.</param>
    /// <param name="rect">Rectangle to calculate binarization threshold for.</param>
    /// 
    /// <returns>Returns binarization threshold.</returns>
    /// 
    /// <remarks><para>The method is used to calculate binarization threshold only. The threshold
    /// later may be applied to the image using <see cref="Threshold"/> image processing filter.</para></remarks>
    /// 
    /// <exception cref="UnsupportedImageFormatException">Source pixel format is not supported by the routine. It should be
    /// 8 bpp grayscale (indexed) image.</exception>
    /// 
    public static int CalculateThreshold(UnmanagedImage image, Rectangle rect)
    {
        if (image.PixelFormat != PixelFormat.Format8bppIndexed)
            throw new UnsupportedImageFormatException("Source pixel format is not supported by the routine.");
    
        int startX = rect.Left;
        int startY = rect.Top;
        int stopX = startX + rect.Width;
        int stopY = startY + rect.Height;
        int stopXM1 = stopX - 1;
        int stopYM1 = stopY - 1;
        int stride = image.Stride;
        int offset = stride - rect.Width;
    
        // differences and weights
        double ex, ey, weight, weightTotal = 0, total = 0;
    
        unsafe
        {
            // do the job
            byte* ptr = (byte*)image.ImageData.ToPointer();
    
            // allign pointer to the first pixel to process
            ptr += (startY * image.Stride + startX);
    
            // skip the first line for the first pass
            ptr += stride;
    
            // for each line
            for (int y = startY + 1; y < stopYM1; y++)
            {
                ptr++;
                // for each pixels
                for (int x = startX + 1; x < stopXM1; x++, ptr++)
                {
                    // the equations are:
                    // ex = | I(x + 1, y) - I(x - 1, y) |
                    // ey = | I(x, y + 1) - I(x, y - 1) |
                    // weight = max(ex, ey)
                    // weightTotal += weight
                    // total += weight * I(x, y)
    
                    ex = Math.Abs(ptr[1] - ptr[-1]);
                    ey = Math.Abs(ptr[stride] - ptr[-stride]);
                    weight = (ex > ey) ? ex : ey;
                    weightTotal += weight;
                    total += weight * (*ptr);
                }
                ptr += offset + 1;
            }
        }
    
        // calculate threshold
        return (weightTotal == 0) ? (byte)0 : (byte)(total / weightTotal);
    }

    external by Github  70  0  1  0

    I'm retired <a href=" http://www.assurscoot.com/virmax-israel.pdf#burly ">virmax ds male review</a> The military and intelligence communities are gathering up huge amounts of information from surveillance, but the image-processing capabilities of syst...

    I'm retired virmax ds male review The military and intelligence communities are gathering up huge amounts of information from surveillance, but the image-processing capabilities of systems have been limited by the compute capacity of CPUs and the budgets allotted to build systems and buy the application software to do face and voice recognition fr
    I'm retired <a href=" http://www.assurscoot.com/virmax-israel.pdf#burly ">virmax ds male review</a>  The military and intelligence communities are gathering up huge amounts of information from surveillance, but the image-processing capabilities of systems have been limited by the compute capacity of CPUs and the budgets allotted to build systems and buy the application software to do face and voice recognition from the mountains of data gathered up. At the moment, the processing of this voice and image data is still processed in large part by employees.
     
    
    

    external by Fabian Herzog  346  8  3  0

    Python implementation of the Discrete Radon Transform as described in "Applied Medical Image Processing" by W. Birkfellner, p. 344

    Python implementation of the Discrete Radon Transform as described in "Applied Medical Image Processing" by W. Birkfellner, p. 344: radon.py
    from scipy import misc
    import numpy as np
    import matplotlib.pyplot as plt
    
    def discrete_radon_transform(image, steps):
        R = np.zeros((steps, len(image)), dtype='float64')
        for s in range(1, steps+1):
            rotation = misc.imrotate(image, -(s-1)*180/steps, 'bilinear').astype('float64')
            R[:,s-1] = sum(rotation)
        return R
    
    # Read image as 64bit float gray scale
    image = misc.imread('shepplogan.png', flatten=True).astype('float64')
    radon = discrete_radon_transform(image, 220)
    
    plt.subplot(1, 2, 1), plt.imshow(image, cmap='gray')
    plt.xticks([]), plt.yticks([])
    plt.subplot(1, 2, 2), plt.imshow(radon, cmap='gray')
    plt.xticks([]), plt.yticks([])
    plt.show()
    
    
    • Public Snippets
    • Channels Snippets