0

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 = 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
Community
  • 1
  • 1
Jessy
  • 15,321
  • 31
  • 83
  • 100

2 Answers2

0

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)])
arun
  • 105
  • 6
0

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.

MPG
  • 835
  • 4
  • 10
  • thanks the image are more clear now :) ...but the "+" which I used to plot the xy coordinate, which I set in blue color, turn into black color when I saved it. Why? – Jessy Jul 07 '10 at 13:53