我怎样才能保存在MATLAB中更改的图像? [英] How can I save an altered image in MATLAB?

查看:124
本文介绍了我怎样才能保存在MATLAB中更改的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



另外,我只是在学习MATLAB,请在MATLAB中使用它。要温柔。这似乎应该是简单的,但我似乎无法做到这一点。

  im = imread('image.tif ); 
imshow(im);
rectangle('Position',[100,100,10,10]);
imwrite(im,'image2.tif');

即使我可以在图像上看到矩形,保存的图像也不会显示矩形。如何保存图像并显示矩形?
$ b $ FWIW,我已经试过了 saveas(),但是这给了我一个巨大的形象。有没有一种方法可以使用 saveas()并使保存的图像大小正确?

解决方案

实际上有一个错误MathWorks网站关于这个问题。太糟糕了,他们没有拼出一个真正的答案(因为,恕我直言,拿着你的显示器的统治者是不是一个真正的解决方案)。

使用 print 命令,您必须手动更改 -r 参数,直到保存图像的大小与输入图像的大小相匹配。 -r 参数指定保存的图像的DPI。由于大多数屏幕有不同的DPI,所以没有一个万能的解决方案。

  im = imread('image.tif ); 
f = figure,imshow(im,'Border','tight');
rectangle('Position',[100,100,10,10]);
print(f,'-r80','-dtiff','image2.tif');

使用上面的代码,调整 -r 参数,直到它看起来是正确的,voilà!


I want to read an image into MATLAB, draw a rectangle on it, and then save the image.

Also, I'm just learning MATLAB--please be gentle. It seems like it should be simple, but I can't seem to do it.

im = imread('image.tif');
imshow(im);
rectangle('Position', [100, 100, 10, 10]);
imwrite(im, 'image2.tif');

Even though I can see the rectangle on the image, the saved image does not display the rectangle. How can I save the image and have the rectangle show up?

FWIW, I've already tried saveas(), but that gives me a HUGE image. Is there a way to use saveas() and make the saved image the correct size?

解决方案

There's actually a bug at The MathWorks site about this issue. Too bad they don't spell out a real answer (as, IMHO, holding up a ruler to your monitor is not a real solution).

Using the print command, you must manually change the -r parameter until the size of the saved image matches the size of the input image. The -r parameter specifies the DPI of the saved image. Since most screens have different DPIs, there's no one-size-fits-all solution.

im = imread('image.tif');
f = figure, imshow(im, 'Border', 'tight');
rectangle('Position', [100, 100, 10, 10]);
print(f, '-r80', '-dtiff', 'image2.tif');

Use the code above, tweak the -r parameter until it looks right, and voilà!

这篇关于我怎样才能保存在MATLAB中更改的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆