How to extract sliding block features of an image by using blockproc? Please analyze my code

2 views (last 30 days)
Hello dear all I am trying to extract sliding block features of an images by using blockproc. Firtsly i have tried nlfilter, but it is not useful sliding blocks by jumping 20 pixels right and down as Sean de Wolski and Image Analyst mentioned.
I have created a function to extract block properties. It worked with nlfilter but matlab gave some error for blockproc such below. Please tell me where im doing wrong and give an advice please. Thank you very much for your contribution...
Error message is: Function BLOCKPROC encountered an error while evaluating the user supplied function handle, FUN. The cause of the error was: Error using imhist Expected input number 1, I or X, to be one of these types: double, uint8, int8, logical, uint16, int16, single, uint32, int32 Instead its type was struct. Error in imhist>parse_inputs (line 277)
My code is
% blockproc Block Processing
close all; clear all; clc;
global num;
global cnt;
cnt = 1;
num = 0;
I = imread('o1.jpg');
I = rgb2gray(I);
fun = @fn_blk;
disp('Performing blockproc Operation')
tic
B = blockproc(I,[210 210],fun,'BorderSize',[20 20], ...
'PadPartialBlocks',true);
toc
imshow(I), title('Original')
figure
imshow(B, []), title('blockproc')
----------------------------------------------------------------
function fn_blk(x)
global cnt;
global inputs;
count = imhist(x);
% normalize histogram values
count = count./numel(x);
L = length(x);
% calculate mean directly
mu = centralmoments(count,3);
inputs(1,cnt)= mean(x(:)); %mean: average intensity
inputs(2,cnt)= mu(2)^0.5; %standard deviation: average contrast
varnorm = mu(2)/(L-1)^2; %smoothness: ranges from 0 (constant intensity) to 1
inputs(3,cnt)= 1-1/(1+varnorm);
inputs(4,cnt)= mu(3)/(L-1)^2; %skewness of histogram: 0 for symmetric histograms
inputs(5,cnt)= sum(count.^2); %uniformity: high value if all gray levels are equal
inputs(6,cnt)= -sum(count.*(log2(count+eps))); %entropy: randomness
cnt = cnt + 1;
end

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!