I want to turn this code into led light instead of red ones

3 次查看(过去 30 天)
Hi, I want to turn this code into led light instead of red ones. How may I do that; which part should I change?
Here is my code;
data =imread('IMG_4236.JPG');
% Now to track red objects in real time
% we have to subtract the red component
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);
% Remove all those pixels less than 300px
diff_im = bwareaopen(diff_im,300);
% Label all the connected components in the image.
bw = bwlabel(diff_im, 8);
% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
%This is a loop to bound the red objects in a rectangular box.
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', 'yellow');
end
and here is the image

回答(2 个)

Image Analyst
Image Analyst 2022-11-27
I don't know what this means: "turn this code into led light instead of red ones".
You can't turn code into a light. The light you have in your scene is white. If you want a red LED instead of a white one, then put a red LED into your circuit. It has nothing to do with code. It has to do with electrical components and perhaps a soldering iron or a breadboard or other components to build circuits with.
The bright light in the image is not red. Plus your algorithm is just overly simplistic (even if the light were red) and basically no good. If you want to track a colored object in an image, see my attached demo where I track a green Sharpie marker in a video.
  15 个评论
Batuhan Istanbullu
Batuhan Istanbullu 2022-11-28
I do not know where I'm doing wrong when I'm trying to implement your code to my values and my video

请先登录,再进行评论。


Matt J
Matt J 2022-11-27
编辑:Matt J 2022-11-27
Is this what you want?
IMG=load('Image').A;
c=regionprops(all(IMG>250,3),'Centroid').Centroid; %LED centroid/position
imshow(IMG); hold on
plot(c(1),c(2),'rx'); hold off
  6 个评论
Matt J
Matt J 2022-11-27
You're welcome, but please Accept-click the answer as well as answers to other questions you've posted which are now resolved.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by