【问题标题】:MATLAB Anonymous function handle to use with NLFILTER与 NLFILTER 一起使用的 MATLAB 匿名函数句柄
【发布时间】:2011-11-07 10:46:26
【问题描述】:

我有以下函数计算 GLCM,然后计算给定的统计参数。我想将此函数传递给 NLFILTER 来计算整个图像(在小窗口中,例如卷积)。我已经将 NLFILTER 设置为使用并行计算工具箱运行,所以我真的很想转换下面的函数:

function [s]=glcm(img,meth)
%GLCM calculates a Gray Level Co-occurence matrix & stats for a given sub
% image.
% Input: Sub Image (subI) and a method (meth)...
%        'Contrast','Correlation','Energy','Homogeneity'
%

subI=uint8(img);
m=graycomatrix(img,'Offset',[0 1],'NumLevels',8,'Symmetric',true);

if meth(1:3)=='con'
    s=graycoprops(m,'Contrast');
    s=s.Contrast;
elseif meth(1:3)=='cor'
    s=graycoprops(m,'Correlation');
    s=s.Correlation;
elseif meth(1:3)=='ene'
    s=graycoprops(m,'Energy');
    s=s.Energy;        
elseif meth(1:3)=='hom'
    s=graycoprops(m,'Homogeneity');
    s=s.Homogeneity;
else
    error('No method selected.')
end

我真的很困惑如何将其转换为适合与 NLFILTER 一起使用的函数句柄。有任何想法吗?谢谢。

【问题讨论】:

    标签: image matlab image-processing textures glcm


    【解决方案1】:

    创建匿名函数时,可以在函数定义中传递额外的静态参数:

    %# define the method
    method = 'ene';
    
    %# create an anonymous function that takes one input argument
    %# and that passes the `method` defined above
    %# as an argument to glcm
    anonFcn = @(x)glcm(x,method);
    
    %# apply to your image with whatever window size you're interested in
    out = nlfilter(yourImage,windowSize,anonFcn)
    

    【讨论】:

    • 正是我想要的,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-14
    • 1970-01-01
    • 2018-10-30
    相关资源
    最近更新 更多