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

    相关文章

    Mysql常见的SQL语句格式及实用技巧

    《Mysql常见的SQL语句格式及实用技巧》本文系统梳理MySQL常见SQL语句格式,涵盖数据库与表的创建、删除、修改、查询操作,以及记录增删改查和多表关联等高级查询,同时提供索引优化、事务处理、临时... 目录一、常用语法汇总二、示例1.数据库操作2.表操作3.记录操作 4.高级查询三、实用技巧一、常用语

    springboot如何通过http动态操作xxl-job任务

    《springboot如何通过http动态操作xxl-job任务》:本文主要介绍springboot如何通过http动态操作xxl-job任务的问题,具有很好的参考价值,希望对大家有所帮助,如有错... 目录springboot通过http动态操作xxl-job任务一、maven依赖二、配置文件三、xxl-

    利用Python脚本实现批量将图片转换为WebP格式

    《利用Python脚本实现批量将图片转换为WebP格式》Python语言的简洁语法和库支持使其成为图像处理的理想选择,本文将介绍如何利用Python实现批量将图片转换为WebP格式的脚本,WebP作为... 目录简介1. python在图像处理中的应用2. WebP格式的原理和优势2.1 WebP格式与传统

    基于 HTML5 Canvas 实现图片旋转与下载功能(完整代码展示)

    《基于HTML5Canvas实现图片旋转与下载功能(完整代码展示)》本文将深入剖析一段基于HTML5Canvas的代码,该代码实现了图片的旋转(90度和180度)以及旋转后图片的下载... 目录一、引言二、html 结构分析三、css 样式分析四、JavaScript 功能实现一、引言在 Web 开发中,

    Python如何去除图片干扰代码示例

    《Python如何去除图片干扰代码示例》图片降噪是一个广泛应用于图像处理的技术,可以提高图像质量和相关应用的效果,:本文主要介绍Python如何去除图片干扰的相关资料,文中通过代码介绍的非常详细,... 目录一、噪声去除1. 高斯噪声(像素值正态分布扰动)2. 椒盐噪声(随机黑白像素点)3. 复杂噪声(如伪

    Python中图片与PDF识别文本(OCR)的全面指南

    《Python中图片与PDF识别文本(OCR)的全面指南》在数据爆炸时代,80%的企业数据以非结构化形式存在,其中PDF和图像是最主要的载体,本文将深入探索Python中OCR技术如何将这些数字纸张转... 目录一、OCR技术核心原理二、python图像识别四大工具库1. Pytesseract - 经典O

    Python实现精准提取 PDF中的文本,表格与图片

    《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

    C++ 函数 strftime 和时间格式示例详解

    《C++函数strftime和时间格式示例详解》strftime是C/C++标准库中用于格式化日期和时间的函数,定义在ctime头文件中,它将tm结构体中的时间信息转换为指定格式的字符串,是处理... 目录C++ 函数 strftipythonme 详解一、函数原型二、功能描述三、格式字符串说明四、返回值五

    Python基于微信OCR引擎实现高效图片文字识别

    《Python基于微信OCR引擎实现高效图片文字识别》这篇文章主要为大家详细介绍了一款基于微信OCR引擎的图片文字识别桌面应用开发全过程,可以实现从图片拖拽识别到文字提取,感兴趣的小伙伴可以跟随小编一... 目录一、项目概述1.1 开发背景1.2 技术选型1.3 核心优势二、功能详解2.1 核心功能模块2.

    Go语言如何判断两张图片的相似度

    《Go语言如何判断两张图片的相似度》这篇文章主要为大家详细介绍了Go语言如何中实现判断两张图片的相似度的两种方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 在介绍技术细节前,我们先来看看图片对比在哪些场景下可以用得到:图片去重:自动删除重复图片,为存储空间"瘦身"。想象你是一个