我有一个图像,我用Matlab打开使用imshow
,我想用新颜色(150)替换每个像素的颜色值(140,50,61) ,57,80)。如果有人可以请告知我如何做到这一点。用另一种颜色替换图像中的某种颜色Matlab
1
A
回答
2
假设A
是输入的图像数据,这可能是一个办法 -
%// Initialize vectors for old and new pixels tuplets
oldval = [140,50,61]
newval = [150,57,80]
%// Reshape the input array to a 2D array, so that each column would
%// reprsent one pixel color information.
B = reshape(permute(A,[3 1 2]),3,[])
%// Find out which columns match up with the oldval [3x1] values
matches = all(bsxfun(@eq,B,oldval(:)),1)
%// OR matches = matches = ismember(B',oldval(:)','rows')
%// 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))
采样运行 -
>> A
A(:,:,1) =
140 140 140
40 140 140
A(:,:,2) =
50 20 50
50 50 50
A(:,:,3) =
61 65 61
61 61 61
>> out
out(:,:,1) =
150 140 150
40 150 150
out(:,:,2) =
57 20 57
50 57 57
out(:,:,3) =
80 65 80
61 80 80
1
bsxfun
是我会解决它的办法。但是,如果您不熟悉它,则可以从图像中提取每个通道,为每个通道使用三个逻辑模板,然后使用logical
AND进行组合。做和会发现你的图像中的像素,寻找特定的RGB三重。
因此,我们相应地设置每个通道的输出并重构图像以产生输出。
因此,鉴于你的输入图像A
,一个可以这样做:
red = A(:,:,1); green = A(:,:,2); blue = A(:,:,3);
mred = red == 140; mgreen = green == 50; mblue = blue == 61;
final_mask = mred & mgreen & mblue;
red(final_mask) = 150; green(final_mask) = 57; blue(final_mask) = 80;
out = cat(3, red, green, blue);
相关问题
- 1. 用另一种颜色替换图像中的某个颜色范围Matlab
- 2. 用另一种颜色替换图像中的特定颜色
- 3. 用CSS3中的图像中的另一种颜色替换颜色
- 4. 用另一种颜色替换uiimage中的颜色
- 5. 在NSImage中替换另一种颜色
- 6. 使用PHP替换图像中的另一种颜色
- 7. 背景颜色50%一种颜色和50%另一种颜色
- 8. 将某些像素RGB颜色到另一种颜色
- 9. 从一种特定颜色到另一种颜色的研究生matlab绘图
- 10. 从一种颜色到另一种颜色的插值
- 11. 用另一种颜色更改所有像素的颜色
- 12. 从一种颜色到另一种颜色到百分比
- 13. 如何将一种颜色变成另一种颜色?
- 14. 确定一种颜色“图像中单个颜色的多少”
- 15. 在UIView中将背景色从一种颜色淡出到另一种颜色
- 16. 一半的信是一种颜色,另一半另一种颜色
- 17. 将ShapeDrawable中的单色(黑色)替换为Android中的另一种颜色
- 18. 将自动文本颜色替换为选中的某种显式颜色
- 19. 直接从高亮颜色切换颜色到另一种颜色
- 20. 需要更快的方法来替换基于另一种颜色的图像中的颜色
- 21. 如何将一种颜色替换为eps文件的每个对象中的另一种颜色?
- 22. 如何让图像中的某种颜色变成黑色?
- 23. 颜色的另一种颜色的JTable中选择行
- 24. 另一种方法将背景颜色淡入另一种颜色
- 25. 在UIImage(或其衍生产品)中,如何将一种颜色替换为另一种颜色?
- 26. ggplot:一种颜色/
- 27. 通过用户输入从一种颜色变为另一种颜色
- 28. 您可以在位图图像中将一种颜色更改为另一种颜色吗?
- 29. JAVA:使用ColorModel替换另一种颜色
- 30. 使用CSS给一个黑色的图标另一种颜色
你能告诉我怎么用替换'OLDVAL(:)'?旧的颜色是RGB(140,50,61) – Tak 2015-02-11 04:30:07
@shepherd检查编辑? – Divakar 2015-02-11 04:30:35
谢谢:)。是否可以写一些解释你写的代码行的注释? :) – Tak 2015-02-11 04:32:25