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

    相关文章

    hevc和H.264格式的区别

    HEVC(High Efficiency Video Coding)和H.264(也称为Advanced Video Coding,AVC)都是视频压缩标准,但它们之间存在一些显著的区别,主要集中在压缩效率、资源需求和兼容性方面。 压缩效率 HEVC,也被称为H.265,提供了比H.264更高的压缩效率。这意味着在相同的视频质量下,HEVC能够以大约一半的比特率进行编码,从而减少存储空间需求和

    JAVA读取MongoDB中的二进制图片并显示在页面上

    1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

    mathematica的使用

    因为做实验用到Bloom filter这一技术,Bloom filter里面的数学公式可以用来画图。 那么用什么画图软件比较好呢? 当然是Mathematica啦。 利用代码Plot[{y=x},{x,0,100}] 就可以画出比较好的图 简直nice

    在服务器上浏览图片

    @StarSky 2018-10-26 15:09 字数 15971 阅读 28 https://www.zybuluo.com/StarSky/note/1294871 来源 2018-09-27 线上服务器安装 imgcat Tool   2018-09-27 线上服务器安装 imgcat 0. 准备文件:iterm2_shell_integration.bash1. 在有权限

    【杂记-浅谈DHCP动态主机配置协议】

    DHCP动态主机配置协议 一、DHCP概述1、定义2、作用3、报文类型 二、DHCP的工作原理三、DHCP服务器的配置和管理 一、DHCP概述 1、定义 DHCP,Dynamic Host Configuration Protocol,动态主机配置协议,是一种网络协议,主要用于在IP网络中自动分配和管理IP地址以及其他网络配置参数。 2、作用 DHCP允许计算机和其他设备通

    BD错误集锦8——在集成Spring MVC + MyBtis编写mapper文件时需要注意格式 You have an error in your SQL syntax

    报错的文件 <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.yuan.dao.YuanUserDao"><!

    JavaWeb系列六: 动态WEB开发核心(Servlet) 上

    韩老师学生 官网文档为什么会出现Servlet什么是ServletServlet在JavaWeb项目位置Servlet基本使用Servlet开发方式说明快速入门- 手动开发 servlet浏览器请求Servlet UML分析Servlet生命周期GET和POST请求分发处理通过继承HttpServlet开发ServletIDEA配置ServletServlet注意事项和细节 Servlet注

    el-upload 上传图片及回显照片和预览图片,文件流和http线上链接格式操作

    <div v-for="(info, index) in zsjzqwhxqList.helicopterTourInfoList" :key="info.id" >编辑上传图片// oss返回线上地址http链接格式:<el-form-itemlabel="巡视结果照片":label-width="formLabelWidth"><el-upload:action="'http:

    OSG学习:LOD、数据分页、动态调度

    LOD(level of detail):是指根据物体模型的结点在显示环境中所处的位置和重要度,决定物体渲染的资源分配,降低非重要物体的面数和细节度,从而获得高效率的渲染运算。在OSG的场景结点组织结构中,专门提供了场景结点osg::LOD来表达不同的细节层次模型。其中,osg::LOD结点作为父节点,每个子节点作为一个细节层次,设置不同的视域,在不同的视域下显示相应的子节点。 数据分页:在城市

    PHP生成csv格式Excel,秒级别实现excel导出功能

    防止报超内存,兼容中文,兼容科学技术法。 爽。。。。很爽。。。。 /*** 告诉浏览器下载csv文件* @param string $filename*/public static function downloadCsv($data, $filename, $encoding = 'utf-8'){header("Content-type: text/csv");header("Conten