필터 지우기
필터 지우기

How can I create a binary mask?

조회 수: 7 (최근 30일)
Gulfam Saju
Gulfam Saju 2022년 5월 26일
편집: DGM 2022년 5월 26일
I want to create a binary mask, where there will be random white dots in the area. But it will be more dense in the middle. For the reference please check the image.
row = 320;
col = 320;
trnMask = zeros(row,col)
trnMask = rand(320);
figure,imshow(trnMask);
I tried this code. But it doesn't work.

채택된 답변

DGM
DGM 2022년 5월 26일
편집: DGM 2022년 5월 26일
Without having clear technical goals, I'm just going to assume that no technical requirements exist for shape or density. I'm going to treat this as a rudimentary dithering operation.
% image size
s = 320;
% generate some gaussian profile or something?
sg = s*0.15; % gaussian shape parameter
os = 0.05; % background noise
R = linspace(-s/2,s/2,s);
prof = exp(-(R.^2 + R.'.^2)/(2*sg^2));
prof = prof*(1-os) + os;
% create random mask
mask = rand(s);
% binarize profile by comparing gray levels to mask
out = mask <= prof;
imshow(out)

추가 답변 (0개)

제품

Community Treasure Hunt

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

Start Hunting!

Translated by