Color Detection in Image by using MATLAB
Hi everyone, I hope you are doing fine, Today I will share teach you how to detect images in MATLAB, in order to do so, I will share a step by step guide for Color Detection in MATLAB. I will share a project with you for better understanding and learning.
[You must be registered and logged in to see this link.]
- So as to do the Color Recognition in Images utilizing MATLAB, first of all, we require a Picture.
- Therefore, I Designed a picture in paint that has diverse shapes in various hues as appeared in beneath picture:
[You must be registered and logged in to see this link.] - There are distinctive shapes and colors in the picture, we will distinguish these shapes by their colors.
- Copy/Paste the give code into your m File.
data = imread('TEP.jpg');
diff_im = imsubtract(data(:,:,2), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, ;
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'black');
end
hold off
- After implementing the code, Execute the m file, if there is no error, you will get the output.
[You must be registered and logged in to see this link.]
You can find in the above figure, we have just recognized the shapes with green shading. - The + sign demonstrates the focal point of each distinguished shape.
- X and Y are the x,y directions of the mid point of every shape that are appeared in dark for every recognized shape.
- Presently, We have distinguished red Shapes in the Pic, so keeping in mind the end goal to do as such what I have to do is to just change the third esteem in imsubtract capacity from 2 to 1.
Download the complete code for Color detection.
Download Full Code
- If you run this code in MATLAB, then your output will be like that:
- Now, it recognized the red shapes/Objectives in MATLAB.
- Its x,y coordinates are in Dark Color.
[You must be registered and logged in to see this link.]
In the end we will identify the blue shading, to do so, you simply have to change the third parameter to 3 and it will distinguish the blue shading like this:
That’s all for now, I hope it will help you a lot, For any kind of help ,about Color detection on image with MATLAB, Comment Below.
Sat Apr 29, 2017 10:50 am by ubedullah
» Group hackers
Sat Apr 15, 2017 2:37 pm by Group Hackers
» Hacker Needed
Sat Apr 15, 2017 3:57 am by Group Hackers
» Hacker Needed
Sat Apr 15, 2017 1:45 am by Group Hackers
» Hacker Needed
Thu Apr 13, 2017 11:10 pm by Group Hackers
» Hacker Needed
Tue Apr 11, 2017 2:07 pm by Group Hackers
» Hacker Needed
Tue Apr 11, 2017 2:21 am by Group Hackers
» Hacker Needed
Tue Apr 11, 2017 2:06 am by Group Hackers
» Hacker Needed
Tue Apr 11, 2017 1:35 am by Group Hackers