필터 지우기
필터 지우기

How can I make a random RGB array of either White Cells or Green Cells (or any two colours)?

조회 수: 1 (최근 30일)
Hey, I wish to create a random array of size R x C, and wish to have that array consist of either green or white cells.
My thoughts were to take the script for making a random Black and White image:
BnW = rand(R,C) < p;
Where p is some number between 0 and 1.
Then taking this image and somehow replacing all cells that have a value of 1 (black) and replace with a value of 255 in the second channel (green channel) in a RGB image. But a problem occurs with switching from a logical array to a uint8 array.
Any ideas?

채택된 답변

Stephen23
Stephen23 2019년 5월 6일
편집: Stephen23 2019년 5월 6일
This generates MATLAB standard 0-1 values (multiply by 255 and use uint8 if required):
>> R = 5;
>> C = 7;
>> X = rand(R,C)<0.4;
>> I = cat(3,X,ones(R,C),X);
>> image(I)
greenwhite.png

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by