How to slide m by n overlapped blocks by incrementing the row and column coordinates 20 pixels righ and down by using nlfilter?
1 view (last 30 days)
Show older comments
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 210x210 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
.............................................................................
0 Comments
Accepted Answer
Image Analyst
on 8 Jul 2013
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.
2 Comments
Image Analyst
on 9 Jul 2013
Sure, I have demos of blocproc, but why should I send you on a wild goose chase when I can send you to the people who have already solved this for you. Go here: http://iris.usc.edu/Vision-Notes/bibliography/contentsmedical.html#Medical%20Applications,%20CAT,%20MRI,%20Ultrasound,%20Heart%20Models,%20Brain%20Models and look at section 20.5 where people have published methods that work.
More Answers (1)
Sean de Wolski
on 8 Jul 2013
Why not just use blockproc which is designed for this?
doc blockproc
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!