Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB降低了图像质量_Matlab_Axes_Imshow_Imread_Image Quality - Fatal编程技术网

MATLAB降低了图像质量

MATLAB降低了图像质量,matlab,axes,imshow,imread,image-quality,Matlab,Axes,Imshow,Imread,Image Quality,有一个原始图像test1.jpg。问题是在图像中显示轴并保持图像质量。 我正在运行以下代码,这些代码取自: 1获取的图像test2.jpg质量不好-它变得强烈像素化。 2水平轴大于图像 我尝试使用imwrite,但它无法在图像中保存轴 请告知,我如何解决这些问题。 我将非常感谢您的帮助 原始图像和获得的图像附在此邮件中。 另一个论坛上的一个人提出了解决横轴问题的代码,但最终图像的分辨率仍然很差。代码如下: img = imread('test1.jpg'); % define variabl

有一个原始图像test1.jpg。问题是在图像中显示轴并保持图像质量。 我正在运行以下代码,这些代码取自:

1获取的图像test2.jpg质量不好-它变得强烈像素化。 2水平轴大于图像

我尝试使用imwrite,但它无法在图像中保存轴

请告知,我如何解决这些问题。 我将非常感谢您的帮助

原始图像和获得的图像附在此邮件中。


另一个论坛上的一个人提出了解决横轴问题的代码,但最终图像的分辨率仍然很差。代码如下:

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')
请查看附件中获得的图像。

原则上,您可以使用imwrite执行任何操作。问题是您必须将所有轴写入图像数据的矩形中。此解决方案生成一个棕色遮罩,稍后用地图图像填充。您可以看到,由于最终输出中保留了一些棕色像素,因此存在一些不精确性。希望这能给你一个线索

% read map
img = imread('test1.jpg');
imgsize1 = size(img,1);  % size on screen
imgsize2 = size(img,2);
% create figure small enough for the screen
h = figure('Position',[0,0,imgsize2/3,imgsize1/3],'units','pixels');
a=axes('Position',[.2 .2 .7 .7]);
iptsetpref('ImshowAxesVisible','on');
% make a brown rectangle to mark map location in figure
pix = [];
pix(1,1,1) = 200;
pix(1,1,2) = 50;
pix(1,1,3) = 50;
img1 = uint8(repmat(pix,imgsize1,imgsize2,1));
imshow(img1,'Parent',a);
set(a,'Units','normalized','fontsize',13);
%iptsetpref('ImshowAxesVisible','on');
b=axes('Position',[.2 .1 .7 1e-12]);
set(b,'xlim',[0 1],'Color','none','fontsize',13);
c=axes('Position',[.09 .2 1e-12 .7 ]);
set(c,'ylim',[0 1],'YDir','reverse','Color','none','fontsize',13);
% set labels
xlabel(a,'Pixels')
xlabel(b,'Real distance (m)')
ylabel(a,'Pixels');
ylabel(c,'Real distance (m)');
% save brown map
saveas(h,'test2.jpg');
img2 = imread('test2.jpg');
% find map size in saved image
x = find(img2(:,700,1) == 200,1,'last')-find(img2(:,700,1) == 200,1);
y = find(img2(700,:,1) == 200,1,'last')-find(img2(700,:,1) == 200,1);
ratio = (imgsize1/x + imgsize2/y)/2;
% correct size of image
img3 = imresize(img2,ratio);
% find map coord in image
x3 = find(img3(:,1700,1) == 200,1);
y3 = find(img3(1700,:,1) == 200,1);
% fill brown rectangle with real map
img3(x3:x3+imgsize1-1,y3:y3+imgsize2-1,:) = img;
imwrite(img3,'test3.jpg')
figure;
imshow(img3);

问题是您无法创建大于屏幕大小的图形。因此,无论显示什么,都会进行下采样,然后在保存时,它会丢失分辨率。为了保存所有额外的图形,您必须创建一个图形句柄fig1=figure'Position',[0,0,imgsize1,imgsize2];然后将句柄saveasfig1保存为'test2.jpg';我在您编写代码时更改了代码,但结果是一样的。您是否尝试使用print而不是saveas?它做同样的事情,但有更多的选择来控制分辨率。您可以执行类似于print-djpeg-r600 filename.jpg的操作。-r选项以每英寸像素为单位指定输出的分辨率。如果图像仍然是像素化的,请进一步提高分辨率。
% read map
img = imread('test1.jpg');
imgsize1 = size(img,1);  % size on screen
imgsize2 = size(img,2);
% create figure small enough for the screen
h = figure('Position',[0,0,imgsize2/3,imgsize1/3],'units','pixels');
a=axes('Position',[.2 .2 .7 .7]);
iptsetpref('ImshowAxesVisible','on');
% make a brown rectangle to mark map location in figure
pix = [];
pix(1,1,1) = 200;
pix(1,1,2) = 50;
pix(1,1,3) = 50;
img1 = uint8(repmat(pix,imgsize1,imgsize2,1));
imshow(img1,'Parent',a);
set(a,'Units','normalized','fontsize',13);
%iptsetpref('ImshowAxesVisible','on');
b=axes('Position',[.2 .1 .7 1e-12]);
set(b,'xlim',[0 1],'Color','none','fontsize',13);
c=axes('Position',[.09 .2 1e-12 .7 ]);
set(c,'ylim',[0 1],'YDir','reverse','Color','none','fontsize',13);
% set labels
xlabel(a,'Pixels')
xlabel(b,'Real distance (m)')
ylabel(a,'Pixels');
ylabel(c,'Real distance (m)');
% save brown map
saveas(h,'test2.jpg');
img2 = imread('test2.jpg');
% find map size in saved image
x = find(img2(:,700,1) == 200,1,'last')-find(img2(:,700,1) == 200,1);
y = find(img2(700,:,1) == 200,1,'last')-find(img2(700,:,1) == 200,1);
ratio = (imgsize1/x + imgsize2/y)/2;
% correct size of image
img3 = imresize(img2,ratio);
% find map coord in image
x3 = find(img3(:,1700,1) == 200,1);
y3 = find(img3(1700,:,1) == 200,1);
% fill brown rectangle with real map
img3(x3:x3+imgsize1-1,y3:y3+imgsize2-1,:) = img;
imwrite(img3,'test3.jpg')
figure;
imshow(img3);