MATLAB会降低图像质量

时间:2019-04-02 09:43:32

标签: matlab axes imshow imread image-quality

有一个原始图像test1.jpg。问题是要在图像中显示轴并保持图像质量。 我正在运行以下来自matlab, multiple axes or scales for image pixels and real distance的代码:

img = imread('test1.jpg');

% define variables
imgsize1 = size(img,1);  % size on screen
imgsize2 = size(img,2);
xreal = 1;      % meter
yreal = 1;      % meter

% create figure
figure('Position',[0,0,imgsize1,imgsize2]);

% pixel axes and actual plot
a=axes('Position',[.2 .2 .7 .7]);
set(a,'Units','normalized');
iptsetpref('ImshowAxesVisible','on');
imshow(img,'Parent',a);

% real world axis (below)
b=axes('Position',[.2 .1 .7 1e-12]);
set(b,'Units','normalized');
set(b,'Color','none');
set(b,'xlim',[0 xreal]);

% real world axis (left)
c=axes('Position',[.09 .2 1e-12 .7 ]);
set(c,'Units','normalized');
set(c,'Color','none');
set(c,'ylim',[0 yreal],'YDir','reverse');

% set labels
xlabel(a,'Pixels')
xlabel(b,'Real distance (m)')
ylabel(a,'Pixels');
ylabel(c,'Real distance (m)');
saveas(gcf,'test2.jpg');

1)所获得的图像test2.jpg质量较差-像素化强烈。 2)水平轴大于图像。

我尝试使用imwrite,但是它不会在图像中保存轴。

请告知,我该如何解决这些问题。 我将不胜感激。

原始图像和获得的图像都附在此消息上。 original image

obtained image

2 个答案:

答案 0 :(得分:1)

enter image description here原则上,您可以使用imwrite进行所需的操作。问题是您必须将所有轴都写入图像数据的矩形中。此解决方案将制作一个棕色的蒙版,稍后将其填充地图图像。您会看到那里存在一些不准确性,因为最终输出中仍然保留了一些棕色像素。希望这能给您带来帮助。

receiveNoWait

答案 1 :(得分:0)

另一个论坛上的一个人提出了解决有关水平轴问题的代码,但是最终图像的分辨率仍然很差。这是代码:

img = imread('test1.jpg');

% define variables
imgsize1 = size(img,1);  % size on screen
imgsize2 = size(img,2);
xreal = 1;      % meter
yreal = 1;      % meter

% create figure
h = figure(); % !!!


% pixel axes and actual plot
a=axes('Position',[.2 .2 .7 .7]);
set(a,'Units','normalized');
iptsetpref('ImshowAxesVisible','on');

im = image(img); % !!!

% real world axis (below)
b=axes('Position',[.2 .1 .7 0]);
set(b,'Units','normalized');
set(b,'Color','none');
set(b,'xlim',[0 xreal]);

% real world axis (left)
c=axes('Position',[.09 .2 1e-12 .7 ]);
set(c,'Units','normalized');
set(c,'Color','none');
set(c,'ylim',[0 yreal],'YDir','reverse');

% set labels
xlabel(a,'Pixels')
xlabel(b,'Real distance (m)')
ylabel(a,'Pixels');
ylabel(c,'Real distance (m)');

print('test4','-djpeg','-r300')

请在附件中找到获得的图像。obtained image