How to indentify a broken pill package?

4 次查看(过去 30 天)
Hello, I am writing a program, which should read in an image of a pill package and count how many pills are left over in the package. The code uses a combination of image processing functions including the canny transform into a gradient image and the hough transform for circles. Here are some images to understand what I am talking about (The numbers in the green circles show the order of the circles' metric values, from high to low)
Now I am trying to write some code, which can identify the difference between pills, which are already used and those, which are still left over in the package. Unfortunately the metric value does not give a good indication if the pill pocket is broken or not. I also calculated a ratio where I divided the number of gradient pixels by the total area of the circle. Unfortunately this value is also very unreliable for this problem.
Do you have any other ideas how to identify which of these pill pockets are broken? If it helps, the full pill package is always analyzed first and then, some informations are saved and can be loaded into the code again as a possible comparision. However, the images are never 100% the same, since they are all done by hand within an app.
I'm thankful for any tips, ideas and help!

采纳的回答

Image Analyst
Image Analyst 2020-10-9
I'd probably start with just having a mask/template with ROIs over each pill pocket and take the standard deviation of the image intensities. If the standard deviation is high, then it's been used. If it's low, then the intensity if pretty uniform and the pill has not been pushed out.
Or you could try a deep learning app.
  17 个评论
Image Analyst
Image Analyst 2020-10-12
Yes, I'd just start with the cropped bounding box image. And of course you'll need the cropped circular mask image also so you can get the EDT of that so you know what radius the pixel's intensity is measured at.
Jannis Holtkoetter
Jannis Holtkoetter 2020-10-12
I applied your recommendation of using the crop and feeding these images into a loop with the averageRadialProfile function. I have to say, that I used the grayscale image based on the local standard deviation filter (values between 0 and 1). Is that a problem and should I have used just a grayscale version of the original jpg image (values between 0 and 255? Does it change anything?
The caluclation is being done with the code, which you provided in the file "average_radial_profile.m", as shown in the following. I was looking into the documentation of the different functions, but had problems to fully understand what the averageRadialProfile actually describes...
edtImage = bwdist(binaryImage);
maxDistance = ceil(max(edtImage(:)));
% Allocate an array for the profile
profileSums = zeros(1, maxDistance);
profileCounts = zeros(1, maxDistance);
% Scan the original image getting gray level, and scan edtImage getting distance.
% Then add those values to the profile.
[rows, columns] = size(edtImage);
for column = 1 : columns
for row = 1 : rows
thisDistance = round(edtImage(row, column));
if thisDistance <= 0
continue;
end
profileSums(thisDistance) = profileSums(thisDistance) + double(grayImage(row, column));
profileCounts(thisDistance) = profileCounts(thisDistance) + 1;
end
end
% Divide the sums by the counts at each distance to get the average profile
averageRadialProfile = profileSums ./ profileCounts;
In the loop I put each averageRadialProfile array into one cell array which now contains the averageRadialProfile for each pill. If I plot it for the example above, it gives me this result (the plots with the red circle are broken pills). How would can I analyze these results in a quantified way, so that I can atleast draw some conclusion between the average radial profile and a broken pill?
Again, I would be very thankful for any help!

请先登录,再进行评论。

更多回答(1 个)

Jannis Holtkoetter
Jannis Holtkoetter 2020-10-22
I just accepted the answer with regard to the fact, that I will be able to use the mean intensity of the local standard deviation image for each pill in combination with the mean intensity of a canny edge image for each pill to define if a pill can be marked as used or not. It is definetly not working perfect but it works for a lot of specific looking blisters.
I still do not really know, how to interpret the radial profile of each pills and therefore I have no use for it, however the provided code worked for me and I could compute each radial profile in my example. I'm still open for any explanation or suggestion for implementation.

Community Treasure Hunt

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

Start Hunting!

Translated by