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

3 ビュー (過去 30 日間)
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
.............................................................................

採用された回答

Image Analyst
Image Analyst 2013 年 7 月 8 日
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 件のコメント
Baris GOKCE
Baris GOKCE 2013 年 7 月 9 日
Thank you very much for your answer, could you provide me an example please, i dont know how to do this, actually i need to get some ifomation for each jumpped blocks such mean, standart deviation, skewness of histogram, uniformity in an optic disc image. My aim is trying to find optic disc location by defining candidate regions or blocks. If you have an example, i will be very happy if share it to me.
Image Analyst
Image Analyst 2013 年 7 月 9 日
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.

サインインしてコメントする。

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2013 年 7 月 8 日
Why not just use blockproc which is designed for this?
doc blockproc

Community Treasure Hunt

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

Start Hunting!

Translated by