Matlab颜色检测 [英] Matlab colour detection
本文介绍了Matlab颜色检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨.我在这里有这段代码.我想知道如何检测想要的颜色.例如黄色.谢谢.
Hi. I have this code here. I want to know how do I detect the colour that I want. For example yellow. Thanks.
% Demo macro to very, very simple color detection in RGB color space
% by ImageAnalyst
clc;
close all;
% Read standard MATLAB demo image.
rgbImage = imread('onion.png');
% Display the original image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original RGB Image');
% Maximize figure.
set(gcf, 'Position', get(0, 'ScreenSize'));
% Split the original image into color bands.
redBand = rgbImage(:,:, 1);
greenBand = rgbImage(:,:, 2);
blueBand = rgbImage(:,:, 3);
% Display them.
subplot(3, 4, 2);
imshow(redBand);
title('Red band');
subplot(3, 4, 3);
imshow(greenBand);
title('Green band');
subplot(3, 4, 4);
imshow(blueBand);
title('Blue Band');
% Threshold each color band.
redthreshold = 68;
greenThreshold = 70;
blueThreshold = 72;
redMask = (redBand > redthreshold);
greenMask = (greenBand < greenThreshold);
blueMask = (blueBand < blueThreshold);
% Display them.
subplot(3, 4, 6);
imshow(redMask, []);
title('Red Mask');
subplot(3, 4, 7);
imshow(greenMask, []);
title('Green Mask');
subplot(3, 4, 8);
imshow(blueMask, []);
title('Blue Mask');
% Combine the masks to find where all 3 are "true."
redObjectsMask = uint8(redMask & greenMask & blueMask);
subplot(3, 4, 9);
imshow(redObjectsMask, []);
title('Red Objects Mask');
maskedrgbImage = uint8(zeros(size(redObjectsMask))); % Initialize
maskedrgbImage(:,:,1) = rgbImage(:,:,1) .* redObjectsMask;
maskedrgbImage(:,:,2) = rgbImage(:,:,2) .* redObjectsMask;
maskedrgbImage(:,:,3) = rgbImage(:,:,3) .* redObjectsMask;
subplot(3, 4, 10);
imshow(maskedrgbImage);
title('Masked Original Image');
推荐答案
^ ]的第一个结果:
使用HSV色彩空间进行色彩检测 [ ^ ]
另一行在同一行: http://www.codeguru.com/forum/archive /index.php/t-306787.html [ ^ ]
Google''s[^] first result:
Color Detection Using HSV Color Space[^]
And another one on same lines: http://www.codeguru.com/forum/archive/index.php/t-306787.html[^]
您有使用图像处理技术读取电阻值(电阻颜色代码)的任何方法吗?
Do you have any method of reading a resistor value (resistor colour codes) using image processing techniques?
这篇关于Matlab颜色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文