Mathematica如果把图片导出成动态的gif格式?

2024-02-04 01:32

本文主要是介绍Mathematica如果把图片导出成动态的gif格式?,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这里的例子一定是针对很久以前的版本的Mathematica的, 现在的版本, Export可以直接导出为动态GIF.


</pre><pre code_snippet_id="376694" snippet_file_name="blog_20140604_2_4627778" name="code" class="plain">自定义函数:
</pre><pre code_snippet_id="376694" snippet_file_name="blog_20140604_4_7724677" name="code" class="plain">ManToGif[man_, name_String, step_Integer] :=Export[name <> ".gif",Import[Export[name <> Which[$OperatingSystem == "MacOSX", ".mov", $OperatingSystem == "Windows", ".avi"],man],"ImageList"][[1 ;; -1 ;; step]]]


导出的用法和实例:

man = Manipulate[ContourPlot[q1/Norm[{x, y} - p[[1]]] + q2/Norm[{x, y} - p[[2]]], {x, -2, 2}, {y, -2, 2}, Contours -> 20, PlotRangePadding -> 0, Frame -> False, PlotPoints -> 40, ImageSize -> 230, ColorFunction -> "DarkRainbow"], {{q1, -1}, -3, 3}, {{q2, 2}, -3, 3}, {{p, {{-1, 0}, {1, 0}}}, {-1, -1}, {1, 1}, Locator}, Deployed -> True, FrameMargins -> 0];

ManToGif[man, "charge", 2]


通过改变绘制图片的某个参数,得到动态的效果,然后导出成gif,

这在Mathematica中是不直接支持的. 


但是可以通过Import, Export的方式, 把动态图片的帧导出到视频格式的文件中, 再导入Mathematica中, 然后重导出最终生成gif格式

http://community.wolfram.com/groups/-/m/t/86994;jsessionid=F81DC17EA304180AFB319A45B4E93E9A.wlp1?p_p_auth=83wbyBRj

Showcasing Manipulate[…] via .GIF animations

GROUPS:
Mathematica,  Wolfram Community,  Dynamic Interactivity,  Graphics and Visualization,  Import and Export
When we create Manipulate or Animate and would like to showcase them on Wolfram Community site, a cool way is to make an animated GIF file of it. It would be also great if this GIF file could contain motion of controls, so people can see what they do. We can apply Export function to Manipulate with .AVI or .MOV or .FLV formats. This will make a movie that can show all motions of controls and content of Manipulate. But from a movie to a GIF there are just a few steps. This function below does these steps. It basically exports Manipulate to a movie, imports it as “ImageList”, and then exports it again as a GIF. Because Mac and Windows have different native movie formats we need to auto-detect them. The result of the function is two files – one is a movie and another is an animated GIF saved in default directory. Here is the legend for arguments:
  • man - variable representing Manipulate
  • name - pure name of the file without any extension
  • step - which every frame to pick: 1 - original no compression, 2 – every 2nd compress twice, etc. 

ManToGif [ man _ name _ String step _ Integer :=
  Export [ name  < ".gif" ,
   Import [
     Export [ name  < Which [ $OperatingSystem  ==  "MacOSX" ".mov" $OperatingSystem  ==  "Windows" ".avi" ] ,
      man ] ,
     "ImageList" ] [ [ ; - ; step ] ]
   ]
Let’s see how it works on an example. Here is a Manipulate with 4 controls: 2 sliders and 2 locators. 
man  Manipulate [ ContourPlot [
     q1 / Norm [ { x y p [ [ 1 ] ] q2 / Norm [ { x y p [ [ 2 ] ] ] { x - 2
      2 } { y - 2 2 } Contours  ->  20 PlotRangePadding  ->  0
     Frame  ->  False PlotPoints  ->  40 ImageSize  ->  230
     ColorFunction  ->  "DarkRainbow" ] { { q1 - 1 } - 3 3 } { { q2 2 } - 3
     3 } { { p { { - 1 0 } { 1 0 } } } { - 1 - 1 } { 1 1 } Locator }
    Deployed  ->  True FrameMargins  ->  0 ] ;
Here is the result of the function:
ManToGif [ man "charge" 2 ]



Any suggestions how we can improve this function?
  • To make it work faster
  • To make smaller .GIFs
  • Any other way… 

P.S. - A few things to note:
  • Control the screen size of GIF by controlling size of Manipulate content.
  • The smaller the screen size, the smaller the byte size.
  • By default Export will generate an animation by running the Manipulate through one Autorun cycle.
  • AutorunSequencing is used when a Manipulate expression is exported using Export to a dynamic format.
  • Use AutorunSequencing to specify how autorun should use the controls provided.
  • When a Manipulate output containing explicit bookmarks is exported to a video animation format using Export, the resulting video will be one cycle through the sequence generated by Animate Bookmarks.


    这篇关于Mathematica如果把图片导出成动态的gif格式?的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



    http://www.chinasem.cn/article/676007

    相关文章

    SpringBoot基于配置实现短信服务策略的动态切换

    《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

    关于MongoDB图片URL存储异常问题以及解决

    《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

    python实现svg图片转换为png和gif

    《python实现svg图片转换为png和gif》这篇文章主要为大家详细介绍了python如何实现将svg图片格式转换为png和gif,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录python实现svg图片转换为png和gifpython实现图片格式之间的相互转换延展:基于Py

    使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)

    《使用Python从PPT文档中提取图片和图片信息(如坐标、宽度和高度等)》PPT是一种高效的信息展示工具,广泛应用于教育、商务和设计等多个领域,PPT文档中常常包含丰富的图片内容,这些图片不仅提升了... 目录一、引言二、环境与工具三、python 提取PPT背景图片3.1 提取幻灯片背景图片3.2 提取

    Python实现图片分割的多种方法总结

    《Python实现图片分割的多种方法总结》图片分割是图像处理中的一个重要任务,它的目标是将图像划分为多个区域或者对象,本文为大家整理了一些常用的分割方法,大家可以根据需求自行选择... 目录1. 基于传统图像处理的分割方法(1) 使用固定阈值分割图片(2) 自适应阈值分割(3) 使用图像边缘检测分割(4)

    HTML5表格语法格式详解

    《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab

    C#实现将Excel表格转换为图片(JPG/ PNG)

    《C#实现将Excel表格转换为图片(JPG/PNG)》Excel表格可能会因为不同设备或字体缺失等问题,导致格式错乱或数据显示异常,转换为图片后,能确保数据的排版等保持一致,下面我们看看如何使用C... 目录通过C# 转换Excel工作表到图片通过C# 转换指定单元格区域到图片知识扩展C# 将 Excel

    JS+HTML实现在线图片水印添加工具

    《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

    使用Node.js制作图片上传服务的详细教程

    《使用Node.js制作图片上传服务的详细教程》在现代Web应用开发中,图片上传是一项常见且重要的功能,借助Node.js强大的生态系统,我们可以轻松搭建高效的图片上传服务,本文将深入探讨如何使用No... 目录准备工作搭建 Express 服务器配置 multer 进行图片上传处理图片上传请求完整代码示例

    MySQL中动态生成SQL语句去掉所有字段的空格的操作方法

    《MySQL中动态生成SQL语句去掉所有字段的空格的操作方法》在数据库管理过程中,我们常常会遇到需要对表中字段进行清洗和整理的情况,本文将详细介绍如何在MySQL中动态生成SQL语句来去掉所有字段的空... 目录在mysql中动态生成SQL语句去掉所有字段的空格准备工作原理分析动态生成SQL语句在MySQL