Hi Athulya,
Check if this works for you:-
im=rgb2gray(imread('SM.jpg')); %some image
fun = @(block_struct) graycomatrix(block_struct.data);
im2=blockproc(im,[32 32],fun);
Links:-
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!