MATLAB - 将图像写入 eps 文件

发布于 2024-08-25 18:26:30 字数 1035 浏览 2 评论 0原文

在 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) ;

但是我得到了:

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

错误==> Study_weaker 122
imshow(img,'border','tight',... %# 在没有
的图形窗口中显示
191 error(eid,'%s 需要 Java 才能运行。',upper(mfilename));

我该如何修复它?

In MATLAB, how do you write a matrix into an image of EPS format?

It seems imwrite does not support EPS.

Convert is not working on the Linux server I am using:

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

Why?


I tried gnovice's idea under terminal mode:

    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) ;

However I got:

??? Error using ==> imshow at 191
IMSHOW requires Java to run.

Error in ==> study_weaker at 122
imshow(img,'border','tight',... %# Display in a figure window without

191 error(eid,'%s requires Java to run.',upper(mfilename));

How can I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

耶耶耶 2024-09-01 18:26:30

一种可能的解决方案是使用 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 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

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

One possible solution is to plot your image using IMSHOW, then print the entire figure as a .eps using PRINT:

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

One drawback to this solution is that if the image is too big to fit on the screen, IMSHOW will shrink it to fit, which will reduce the on-screen resolution of the image. However, you can adjust the final resolution of the saved image using the -r<number> option for the PRINT function. For example, you can print your figure as an Encapsulated Level 2 Color PostScript with a resolution of 300 dpi by doing the following:

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

EDIT: If you are unable to use IMSHOW (either because you don't have the Image Processing Toolbox or because you are using a MATLAB mode that doesn't allow it), here is an alternative way to create and print the figure:

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

You can also take a look at this documentation to see how printing works without a display.

久伴你 2024-09-01 18:26:30

它应该可以使用 imwrite 来工作。不过,您必须添加颜色图才能使其正常工作。

然而,检查帮助页面我发现不可能使用 imwrite 写入 EPS 文件。

It should work using imwrite. You would have to add a colormap for it to work though.

However, ckecking the help pages I see that it is NOT possible to use imwrite to write an EPS file.

心碎无痕… 2024-09-01 18:26:30

以下代码可以帮助您将 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

Following code may help you to convert png file to 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文