필터 지우기
필터 지우기

Creating a mat file with binary mask

조회 수: 4 (최근 30일)
Gulfam Saju
Gulfam Saju 2022년 4월 21일
댓글: Gulfam Saju 2022년 5월 9일
I want to create a 256*256 mask.mat file, where the middle 32 lines will be white (binary 1) and in there will be 30 lines of 1, randomly other than these 32 lines. I tried the below code: what should I add:
row = 256;
col = 256;
mask = zeros(row, col);
mask(:, 113:144) = 1;
figure, imshow(mask);
save("new-created-mask.mat", "mask");

채택된 답변

Voss
Voss 2022년 4월 21일
row = 256;
col = 256;
mask = zeros(row, col);
% 32 vertical lines in the middle (or one vertical line 32 columns wide)
mask(:, 113:144) = 1;
% create 30 other vertical lines at random:
idx_avail = 1:col; % column indexes available for the new random lines
idx_avail(113:144) = []; % don't allow random lines in the middle
% 30 random numbers chosen from idx_avail without repeats:
% randperm(N_avail,30) returns 30 unique integers between 1 and N_avail, inclusive
% then idx_avail(randperm(__)) converts those to indexes of columns of mask
N_avail = numel(idx_avail);
random_idx = idx_avail(randperm(N_avail,30));
% put the lines in place:
mask(:,random_idx) = 1;
figure, imshow(mask);
save("new-created-mask.mat", "mask");
  댓글 수: 3
Voss
Voss 2022년 4월 21일
You're welcome!
Gulfam Saju
Gulfam Saju 2022년 5월 9일
Hello! I want to create somthing just like the uploaded file. I want to create one like (data.train) of the sampling_pattern.mat file. Can you help?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by