I have a function show below glcmcontrast
which is applied to an image in a sliding window operation using nlfilter.
function s = glcmcontrast(subI)
glcm = graycomatrix(subI,'Offset',[0 1],'NumLevels',64,'Symmetric',true);
stats = graycoprops(glcm,'contrast');
s=stats.Contrast;
This returns a scalar value for each sub image (the window, as passed by nlfilter). To use this with nlfilter I have it as an anonymous function handle, and its usage is shown below.
glcmanon = @(x)glcmcontrast(x);
tic; B = nlfilter(image,[3 3],glcmanon); toc;
This code quickly becomes very slow for images over 1024 x 1024. It is noted in the documentation that colfilt can be used with the 'sliding'
argument to perform the same operations. My question is how I would use the function glcmcontrast
with colfilt
. Running it returns the error:
tic; B = colfilt(A,[3 3],'sliding',glcmcontrast); toc;
'Error using reshape
To RESHAPE the number of elements must not change.
Error in colfilt (line 183)
b(i*mb+brows,j*nb+bcols) = ...'
I know from the documentation that colfilt
reshapes the array using im2col into an (m*n)-by-((i-m+1)*(j-n+1))
where the window size is [m n]
and the image size is [i j]
. The question is how do I rewrite my glcmcontrast
function into a format that works with colfilt
? The line from colfilt
that actually applies the function to the reshaped array is
b = reshape(feval(fun,x,params{:}), size(a));
but I am completely lost as to how to apply my function to this. I think the problem something to do with my function outputting a scalar value, but I'm not sure..