What does patch = imJ(j : (j+patchSize-1) , i:(i+patchSize-1), :) means?

I think it means RGB but I'm not too sure. Why does the j and i has to add increment by patchSize -1?
In front of this code is
for j = 1:height
for i = 1:width
patch = imJ( j : (j+patchSize-1), i:(i+patchSize-1), :);
Thanks in advance

 Accepted Answer

It extracts a square of width patchsize from an rgb image.
Suppose the patch size is 4 and you are starting at (1,1). Then you need to extract (1:4,1:4,:) which is (1:1+3,1:1+3,:) which is 1:1+4-1,1:1+4-1,:) which leads to the general (i:i+patchsize-1,j:j+patchsize-1,:)

More Answers (1)

dpb
dpb on 25 Feb 2017
Edited: dpb on 25 Feb 2017
Read
doc colon
It's simply a subarray selection of a rectangular area ("patch") from the imj array (undoubtedly an image) patchSize square starting at the corner (i,j==1). There better be some exit code somewhere in the loop or it will error when either i,j are past the upper bounds less the size parameter.
The last dimension colon picks up all the planes so will be 3D array if imJ is RGB although Matlab addressing is general-enough to work with only 2D array as well with the superfluous trailing dimension just as an observation.

Asked:

on 25 Feb 2017

Edited:

dpb
on 25 Feb 2017

Community Treasure Hunt

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

Start Hunting!