What is the use of repmat in the following program?

1 回表示 (過去 30 日間)
Pooja
Pooja 2013 年 8 月 15 日
What is the use of repmat in the following program?
i=I;
[ir ic]=size(I);
if ir ~=512 && ic~=512
I=repmat(I,[1 2]);
end

回答 (1 件)

Jan
Jan 2013 年 8 月 15 日
編集済み: Jan 2013 年 8 月 15 日
If none of the dimensions of I equal 512 (for some reason) it is repeated and the copied matrix is added horizontally to I.
i.e. the following should produce the same output
if ~any( size(I)==512 )
I=horzcat(I,I);
end
  2 件のコメント
Pooja
Pooja 2013 年 8 月 15 日
By doing this will it affect the input image?Any data loss?
Jan
Jan 2013 年 8 月 15 日
As I said, the matrix I (or image if you will) will be duplicated and the results concatenated if none of the input dimensions equal "512". In that case, the code does affect the image - you end up with an image of double width where left half and right half are identical. Prior to this step a copy of the image is made (i=I;). No data will be lost.
Anyway, the action based on the condition in the if-statement does seem slightly weird to me. Are you sure the code makes sense in a broader scope?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by