注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

王小二的博客

勤俭以修身,淡泊以明志

 
 
 

日志

 
 

使用 Matlab 将图片批量转化为eps格式(for TeX user)  

2012-08-28 09:35:46|  分类: 排版软件 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
前两天刚刚在 Ubutnu 下把 TeX 的中文支持装好。
  需要批量转换图片,当时不知道那些工具该怎么用,于是自己在 Matlab 下编写了一个程序,可将 Matlab 中 imread() 函数所支持的所有格式的图片均转化为 eps 格式。程序清单附在最后面。
  此程序仅供参考,转化出来的效果还可以。就是 Matlab 用起来本来就很慢,所以这个程序也就不会很快。另外请注意,此程序是在 Linux 操作系统下的 Matlab 上运行的,如果你想换到 Windows 下的 Matlab 上面用,需要做一些修改:将目录路径中的斜杠“/”换成反斜杠“\”,我没有在 Windows 下调试过,不过应该没问题。
function status = image2eps(directory)
%
%      --->       M-file name: IMAGE2EPS.M       <---
%      --->  Created environment: Matlab R2007b  <---
%
% IMAGE2EPS(DIRECTORY) Create EPS files movie from images.

%    STATUS = IMAGE2EPS() converts all image files in current directory
%    into EPS files.
%
%    STATUS = IMAGE2EPS(DIRECTORY) converts all image files in the directory
%    appointed by DIRECTORY into EPS files.
%
%    The function will always return a zero, and the EPS files newly
%    created will be saved in the directory where their source images come
%    from.
%
%    This function would be quite useful while you are using LaTeX and want
%    to insert an image into your TeX document. Current supported image
%    file formats here:
%
%    | .bmp | .cur | .gif | .hdf | .ico | .jpeg | .jpg | .pbm | .pcx | .pgm |
%    | .png | .ppm | .ras | .xwd | .tif | .tiff |
%
%    Letters in extensions can be either big or small.
%
%    See also imread, imshow, print.
%
%    Programmed by Long Chao, Beihang Univsrsity
%                     QQ:                 409053987
%                     E-mail and/or MSN:  cshishaliu@163.com
%    ALL RIGHTS OPEN
%    Monday, April 14. , 2008
%
% --- Get name of the file in directory appointed ----
if nargin == 0
    fileinfo = dir;
    directory = '.\';
else
    fileinfo = dir(directory);
end
if directory(end) ~= '\'
    directory = [directory,'\'];
end
filename = struct2cell(fileinfo);
filename = filename(1,3:end)';
% --- Get supported file formats ---
% Get the formats whose extension is made up of three letters
supportformats3 = ['.bmp';'.cur';'.gif';'.hdf';'.ico';'.jpg';'.pbm';'.pcx';'.pgm';'.png';'.ppm';'.ras';'.xwd';'.tif'];
% Get the formats whose extension is made up of three letters
supportformats4 = ['.jpeg';'.tiff'];
% --- Convert images in the directory ---
figure; % Open a new figure
for i = 1:size(filename,1);
    name = [directory,char(filename(i))];
    if size(name,2) >= 4  % File name was required to be not less than 4 letters
       
        % Find if the current file is supported and has an extension made up of THREE SMALL letters
        if max( sum( (( ones(size(supportformats3,1),1) * name((end-3):end) ) == supportformats3)' ) ) == 4
            imshow(imread(char(name)));
            print('-depsc',name(1:(end-4)));
        end
       
        % Find if the current file is supported and has an extension made up of THREE BIG letters
        if max( sum( (( ones(size(supportformats3,1),1) * (name((end-3):end) + [0,32,32,32]) ) == supportformats3)' ) ) == 4
            imshow(imread(char(name)));
            print('-depsc',name(1:(end-4)));
        end
       
        % Find if the current file is supported and has an extension made up of FOUR SMALL letters
        if max( sum( (( ones(size(supportformats4,1),1) * name((end-4):end) ) == supportformats4)' ) ) == 4
            imshow(imread(char(name)));
            print('-depsc',name(1:(end-5)));
        end
       
        % Find if the current file is supported and has an extension made up of FOUR BIG letters
        if max( sum( (( ones(size(supportformats4,1),1) * (name((end-4):end) + [0,32,32,32,32]) ) == supportformats4)' ) ) == 4
            imshow(imread(char(name)));
            print('-depsc',name(1:(end-5)));
        end
    end
end
status = 0;  % Return a zero
close; % Close the figure opened
详情参见
http://forum.ubuntu.org.cn/viewtopic.php?t=115361&highlight=
  评论这张
 
阅读(883)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017