Re: Laws' Textures and MATLAB



I am interested in texture and I couldn't find code for Laws texture
so I took a first cut at implementing a function.

I tested it on this image:
http://img.villagephotos.com/p/2006-4/1174390/5texture.jpg

BTW, you will need the image processing toolbox.
Also, I used as my reference this website:
http://public.lanl.gov/kelly/Notebook/laws.shtml

Here are some pieces of code:
%% create 1D masks
ks= [ ...
[1,4,6,4,1]; ... %L5
[-1,-2,0,2,1]; ... %E5
[-1,0,2,0,-1]; ... %S5
[-1 2 0 -2 1]; ... %W5
[1,-4,6,-4,1]; ... % R5
];
% stack of outer products
kstack = zeros(5,5,25);
k = 1;
for i = 1:5
for j= 1:5
kstack(:,:,k) = ks(i,:)' * ks(j,:);
k = k + 1;
end %for j= 1:5
end % for i=1:5

%% read in image and init variables
imgtxture = double(imread('C:\MATLAB701\work\texture\5texture.bmp') );
feats = zeros([size(imgtxture) 25]);
egy = @(x) sum(abs(x(:)));

%% prep normalize image
d = 15; % side of processing block
imnorm = conv2(imgtxture,kstack(:,:,1),'same');
imnormT = nlfilter(imnorm,[d d],egy);

%% fill in the feats array
feats(:,:,1) = imnormT;
for kfeat = 2:25
feats(:,:,kfeat) =
nlfilter(conv2(imgtxture,kstack(:,:,kfeat),'same'),[d d],egy);
feats(:,:,kfeat) = feats(:,:,kfeat)./imnormT;
end % for kfeat = 2:25

%% display the feats image in a tiled figure
nrows = 5;
ncols = 5;
dx = 1/ncols;
dy = 1/nrows;
ycorner = 0;
% adjust figure for each computer's display size
rootSize = get(0,'ScreenSize');
figpos = rootSize(1:2) + [50 50];
figdim = rootSize(3:4) - [100 150];
fh = figure;
set(fh,'Position',[figpos figdim]);
% display the images
k = 1;
for krow = 1:nrows
xcorner = 0;
for kcol = 1:ncols
subplot('Position',[xcorner ycorner dx dy]);
imshow(feats(:,:,k),[]);
k = k + 1;
xcorner = xcorner + dx;
end %for kcol
ycorner = ycorner+dy;
end %for krow

.