applying thresholds simultaneously in SimpleColo​rDetection​ByHue()

3 次查看(过去 30 天)
I'm trying to use this program to detect not one but three different colors (red green blue) at the same time, applying three different thresholds. Is there a way? Try to explain each little step because I haven't used Matlab for a while and I'm a bit rusty. Thank you all!

采纳的回答

Image Analyst
Image Analyst 2017-9-20
编辑:Image Analyst 2017-9-20
Yes, basically just do each color one at a time and get a mask for each one, then OR them together.
% Set hsv thresholds for color1
maskColor1 = ........ % Create mask based on those thresholds.
% Set hsv thresholds for color2
maskColor2 = ........
% Set hsv thresholds for color3
maskColor3 = ........
% Get the mask for all 3
allThreeColorsMask = maskColor1 | maskColor2 | maskColor3;
  17 个评论
giacomo
giacomo 2017-10-16
Done! One more question. What about if I want to evaluate the porosity in 4 areas of the cropped image? Would it be something like:
%
hsvImage = rgb2hsv(rgbImage);
[r, c, p] = size(hsvImage);
DarkAreas1 = vImage(1:r,1:c/4,:);
Porosity1 = sum(darkAreas1(:))/numel(darkAreas);
same thing for the other three areas and then mean for the total porosity? (it's to display the heterogeneity of the index from top to bottom of the image). Then I wanted to load another image after the elements have been stressed to evaluate the same index and a global one for comparison. The important thing is that the cropped area has to be the same in coordinates and width/height (pic position will be the same since it's same camera and same position of shooting). It has something to do with 'rect' command but I'm not sure what. Thank you. Please tell me if I should create another question for this. :)
Image Analyst
Image Analyst 2017-10-17
Not sure what you want, but what you are doing is taking the leftmost quarter strip of the image, and getting the mean all the gray levels in that vertical strip. The last two lines could be done like this:
Porosity1 = mean2(vImage(1:r,1:c/4,:));
Of course you need to define vImage. Did you mean hsvImage? Or did you mean (but left out)
vImage = hsvImage(:, :, 1); % Extract value channel.
If you meant that, then you can leave off the final colon:
Porosity1 = mean2(vImage(1:r,1:c/4));
If you want a fixed number of columns, instead of 1/4 the width of the image, then just specify it. For example, use 100 instead of c/4. It does not need to involve rect() unless you want the user to be able to adjust the location of the box interactively over the image.

请先登录,再进行评论。

更多回答(1 个)

CHERI AUTO
CHERI AUTO 2019-3-25
how to change input image as real time web cam in the laptop on matlab coading

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by