?? imtext.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
%==========================================================================
%==========================================================================
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -