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!
  3 个评论
Walter Cromer
Walter Cromer 2023-6-1
Since posting, I have used imclose with a disk filter mask with value of 80 and it seems to work fine. I am interested in other approaches too.

请先登录,再进行评论。

回答(2 个)

Image Analyst
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.
  1 个评论
Walter Cromer
Walter Cromer 2023-6-1
Thanks! You're right in that the snippet I posted didn't define I_3. The actual code does. I was tryint to save a little space. It's really I_1 that isn't needed.

请先登录,再进行评论。


DGM
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(:))
dotispresent = logical
1
% 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).

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by