Here. This implements a sliding-window filter based on your interpretation of what "find the difference of a particular with its adjacent 5 pixels" means.
In this filter, the output pixel is the sum of absolute differences between the pixel and its neighbors in a 5x5 window.
A = rgb2gray(imread('7.png'));
A = imsharpen(imresize(A,2));
centerpix = ceil(fs^2/2);
neighbors = [(1:centerpix-1) (centerpix+1:fs^2)];
F = @(x) sum(abs(x(centerpix) - x(neighbors)));
C = nlfilter(im2double(A),[fs fs],F);
No thresholding is performed internally, though it could. It can just as simply be applied afterwards.
How that relates to the operations performed in the paper is anybody's guess. There's no description of threshold selection or the parameters used for subsequent morphological operations.
The core of the paper is undocumented nonsense. It is unclear how the pseudocode relates to any of the described operations in the text or to which examples it applies. The preceding examples regarding sobel and prewitt filters appear to have been simply performed with imfilter() without actually calculating the gradient magnitude or paying particular attention to threshold levels. I don't know what you hope to glean from the results.