Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Take every Nth element of a matrix

I am trying to create a block average filter of an image.

In Matlab my code looks like:

ba=4; %block average block size B = ones(ba)/ba^2; out1 = conv2(double(rgb_img(:,:,1))/255,B,'valid'); out1 = out1(1:ba:end,1:ba:end); out2 = conv2(double(rgb_img(:,:,2))/255,B,'valid'); out2 = out2(1:ba:end,1:ba:end); out3 = conv2(double(rgb_img(:,:,3))/255,B,'valid'); out3 = out3(1:ba:end,1:ba:end);

I know how to do the first step using filter2D how do I do the second step (take every 4th element)

Take every Nth element of a matrix

I am trying to create a block average filter of an image.

In Matlab my code looks like:

ba=4; %block average block size
B = ones(ba)/ba^2;
out1 = conv2(double(rgb_img(:,:,1))/255,B,'valid');
out1 = out1(1:ba:end,1:ba:end);
out2 = conv2(double(rgb_img(:,:,2))/255,B,'valid');
out2 = out2(1:ba:end,1:ba:end);
out3 = conv2(double(rgb_img(:,:,3))/255,B,'valid');
out3 = out3(1:ba:end,1:ba:end);

out3(1:ba:end,1:ba:end);

I know how to do the first step using filter2D how do I do the second step (take every 4th element)