简体   繁体   English

无法识别的函数或变量“自适应阈值”

[英]Unrecognized function or variable 'adaptivethreshold'

I am getting the following error message in Matlab "Unrecognized function or variable 'adaptivethreshold'" when every time I want to use Adaptive Threshold function每次我想使用自适应阈值函数时,我都会在 Matlab 中收到以下错误消息“无法识别的函数或变量‘adaptivethreshold’”

clear;close all;
im1=imread('page.png');
im2=imread('tshape.png');
bwim1=adaptivethreshold(im1,11,0.03,0);
bwim2=adaptivethreshold(im2,15,0.02,0);
subplot(2,2,1);
imshow(im1);
subplot(2,2,2);
imshow(bwim1);
subplot(2,2,3);
imshow(im2);
subplot(2,2,4);
imshow(bwim2);

those coding from https://www.mathworks.com/matlabcentral/fileexchange/8647-local-adaptive-thresholding来自https://www.mathworks.com/matlabcentral/fileexchange/8647-local-adaptive-thresholding的那些编码

You should open MATLAB editor inside a folder containing all files: adaptivethreshold.m , page.png , testadaptivethreshold.m , tshape.png and run your script testadaptivethreshold .您应该在包含所有文件的文件夹中打开 MATLAB 编辑器: adaptivethreshold.mpage.pngtestadaptivethreshold.mtshape.png并运行您的脚本testadaptivethreshold

在此处输入图像描述

Or, you can copy-paste the function definition below the script as follows and make sure also that the images are in the same folder or MATLAB search path.或者,您可以按如下方式复制粘贴脚本下方的函数定义,并确保图像位于同一文件夹或 MATLAB 搜索路径中。

clear;close all;
im1=imread('page.png');
im2=imread('tshape.png');
bwim1=adaptivethreshold(im1,11,0.03,0);
bwim2=adaptivethreshold(im2,15,0.02,0);
subplot(2,2,1);
imshow(im1);
subplot(2,2,2);
imshow(bwim1);
subplot(2,2,3);
imshow(im2);
subplot(2,2,4);
imshow(bwim2);


function bw=adaptivethreshold(IM,ws,C,tm)
    %ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the
    %foreground from the background with nonuniform illumination.
    %  bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local 
    %   threshold mean-C or median-C to the image IM.
    %  ws is the local window size.
    %  tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.
    %
    %  Contributed by Guanglei Xiong (xgl99@mails.tsinghua.edu.cn)
    %  at Tsinghua University, Beijing, China.
    %
    %  For more information, please see
    %  http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

    if (nargin<3)
        error('You must provide the image IM, the window size ws, and C.');
    elseif (nargin==3)
        tm=0;
    elseif (tm~=0 && tm~=1)
        error('tm must be 0 or 1.');
    end

    IM=mat2gray(IM);

    if tm==0
        mIM=imfilter(IM,fspecial('average',ws),'replicate');
    else
        mIM=medfilt2(IM,[ws ws]);
    end
    sIM=mIM-IM-C;
    bw=imbinarize(sIM,0);
    bw=imcomplement(bw);
end

And here is how it shows the output:以下是它显示输出的方式:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM