How to detect a specific color in photo?
45 views (last 30 days)
Show older comments
Hello. Recently, I faced some problems in using the image analysis. In attached photo, I needed to calculate the percent of shell(or root, sediment etc.) in total area. I already tried to detect the shell and calculate the percent of shell in total circle area.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164651/image.png)
Then, I plotted the red marker at each point, and could calculate the percent of shell. The following is code to detect the shell.
rgbImage = imread('GEMS_Vegetation.png');
imshow(rgbImage);
[x,y] = ginput(1);
row = round(y);
column = round(x);
r = rgbImage(:,:,1); r_dou = im2double(r)*255; Red = r_dou(row, column);
g = rgbImage(:,:,2); g_dou = im2double(g)*255; Green = g_dou(row, column);
b = rgbImage(:,:,3); b_dou = im2double(b)*255; Blue = b_dou(row, column);
Error_R = 0.15;
[R_r R_c] = find(r_dou <= Red+(Error_R*Red) & r_dou >= Red-(Error_R*Red)); R = [R_r R_c];
[G_r G_c] = find(g_dou <= Green+(Error_R*Green) & g_dou >= Green-(Error_R*Green)); G = [G_r G_c];
[B_r B_c] = find(b_dou <= Blue+(Error_R*Blue) & b_dou >= Blue-(Error_R*Blue)); B = [B_r B_c];
[RG,ia,ib] = intersect(R,G,'rows'); [RGB,ic,id] = intersect(RG,B,'rows');
figure()
imshow(rgbImage); hold on;
plot(RGB(:,2), RGB(:,1), 'ro', 'markersize', 3);
T_color = find(r_dou ~= 0);
Obj_pixels = (length(RGB)/length(T_color))*100;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164654/image.png)
However, in detecting the roots(greenish color) or stem, we couldn't detect the proper values. I thought that there is a water, inducing a reflection and shadow.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/164658/image.png)
In this point, how can I properly detect the wanted colors..??
0 Comments
Answers (1)
Kushagr Gupta
on 8 Jun 2017
I would recommend the following link to do image segmentation in color space:
Moreover, there is a imageSegmenter app in MATLAB that can be used for trying out different segmentation techniques in a quick way to see which performs the best. It can be accessed by executing the following command:
>>imageSegmenter
Hope this helps!
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!