How to detect green laser spot with nearly white center
4 次查看(过去 30 天)
显示 更早的评论
Our system shines a 1mW green dot laser onto a white / off-white background under certain conditions. The surface has blobs of gel and seeds appearing as well so it is not a perfectly uniform background. But they have a very low level of green. I need to detect the presence of the green dot. The video does not have to be processed in real-time.
The dot from the laser that appears has a very bright, more white than green, center, surrounded by the green light. It is always generally in the same location in the video we take.
Previously, when using a green LED, the code below worked because the LED did not make a brilliant white spot in the center. But the LED is not overall bright enough to meet our needs. Hence the laser.
I = read(MyVideo,FrameToExamine);
I_1 = I(:,:,1);
I_2 = I(:,:,2);
I_X = I_2 - I_3;
I_B = imbinarize(I_X,"adaptive");
I_Dot = I(GreenDotXStart:GreenDotXEnd, GreenDotYStart:GreenDotYEnd); %% These values define the position of the
%% the dot is in.
rSumDot = sum(I_Dot,2);
OverallSumDot = sum(rSumDot);
if OverallSumDot > 100 %% a threshold value
GreenLightState(FrameToExamine,2) = 1; %% record the green dot was found in the frame
else
GreenLightState(FrameToExamine,2) = 0; %% record the green dot was not found in the frame
end
I'm thinking that if I could mask the brilliant center area of the laser dot, I could use the same code above to detect the presence of the dot. But I don't know how to create and apply such a 'donut hole' mask. Help will be much appreciated!
回答(2 个)
Image Analyst
2023-6-1
If it worked with a green LED but not the green laser because the green laser dot is more white inside, then just fill the binary image:
I_B = imbinarize(I_X,"adaptive");
% Fill white center:
I_B = imfill(I_B, 'holes');
Maybe it will work after that.
By the way, your code did not define I_3.
DGM
2023-6-1
编辑:DGM
2023-6-1
here's this, FWIW.
inpict = imread('dot.png');
% get bright spots that coincide with green spots
% centers of green spots don't need to also be green
[Y,~,Cr] = imsplit(rgb2ycbcr(inpict));
mask = (Y>=139) & imfill(Cr<=118,'holes');
% you'll probably need to do something to make sure
% that the mask doesn't select other bright green things
% get rid of small or thin blobs
mask = imopen(mask,strel('disk',4));
% if there are any blobs left, assume they're the one we want
dotispresent = any(mask(:))
% get the center position of the dot and show it
% this isn't necessary for your processing,
% but it's helpful at least for debugging and for this demo
S = regionprops(mask,'centroid');
imshow(inpict,'border','tight'); hold on
xy = S.Centroid;
plot(xy(1),xy(2),'kx')
The radius of the strel used in imopen() will need to be adjusted to somewhat less than half the expected dot diameter. I don't know what that actually is, since I'm working on a screenshot, and not the original image.
Depending on what size the actual images, how much the presentation varies, and whether there are cases where other bright green things might appear, it may be worthwhile to do extra filtering to make sure that any blobs in the mask are actually dots (based on their size or shape, etc).
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Computer Vision with Simulink 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!