How to detect contents of a beaker in an image
1 view (last 30 days)
Show older comments
I have an image of a beaker in which I want to automatically detect the contents of the beaker. I cannot use the intensity for this because sometimes the intensity of the beaker content is the same as the one in the walls. Also the the length and height of the beaker content is not always the same. Is there a method that I can use to create a mask for just the beaker content without having to do it manually?
8 Comments
Image Analyst
on 7 Feb 2023
Attach the original image, not a screenshot with tick marks, tick labels, and other stuff. We want just the bare image. Not a figure or .fig file, just the original .tiff, .jpg, or .PNG file.
Answers (2)
DGM
on 7 Feb 2023
Here's an initial attempt. How well this works really depends on how vague the gap between the blobs can be. As Walter mentions, if there are images other than screenshots, that would probably help too.
% read the images
A = imread('bk1.png');
B = imread('bk2.png');
imshow(generatemask(A))
imshow(generatemask(B))
function mk = generatemask(inpict)
% try to make things less sensitive to value
inpict = imadjust(inpict);
% binarize (idk how well this will work across all images)
mk = imbinarize(inpict,'adaptive','sensitivity',0.7);
% clean up the mask
mk = imopen(mk,ones(5)); % try to break any small bridges
mk = imfill(mk,'holes'); % fill any holes
mk = bwareaopen(mk,10E3); % get rid of small blobs
mk = bwpropfilt(mk,'extent',[0.85 1]); % keep blobs which are roughly grid-aligned rectangles
mk = bwareafilt(mk,1); % keep the largest remaining blob
end
As to how to apply watershed segmentation to this problem, I'm not the one to ask, but if it's a particularly good use-case, I'd like to see an example applied to this specific problem.
0 Comments
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!