Matlab“按比例缩小"一个带有平均值的向量 [英] Matlab "Scale Down" a Vector with Averages
本文介绍了Matlab“按比例缩小"一个带有平均值的向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
很难解释我要寻找的东西,我在Matlab中用n矩阵表示了一个图像,并且试图将其按比例缩小到4x4,就像对图像进行缩放(平均最近的值)一样
Quite hard to explain what I am looking for, I have an image represented as a m by n matrix in Matlab and I am trying to scale it down to 4x4 the same way an image would be scaled (average the nearest values)
例如
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
0 2 3 4 9 9 7 8
0 2 3 4 9 9 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 7
1 2 3 4 5 6 7 7
将成为
1.5 3.5 5.5 7.5
1.0 3.5 9.0 7.5
1.5 3.5 5.5 7.5
1.5 3.5 5.5 7.0
推荐答案
看起来像imresize
所提供的内容与您的预期略有不同.对于您的输入数据,将执行以下操作:
Looks like imresize
gives something slightly different from what you expected. For your input data, the following will work:
A = filter2([1 1; 1 1] / 4, X, 'same')
A = A(1:2:end, 1:2:end);
编辑:实际上,执行以下操作可能会更快:
EDIT: Actually, it's probably faster to do the following:
i = 1:2:size(A,1)-1;
j = 1:2:size(A,2)-1;
B = 0.25 * (A(i,j) + A(i+1,j) + A(i,j+1) + A(i+1,j+1));
这篇关于Matlab“按比例缩小"一个带有平均值的向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文