Assigning random values to image pixels

4 Ansichten (letzte 30 Tage)
Sordin
Sordin am 30 Apr. 2017
Beantwortet: Guillaume am 30 Apr. 2017
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.

Akzeptierte Antwort

Guillaume
Guillaume am 30 Apr. 2017
I = zeros(128, 128)
I(32:96, 32:96) = rand(96-32+1, 96-32+1);

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by