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
Image Matlab:如何将所有三个通道中图片的特定RGB值更改为;255“;(白色)_Image_Image Processing_Rgb_Pixel - Fatal编程技术网

Image Matlab:如何将所有三个通道中图片的特定RGB值更改为;255“;(白色)

Image Matlab:如何将所有三个通道中图片的特定RGB值更改为;255“;(白色),image,image-processing,rgb,pixel,Image,Image Processing,Rgb,Pixel,我有一张尺寸为2816x2112x3 uint8的照片。我的目标是找到蓝色通道中超过120的所有值,然后将所有三个通道中的RGB值更改为255,以便在特定位置上有白点(不使用循环) 我的做法是: position=find(image(:,:,3)>120); %get the positions image(positions)=255; 不幸的是,我被困在这里,因为我无法使用: image(positions,1)=255; image(positio

我有一张尺寸为2816x2112x3 uint8的照片。我的目标是找到蓝色通道中超过120的所有值,然后将所有三个通道中的RGB值更改为255,以便在特定位置上有白点(不使用循环)

我的做法是:

    position=find(image(:,:,3)>120); %get the positions
    image(positions)=255;
不幸的是,我被困在这里,因为我无法使用:

    image(positions,1)=255;
    image(positions,2)=255;
    image(positions,3)=255;
我也想过这样做,但我也不能使用,因为它会覆盖更多的值:

    [yy xx]=find(image(:,:,3)>120);
    image(yy,xx,1)=255;
    image(yy,xx,2)=255;
    image(yy,xx,3)=255;
如果能听到一些关于这方面的想法,那就太好了

该函数将下标索引(即使用
x
y
z
坐标)转换为。要获取三维数组中点的线性索引
(yy,xx,zz)
,请调用

lin = sub2ind(size(im), yy, xx, zz);
这也适用于数组,但是
xx
yy
zz
必须具有相同的大小,因此您需要使用
numel(xx)
元素创建
zz
数组:

im(sub2ind(size(im), yy, xx, 1*ones(numel(xx),1))) = 255;
im(sub2ind(size(im), yy, xx, 2*ones(numel(xx),1))) = 255;
im(sub2ind(size(im), yy, xx, 3*ones(numel(xx),1))) = 255;
完整的示例代码:

im = imread('https://i.kinja-img.com/gawker-media/image/upload/s--pEKSmwzm--/c_scale,fl_progressive,q_80,w_800/1414228815325188681.jpg');
[yy xx] = find(im(:,:,3)>120);
im(sub2ind(size(im), yy, xx, 1*ones(numel(xx),1))) = 255;
im(sub2ind(size(im), yy, xx, 2*ones(numel(xx),1))) = 255;
im(sub2ind(size(im), yy, xx, 3*ones(numel(xx),1))) = 255;
创建以下输出:

PS:
image
是一个内置的MATLAB函数。通过命名变量
image
,您就不能再使用该函数了。我建议重命名变量