MATLAB: How to slide m by n overlapped blocks by incrementing the row and column coordinates 20 pixels righ and down by using nlfilter

block operationsblock processingcolfiltImage Processing Toolboxnlfilterslidingsliding blockssliding neighborhood

Hello dear all I am trying to create a function that performs sliding block processing in an image. More specifically, it starts by selecting the first 210×210 block of the image (from top left corner), performs the function, and then increments the row and column coordinates 20 pixels right and down.
I have cheated the function for nlfileter, but it is not logic, it puts a white pixel after each 20 pixels, it is ok for the first row but what i want, it increments 20 pixels down after firs row finished but unfortunately i did not able to this. My codes are given in below please give me a logical ideas for by incrementing 20 pixels down to the end of image
———————— nlfileter_test.m file——————-
% Sliding neighborhood filtering example
close all; clear all; clc;
global num;
cnt = 1;
num = 0;
I = imread('o11.jpg');
I = rgb2gray(I);
fun = @fn_extr_img_features;
disp('Performing Sliding Neighborhood Operation')
tic
I2 = nlfilter(I,[210 210],fun);
toc
imshow(I), title('Original')
figure
imshow(I2, []), title('nlfilter')
——————————————————————————–
——————-fn_extr_img_features.m file——————
function y = fn_extr_img_features(x)
global num;
if (mod(num, 20) == 0) % this codes makes one white pixel atfer each 20 pixels black pixel.
y=255;
else
y = 0;
end
num = num + 1;
end
…………………………………………………………………..

Best Answer

nlfilter() does not move in "jumps" of 20 pixels - it slides along by one pixel at a time. By putting in the correct parameters to blockproc() you can have overlapping tiles (like nlfilter, imfilter, and conv2), or it can be perfectly tiled by moving a 20x20 window in "jumps" of 20 pixels, and it even might be able to jump enough to have gaps between the window locations.
Beyond that your code really doesn't do anything useful, or if it's useful to you it's not very efficient. There are better ways to create a black image with an array of dots spaced every 20 pixels.