Adding black and white pixels into an image.

7 ビュー (過去 30 日間)
Rafael Rivas
Rafael Rivas 2021 年 8 月 8 日
編集済み: KSSV 2021 年 8 月 8 日
I have a guassian lab where I have to show dead pixles (black and white)
The first part of my code has this where 128= mean and std = 8and the image size is 256*256.
When I run this code i get a pretty gray picture, which was expected.
I = normrnd(128,8,[256,256]);
imshow(I,[0,255]);
Now, i have to find the uniform distibution to replace 5% of the samples with black (i=0) and 5% of the pixels white (i=255). I'm having a hard time doing that.

採用された回答

KSSV
KSSV 2021 年 8 月 8 日
編集済み: KSSV 2021 年 8 月 8 日
I = normrnd(128,8,[256,256]);
imshow(I,[0,255]);
% Pick indices to replace with black and white
[m,n] = size(I) ;
idx = randperm(m*n,round(m*n*10/100)) ; % 5% +5% = 10%
% Replace with black
idx1 = randsample(idx,length(idx)/2) ;
idx2 = setdiff(idx,idx1);
I(idx1) = 0 ; % replace with black
I(idx2) = 255 ; % Replace with white
imshow(I)
  2 件のコメント
Rafael Rivas
Rafael Rivas 2021 年 8 月 8 日
It looks better than what I had but for the I(idx), should it be I(idx1) and I(idx2)? Otherwise when I run the code, I only get gray and white and no black?
KSSV
KSSV 2021 年 8 月 8 日
Yes yes... Typo error... Edited the code...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by