I want to turn this code into led light instead of red ones
조회 수: 1 (최근 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
댓글 수: 0
답변 (2개)
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
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
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 Center 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!