在MATLAB中填充图像 [英] Padding an image in MATLAB
本文介绍了在MATLAB中填充图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的图片大小为61x56,我想将图片填充为392x392。
I have an image of size 61x56 and I want to pad the image to size 392x392.
我正在尝试使用 padarray
但由于我得到一个非整数值,我无法做到这一点。谁能帮我这个。非常感谢!我附上了我想要做的事情。
I am trying to use padarray
but since I get a non-integer value I am unable to do this. Can anyone help me with this. Thanks a lot! I have attached what I want to do below.
K = imread('test.jpg');
K = rgb2gray(K);
[m n] = size(K);
p = 392;
q = 392;
K_pad = padarray(K, [(p-m)/2 (q-n)/2], 'replicate');
推荐答案
你可以划分你的 padarray
两个电话中的指令:
You can divide your padarray
instruction in two calls:
K_pad = padarray(K, [floor((p-m)/2) floor((q-n)/2)], 'replicate','post');
K_pad = padarray(K_pad, [ceil((p-m)/2) ceil((q-n)/2)], 'replicate','pre');
但是你可能想检查图像角落里发生了什么,看它是否正常你想用它做什么。
But you may want to check what is happening in the corners of the image to see if it is ok with what you want to do with it.
这篇关于在MATLAB中填充图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文