Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问每个图像像素,matlab_Matlab_Image Processing - Fatal编程技术网

如何访问每个图像像素,matlab

如何访问每个图像像素,matlab,matlab,image-processing,Matlab,Image Processing,我想将图像的每个像素随机更改为0 到目前为止我的代码 randx = randsrc(512,512,[1 0]); for n=1:1:512 if (randx(n)==0) A(n)=0; end end 到目前为止,只有第一列发生了变化。 不知道如何改变其他的 感谢您的帮助您可以使用任意随机函数生成与图像大小相同的数组。例如,这里我使用了randsample: I = imread('cameraman.tif'); p = [0.2 0.8];

我想将图像的每个像素随机更改为0

到目前为止我的代码

randx = randsrc(512,512,[1 0]);

for n=1:1:512
    if (randx(n)==0)
        A(n)=0;
    end  
end
到目前为止,只有第一列发生了变化。 不知道如何改变其他的


感谢您的帮助

您可以使用任意随机函数生成与图像大小相同的数组。例如,这里我使用了
randsample

I = imread('cameraman.tif');
p = [0.2 0.8]; % probabilities for 0 and 1
% randomly set pixels to 0
r = reshape(randsample([0 1],numel(I),true,p),size(I));
I(r == 0) = 0;
imshow(I);

您需要使用两个索引访问图像:行和列。仅使用n介于1和512之间的A(n),您只能访问第一列的元素(请注意,您的图像有512x512=262144个元素,您只能访问第一列512,即第一列)

试用

for n=1:1:262144

相反。这会有用的

看看numpy索引和切片。在继续之前,理解这一点非常重要。然后你也可以自己解决这个问题