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_Matlab Figure - Fatal编程技术网

Matlab 用另一种颜色替换图像中的特定颜色范围

Matlab 用另一种颜色替换图像中的特定颜色范围,matlab,image-processing,matlab-figure,Matlab,Image Processing,Matlab Figure,如何将具有特定RGB范围的像素(不仅仅是如本文所示的特定值)替换为(150,57,80)之类的另一个单一值,例如R范围为140-150、G范围为50-55、B范围为61-70的像素。如果有人能提供建议。事实证明,在找到合适的匹配像素位置时,您只需稍加修改即可。下面是实现- %// Initialize vectors for the lower and upper limits for finding suitable %// pixels to be replaced lower_lim =

如何将具有特定RGB范围的像素(不仅仅是如本文所示的特定值)替换为(150,57,80)之类的另一个单一值,例如R范围为140-150、G范围为50-55、B范围为61-70的像素。如果有人能提供建议。

事实证明,在找到合适的匹配像素位置时,您只需稍加修改即可。下面是实现-

%// Initialize vectors for the lower and upper limits for finding suitable 
%// pixels to be replaced
lower_lim = [140,50,61]
upper_lim = [150,55,70]

%// Initialize vector for new pixels tuplet
newval = [150,57,80]

%// Reshape the input array to a 2D array, so that each column would
%// represent one pixel color information. 
B = reshape(permute(A,[3 1 2]),3,[])

%// Find out which columns fall within those ranges with `bsxfun(@ge` and `bsxfun(@le`
matches  = all(bsxfun(@ge,B,lower_lim(:)) & bsxfun(@le,B,upper_lim(:)),1)

%// Replace all those columns with the replicated versions of oldval
B(:,matches) = repmat(newval(:),1,sum(matches))

%// Reshape the 2D array back to the same size as input array
out = reshape(permute(B,[3 2 1]),size(A))

事实证明,在找到合适的匹配像素位置时,您需要进行一些修改。下面是实现-

%// Initialize vectors for the lower and upper limits for finding suitable 
%// pixels to be replaced
lower_lim = [140,50,61]
upper_lim = [150,55,70]

%// Initialize vector for new pixels tuplet
newval = [150,57,80]

%// Reshape the input array to a 2D array, so that each column would
%// represent one pixel color information. 
B = reshape(permute(A,[3 1 2]),3,[])

%// Find out which columns fall within those ranges with `bsxfun(@ge` and `bsxfun(@le`
matches  = all(bsxfun(@ge,B,lower_lim(:)) & bsxfun(@le,B,upper_lim(:)),1)

%// Replace all those columns with the replicated versions of oldval
B(:,matches) = repmat(newval(:),1,sum(matches))

%// Reshape the 2D array back to the same size as input array
out = reshape(permute(B,[3 2 1]),size(A))

这也是对我在你之前发布的另一个问题中提供的答案的修改。您只需更改
逻辑
掩码计算,以便我们搜索红色、绿色和蓝色值的范围

因此:

red = A(:,:,1); green = A(:,:,2); blue = A(:,:,3);

%// Change here
mred = red >= 140 & red <= 150; 
mgreen = green >= 50 & green <= 55; 
mblue = blue >= 61 & blue <= 70;

%// Back to before
final_mask = mred & mgreen & mblue;
red(final_mask) = 150; green(final_mask) = 57; blue(final_mask) = 80;
out = cat(3, red, green, blue);
red=A(:,:,1);绿色=A(:,:,2);蓝色=A(:,:,3);
%//在这里换车

mred=red>=140&red=50&green=61&blue这也是对我在您之前发布的另一个问题中提供的答案的修改。您只需更改
逻辑
掩码计算,以便我们搜索红色、绿色和蓝色值的范围

因此:

red = A(:,:,1); green = A(:,:,2); blue = A(:,:,3);

%// Change here
mred = red >= 140 & red <= 150; 
mgreen = green >= 50 & green <= 55; 
mblue = blue >= 61 & blue <= 70;

%// Back to before
final_mask = mred & mgreen & mblue;
red(final_mask) = 150; green(final_mask) = 57; blue(final_mask) = 80;
out = cat(3, red, green, blue);
red=A(:,:,1);绿色=A(:,:,2);蓝色=A(:,:,3);
%//在这里换车

mred=red>=140&red=50&green=61&blue同样,请说明它们是否将被单个元组替换?什么是单个元组?就像它们将被单个像素颜色信息替换一样,比如
(150,57,80)
?同样,请说明它们是否将被单个元组替换?什么是单个元组?就像它们将被单个像素颜色信息替换一样,如
(150,57,80)