Assigning random values to image pixels

5 ビュー (過去 30 日間)
Sordin
Sordin 2017 年 4 月 30 日
回答済み: Guillaume 2017 年 4 月 30 日
I am trying to assign random values to the elements of a rectangular region within an image matrix, so that the result looks something like this:
This is my approach:
I = zeros(128,128);
for i=32:96
for j=32:96
I(i,j) = rand();
end
end
imshow(I);
Is there a more efficient way of doing this, perhaps without a double for-loop?
Any suggestions would be greatly appreciated.

採用された回答

Guillaume
Guillaume 2017 年 4 月 30 日
I = zeros(128, 128)
I(32:96, 32:96) = rand(96-32+1, 96-32+1);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by