what does this means.

3 views (last 30 days)
Prasad MV
Prasad MV on 19 Feb 2012
Edited: Jonathan LeSage on 16 Oct 2013
can you tell me what does this means. .
repmat(okpxls, [1, 1, 3]);
and zeros(size(img), class(img));
pls reply asap. .

Accepted Answer

Wayne King
Wayne King on 19 Feb 2012
Enter
size(okpxls)
after the line:
okpxls = minr <= r & r <= maxr & ming <= g & g <= maxg & minb <= b & b <= maxb;
What I think you will see is that okpxls is a 2-D matrix the same size as r, g, and b.
Then the line:
okpxls = repmat(okpxls,[1 1 3])
says take that 2-D matrix okpxls and replicate that exact 2-D matrix into a MxNx3 matrix
Look at this very simple example
x = randn(2,2);
x1 = repmat(x,[1 1 3]);
Now if you enter
size(x1)
You see that x1 is 2x2x3 and furthermore that
x1(:,:,1) is equal to x, x1(:,:,2) is equal to x, and x1(:,:,3) is equal to x
Please read the documentation for repmat.

More Answers (1)

Wayne King
Wayne King on 19 Feb 2012
repmat(okpxls,[1 1 3]) replicates (copies) an input into 3-D.
x = randn(3,1);
y = repmat(x,[1 1 3]);
y has the same row and column size as x, but has dimension 3 along the third dimension.
Another example:
x = randn(2,2);
y = repmat(x,[1 1 3]);
size(y)
zeros(size(img), class(img));
creates a matrix of zeros the same size and class as image
x1 = uint8(randn(8,8));
x2 = zeros(size(x1),class(x1));
  4 Comments
Wayne King
Wayne King on 19 Feb 2012
as far as zeros()
if x has a certain class, say unsigned 8-bit integer
x = uint8(randn(2,2))
size(x)
class(x)
then
y = zeros(size(x),class(x))
creates an array, vector, etc the same size as x AND of the same class
Prasad MV
Prasad MV on 19 Feb 2012
okpxls = minr <= r & r <= maxr & ming <= g & g <= maxg & minb <= b & b <= maxb;
okpxls = repmat(okpxls, [1, 1, 3]);
newimg = zeros(size(img), class(img));
what i didnt get was [1 1 3]
what does this mean

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!