フィルターのクリア

How to create an image that has random chunks of black and white pixels

10 ビュー (過去 30 日間)
MM
MM 2021 年 9 月 27 日
編集済み: Adam Danz 2021 年 9 月 28 日
I would like to create an image (1920 x 1080) that looks like the image below. How do I create something like this? Black and white spots can be randomly placed

採用された回答

Adam Danz
Adam Danz 2021 年 9 月 27 日
編集済み: Adam Danz 2021 年 9 月 28 日
Specify imageSize and blockScale to create randomly placed blocks of black and white pixels.
imageSize = [1920,1080]; % [width, height]
blockScale = 40; % larger values create larger blocks
blocksize = round(imageSize/blockScale);
data = randi(2,fliplr(blocksize))-1;
B = imresize(data, fliplr(imageSize),'nearest');
imagesc(B)
colormap([0 0 0; 1 1 1])
axis equal
axis tight
set(gca, 'xtick', [], 'ytick', [], 'LineWidth', 5) % add frame
If you just want random black and white pixels,
B = randi(2,[1080,1920])-1;
figure()
imshow(B)

その他の回答 (1 件)

yanqi liu
yanqi liu 2021 年 9 月 28 日
clc; clear all; close all;
% init image (1920 x 1080)
A = zeros(1080,1920);
% choose white
ind1 = randperm(numel(A(:)));
rate = 0.3;
xt = ind1(1:round(length(ind1)*rate));
A(xt) = 1;
A([1 end],:)=0;
A(:,[1 end])=0;
figure; imshow(logical(A));

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by