开发者

MATLAB - How to avoid a jagged image?

开发者 https://www.devze.com 2023-01-05 14:40 出处:网络
How do I avoid a jagged image in MATLAB? I have a 600 x 600 pixels image opened in MATLAB and do some processing on the image. However, when I save it, it looks so blurred and jagged. What should I d

How do I avoid a jagged image in MATLAB?

I have a 600 x 600 pixels image opened in MATLAB and do some processing on the image. However, when I save it, it looks so blurred and jagged. What should I do?

(This question is related to my previous question, MATLAB - How to plot x,y on an image and save?)

fid = fopen(datafile.txt);
A = textscan(fid,'%f%f%f'); %read data from the file
code = A{1};
xfix = 开发者_JAVA技巧A{2};
yfix = A{3};

for k=1:length(code)
    imagefile=code(k);
    rgb = imread([num2str(imagefile) '.jpg']);
    imshow(rgb);
    hold on;
    x = xfix2(k);
    y = yfix2(k);
    plot(x,y,'-+ b'); % plot x,y on the
    saveas(([num2str(imagefile) '.jpg'])) % Save the image with the same name as it open.
end
hold off


If it is just a resolution issue, perhaps using the print command (as listed below) with an explicit resolution option may fix it.

print(gcf,'-djpeg','-r600',[num2str(imagefile)])


My guess would be JPEG compression artifacts. JPEG isn't a great format for data with a lot of high frequency components. Have you tried turning the compression down? Like so:

imwrite(f.cdata,([num2str(imagefile) '.jpg']),'Quality',100);

The default for the quality parameter is only 75. That's plenty for a lot of cases, but you might need more.

0

精彩评论

暂无评论...
验证码 换一张
取 消