用另一种颜色Matlab替换图像中的某个颜色范围 [英] Replace a certain color range in an image with another color Matlab
本文介绍了用另一种颜色Matlab替换图像中的某个颜色范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
how to replace the pixels having a certain RGB range not just a specific value as shown in this question like for example pixels with R ranging from 140-150, G ranging from 50-55 and B ranging from 61-70 , with another single value like (150,57,80). If anyone could please advise.
推荐答案
这也是对您在先前发布的另一个问题中提供的答案的修改.您只需更改logical
蒙版计算,即可搜索一系列红色,绿色和蓝色值.
This is also a modification to the answer I provided in the other question you posted earlier. You simply change the logical
mask calculations so that we search for a range of red, green and blue values.
因此:
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);
这篇关于用另一种颜色Matlab替换图像中的某个颜色范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文