MATLAB: Simple question about one of “Img()” commands

contrastimg commands

for yy=1:Y
for xx=1:X
frame = img(max(1,yy-WIN):min(Y,yy+WIN),max(1,xx-WIN):min(X,xx+WIN));
ma = max(frame(:)); mi = min(frame(:));
contr(yy,xx) = (ma-mi)/(ma+mi);
end
what does this phrase mean? "max(1,yy-WIN):min(Y,yy+WIN)"

Best Answer

It says create a vector from A to B, where A is the maximum of 1 and yy-WIN and B is the minimum of Y and yy+WIN. That vector is used to index the elements of img(). In other words to select the elements of img() for those row indices. The easiest way to see how this works is to create a simple example for yourself.
Y = 5;
WIN = 2;
for yy = 1:Y
max(1,yy-WIN):min(Y,yy+WIN)
end