⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imtext.m

📁 彩色图像纹理提取的一种算法
💻 M
字号:
%Written by Adam Meadows
%function to give the texture of an image as a value
function texture = imtext(img, lightback, thresh)

% Image Texture, (Adam Meadows: ameadows@cs.ucr.edu)
% texture = imtext(img, lightback, thresh)
% 
% IMG is the input image
% LIGHTBACK is a flag specifying that the background is lighter than the foreground
% THRESH is a threshold to use when creating BW image (if 0, automatic)
%
% TEXTURE returns a numerical texture for the input IMG
%

%convert to grayscale image
I = rgb2gray(img);

%set correct thresh
if thresh == 0
    thresh = graythresh(I);
end

%convert to bw image to id object
bw = im2bw(I, thresh);

%swap if lightback
if lightback
    bw = swap(bw);
end

numPixels = 0;

%now loop through the binary image, only considering coordinates == 1
[r c] = size(I);
total = 0;
while (numPixels < 1000)
        
    i = floor(rand * (r-3)) + 2;
    j = floor(rand * (c-3)) + 2;

    if bw(i,j) == 1
        %compute std of this neighborhood (3x3 area centered at i,j)
        nhood = [I(i-1,j-1) I(i-1,j) I(i-1,j+1) I(i,j-1) I(i,j) I(i,j+1) I(i+1,j-1) I(i+1,j) I(i+1,j+1)];
        total = total + std(nhood);
        numPixels = numPixels + 1;
    end
        
end %end of outer loop

texture = total / numPixels;

%end of get_texture function

%==========================================================================
%==========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -