I want to turn this code into led light instead of red ones
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Batuhan Istanbullu
el 27 de Nov. de 2022
Comentada: Batuhan Istanbullu
el 28 de Nov. de 2022
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
0 comentarios
Respuestas (2)
Image Analyst
el 27 de Nov. de 2022
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 comentarios
Matt J
el 27 de Nov. de 2022
Editada: Matt J
el 27 de Nov. de 2022
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 comentarios
Matt J
el 27 de Nov. de 2022
You're welcome, but please Accept-click the answer as well as answers to other questions you've posted which are now resolved.
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!