Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我想显示一张图像并在其上绘制一些内容,然后将其另存为与原始图像大小相同的图像。我的MATLAB代码是:
figH = figure('visible','off'); imshow(I); hold on; % plot something saveas(figH,'1','jpg'); close(figH); 但是,生成的图像“ 1.jpg”已保存了绘图中的非图像区域以及图像。我怎么解决这个问题? 回答: 您的新图像大于原始图像的原因是因为SAVEAS功能保存了整个图形窗口 ,而不是保存了轴的内容(显示图像的位置)。 您的问题与另一个SO问题非常相似,因此我将首先指出这些答案包含的两个主要选项:
I = imread('peppers.png'); %# Load a sample image imshow(I); %# Display it [r,c,d] = size(I); %# Get the image size set(gca,'Units','normalized','Position',[0 0 1 1]); %# Modify axes size set(gcf,'Units','pixels','Position',[200 200 cr]); %# Modify figure size hold on; plot(100,100,'r*'); %# Plot something over the image f = getframe(gcf); %# Capture the current window imwrite(f.cdata,'image2.jpg'); %# Save the frame data 输出图像image2.jpg应带有红色星号,并且其尺寸应与输入图像相同。 更多&回答... |
![]() |
![]() |