如何用矢量化计算图像块的方差 [英] How to calculate variance of an image patch with vectorization

查看:142
本文介绍了如何用矢量化计算图像块的方差的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个560 * 560 * 3的图像文件,我想将图像分成许多小的8 * 8补丁,然后计算每个补丁的方差。什么是使用Matlab或Octave计算每个图像块的方差的矢量化方法?

I have a 560*560*3 image file, I want to divide the image into many small 8*8 patches, then calculate variance of each patch. What is a vectorized way to calculate variance of each image patch with Matlab or Octave?

推荐答案

您可以使用 nfilter 功能:

  fun = @var;
  B = nlfilter(A, [8 8], fun);

顺便说一句,如果你想要3x3图像补丁,你可以使用 stdfilt 功能。剩下的就是在图像上应用一个正方形:

By the way, if you wanted 3x3 image patches, you could use stdfilt function . All that is left is to apply a square on the image:

  s = stdfilt(im);
  s = s.*s;

这篇关于如何用矢量化计算图像块的方差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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