Simplicity
Simplicity

Reputation: 48946

What does this mean in MATLAB?

I have came about a MATLAB code like the following:

xyz = imfilter(A,B);
xyz_subsample = xyz(1:2:size(xyz, 1), 1:2:size(xyz, 2));

The code is related to subsampling. But, what does the second line mean?

Thanks.

Upvotes: 1

Views: 252

Answers (2)

Luis Mendo
Luis Mendo

Reputation: 112749

The second line is taking every second sample in each spatial dimension. So it's downsampling by a factor of 2 in each dimension.

Downsampling should be preceded by lowpass filter in order to avoid aliasing effects. The filter in the first line probably does that. Is B a lowpass mask?

Upvotes: 4

Daniel
Daniel

Reputation: 36710

The second line uses the colon operator to select every second row and every second colum, which means that every 4th pixel is selected.

Upvotes: 2

Related Questions