7

在 MATLAB 中,如何将矩阵写入EPS格式的图像?

好像imwrite不支持EPS。

Convert 在我使用的 Linux 服务器上不起作用:

$ convert exploss_stumps.jpg exploss_stumps.eps
convert: missing an image filename `exploss_stumps.eps' @ convert.c/ConvertImageCommand/2838

为什么?


我在终端模式下尝试了gnovice的想法:

    figH = figure('visible','off') ;
imshow(img,'border','tight',...      %# Display in a figure window without
        'InitialMagnification',100);  %#    a border at full magnification
print(strcat(filepath,'/', dataset,'_feature_',num2str(j), '.eps'),'-depsc2');
    close(figH) ;

但是我得到了:

???在 191 使用 ==> imshow 时出错
IMSHOW 需要 Java 才能运行。

==> study_weaker 在 122
处出错 imshow(img,'border','tight',... %# 在图形窗口中显示没有

191 错误(eid,'%s 需要 Java 才能运行。',upper(mfilename) );

我该如何解决?

4

3 回答 3

7

一种可能的解决方案是使用IMSHOW绘制图像,然后使用PRINT将整个图形打印为 .eps :

img = imread('peppers.png');         %# A sample image
imshow(img,'Border','tight',...      %# Display in a figure window without
       'InitialMagnification',100);  %#    a border at full magnification
print('new_image.eps','-deps');      %# Print the figure as a B&W eps

此解决方案的一个缺点是,如果图像太大而无法在屏幕上显示,IMSHOW会将其缩小以适应,这将降低图像的屏幕分辨率。-r<number>但是,您可以使用PRINT 功能选项调整保存图像的最终分辨率。例如,您可以通过执行以下操作将您的图形打印为分辨率为 300 dpi 的 Encapsulated Level 2 Color PostScript:

print('new_image.eps','-depsc2','-r300');

编辑:如果您无法使用IMSHOW(因为您没有图像处理工具箱,或者因为您使用的 MATLAB 模式不允许使用它),这里是创建和打印图形的另一种方法:

img = imread('peppers.png');      %# A sample image
imagesc(img);                     %# Plot the image
set(gca,'Units','normalized',...  %# Set some axes properties
        'Position',[0 0 1 1],...
        'Visible','off');
set(gcf,'Units','pixels',...      %# Set some figure properties
        'Position',[100 100 size(img,2) size(img,1)]);
print(gcf,'new_image.eps','-depsc2','-r300');  %# Print the figure

您还可以查看此文档以了解在没有显示器的情况下如何进行打印。

于 2010-03-19T16:04:30.410 回答
0

它应该使用 imwrite 工作。但是,您必须添加一个颜色图才能使其工作。

但是,查看帮助页面时,我发现无法使用 imwrite 来编写 EPS 文件。

于 2010-03-19T16:11:24.400 回答
0

以下代码可以帮助您将 png 文件转换为 eps。

fileName = 'FarmerStats'; % your FILE NAME as string

A = imread(fileName,'png');
set(gcf,'visible','off') %suppress figure
image(A);                
axis image               % resolution based on image
axis off                 % avoid printing axis 
set(gca,'LooseInset',get(gca,'TightInset')); % removing extra white space in figure
saveas(gcf,fileName,'epsc');   % save as COLOR eps file
于 2017-05-05T12:20:58.643 回答