在Matlab中更改图像画布大小 [英] Change image canvas size in Matlab

查看:2846
本文介绍了在Matlab中更改图像画布大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在画布/人物中有一张照片,我希望在不调整照片大小的情况下增加画布/图形的高度和宽度(例如,在更大的画布中显示图像)。我该怎么办?

I have a photo in a canvas/figure and I wish to increase the canvas/figure height and width without resizing the photo (e.g, display the image in a bigger "canvas"). How can I do it?

谢谢。

推荐答案

借用Luis Mendo在上述评论中的回答,使用 padarray 。鉴于您的图像存储在 im 中,您可以这样称呼它:

Borrowing from Luis Mendo's answer in the above comments, use padarray. You would call it like so, given that your image is stored in im:

out = padarray(im, [rows cols], padval, 'both');

rows cols 确定要在图像中填充的像素边框,这与两个标志一致。 padval 是您在增加画布大小时要放置在边框上的值。您可以执行任何符合图像类型的值。例如,您可以执行 0 表示黑色, 255 表示白色, 128 灰色等等。例如,如果要为行创建10像素宽的边框,为灰色列创建5像素宽的边框,请执行以下操作:

rows and cols determine the pixel border you want to pad in your image, which coincides with the both flag. padval is the value you want to place on the border when you're increasing the canvas size. You can either do any value you want that conforms to the type of your image. For example, you can do 0 for black, 255 for white, 128 for gray and so on. For example, if you wanted to do a 10 pixel wide border for the rows and a 5 pixel wide border for your columns in gray, do this:

out = padarray(im, [10 5], 128, 'both');

这是一个加载在 onion.png 图像存储在MATLAB的系统路径中:

Here's an example loading in the onion.png image stored in MATLAB's system path:

im = imread('onion.png');
out = padarray(im, [10 5], 128, 'both');
imshow(out);

这是我得到的:

如您所见,在图像开始(顶部)和之后(底部)之前,图像的行用10像素灰色边框填充。同样,在图像开始(左)和之后(右)之前,图像的列用5像素灰色边框填充。

As you can see, the rows of your image are padded with a 10 pixel gray border before the start of the image (top) and after (bottom). Similarly, the columns of your image are padded with a 5 pixel gray border before the start of the image (left) and after (right).

只需调整行和你想要适合你的目的的列和格雷德尔强度。

Simply adjust the rows and columns and graylevel intensity you want to suit your purposes.

这篇关于在Matlab中更改图像画布大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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