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

    相关文章

    基于C#实现PDF转图片的详细教程

    《基于C#实现PDF转图片的详细教程》在数字化办公场景中,PDF文件的可视化处理需求日益增长,本文将围绕Spire.PDFfor.NET这一工具,详解如何通过C#将PDF转换为JPG、PNG等主流图片... 目录引言一、组件部署二、快速入门:PDF 转图片的核心 C# 代码三、分辨率设置 - 清晰度的决定因

    Python从Word文档中提取图片并生成PPT的操作代码

    《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

    使用Python实现无损放大图片功能

    《使用Python实现无损放大图片功能》本文介绍了如何使用Python的Pillow库进行无损图片放大,区分了JPEG和PNG格式在放大过程中的特点,并给出了示例代码,JPEG格式可能受压缩影响,需先... 目录一、什么是无损放大?二、实现方法步骤1:读取图片步骤2:无损放大图片步骤3:保存图片三、示php

    Android 缓存日志Logcat导出与分析最佳实践

    《Android缓存日志Logcat导出与分析最佳实践》本文全面介绍AndroidLogcat缓存日志的导出与分析方法,涵盖按进程、缓冲区类型及日志级别过滤,自动化工具使用,常见问题解决方案和最佳实... 目录android 缓存日志(Logcat)导出与分析全攻略为什么要导出缓存日志?按需过滤导出1. 按

    Qt中实现多线程导出数据功能的四种方式小结

    《Qt中实现多线程导出数据功能的四种方式小结》在以往的项目开发中,在很多地方用到了多线程,本文将记录下在Qt开发中用到的多线程技术实现方法,以导出指定范围的数字到txt文件为例,展示多线程不同的实现方... 目录前言导出文件的示例工具类QThreadQObject的moveToThread方法实现多线程QC

    SpringBoot集成EasyExcel实现百万级别的数据导入导出实践指南

    《SpringBoot集成EasyExcel实现百万级别的数据导入导出实践指南》本文将基于开源项目springboot-easyexcel-batch进行解析与扩展,手把手教大家如何在SpringBo... 目录项目结构概览核心依赖百万级导出实战场景核心代码效果百万级导入实战场景监听器和Service(核心

    使用Python开发一个Ditto剪贴板数据导出工具

    《使用Python开发一个Ditto剪贴板数据导出工具》在日常工作中,我们经常需要处理大量的剪贴板数据,下面将介绍如何使用Python的wxPython库开发一个图形化工具,实现从Ditto数据库中读... 目录前言运行结果项目需求分析技术选型核心功能实现1. Ditto数据库结构分析2. 数据库自动定位3

    shell脚本批量导出redis key-value方式

    《shell脚本批量导出rediskey-value方式》为避免keys全量扫描导致Redis卡顿,可先通过dump.rdb备份文件在本地恢复,再使用scan命令渐进导出key-value,通过CN... 目录1 背景2 详细步骤2.1 本地docker启动Redis2.2 shell批量导出脚本3 附录总

    Java使用Thumbnailator库实现图片处理与压缩功能

    《Java使用Thumbnailator库实现图片处理与压缩功能》Thumbnailator是高性能Java图像处理库,支持缩放、旋转、水印添加、裁剪及格式转换,提供易用API和性能优化,适合Web应... 目录1. 图片处理库Thumbnailator介绍2. 基本和指定大小图片缩放功能2.1 图片缩放的

    go动态限制并发数量的实现示例

    《go动态限制并发数量的实现示例》本文主要介绍了Go并发控制方法,通过带缓冲通道和第三方库实现并发数量限制,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面... 目录带有缓冲大小的通道使用第三方库其他控制并发的方法因为go从语言层面支持并发,所以面试百分百会问到