在图像中随机更改像素值程序——matlab

I=imread('C:UserswangdDesktop
esult3.png');
% m = rgb2gray(I);
% r = unidrnd(255,1,100); %产生一个1*100的数组,数组中的值为1至255中的随机值
% r1 = randi([2,7],10,100); %在开区间(27)生成10 * 100型随机矩阵
subplot(2,2,1);imshow(I);
title('原始图像');
for w=1:200
    j= randi([1,350],1,1);
    i= randi([1,400],1,1);
    x= randi([200,255],1,1);
    I(j,i)=x;
end
subplot(2,2,2);imshow(I);
title('图像');
imwrite(I,'C:UserswangdDesktop1.png');
原文地址:https://www.cnblogs.com/warmbeast/p/7810848.html