问题
Here is the problem:
A camera takes an image I
of a penny, a dime, and a quarter lying on a white
background and the coins do not overlap. Suppose that thresholding creates a binary image B
successfully
with 1 for the coin regions and 0 for the background.
You are given the known diameters the coins d_p
, d_d
, and d_q
in pixels (note that d_d < d_p < d_q
). How do I use morphology operations (dilation, erosion, opening, and
closing) and logical and set operations (AND, OR, NOT, and set difference), to produce three binary output images P
, D
, and Q
, where P
should contain just the penny, D
should contain just the dime, and Q
should contain just the quarter?
Can anyone give the codes or some hints? Thanks in advance!
回答1:
This obviously looks like homework so I won't write any code for you, but I'll give you some hints to push you in the right direction. The situation you described is highly idealized and not reflective of real-world situations.... which is actually great as it makes coding a lot more simpler. I'm going to assume that the picture was taken directly above the surface with the coins and not on an angle.
You already know the diameters of each of the coins, and because the diameters are in pixels, this makes this problem a whole lot easier. As such, you would specify three structuring elements that are circular that have the same diameters for each of the coins.
First do a morphological opening on
B
using the largest structuring element, which is the quarter. Opening is an erosion, followed by a dilation. One thing you should know about erosion is that any objects that are smaller than the structuring element will disappear while those that are larger will have pixels in the object that remain. As such, by doing a closing, you would remove the penny and dime, while the quarter will be fully reconstructed. One good thing about opening is that if your structuring element is smaller than the object itself, doing an opening should keep the object the same, provided that the structuring element and object follow more or less the same characteristics. Because your structuring element is circular and so are the coins, we're good to go. As such, this is your first imageQ
.Next, use the second largest structuring element, which is the penny, and do an opening on the image
B
. What will happen now is that the dime should disappear while the quarter and the penny should still remain. As such, do a set difference between this image andQ
. Our result is just the dime that is left, and so this isP
.Finally for the dime, you actually don't even need to do any morphology. Do a logical
OR
operation to combine the quarterQ
and pennyP
to get a combined image. After, do a set difference between the original imageB
and this combined image. You'll then isolate the dime, which is nowD
.
This should be enough to get you started. Good luck!
来源:https://stackoverflow.com/questions/25678240/morphology-operations-using-matlab