remove dots from image python 1

remove dots from image python

A lot of your questions stem from the fact that you're not sure how morphological image processing works, but we can put your doubts to rest. You can interpret the structuring element as the "base shape" to compare to. 1 in the structuring element corresponds to a pixel that you want to look at in this shape and 0 is one you want to ignore. There are different shapes, such as rectangular (as you have figured out with MORPH_RECT), ellipse, circular, etc.

As such, cv2.getStructuringElement returns a structuring element for you. The first parameter specifies the type you want and the second parameter specifies the size you want. In your case, you want a 2 x 2 "rectangle"... which is really a square, but that's fine.

In a more bastardized sense, you use the structuring element and scan from left to right and top to bottom of your image and you grab pixel neighbourhoods. Each pixel neighbourhood has its centre exactly at the pixel of interest that you're looking at. The size of each pixel neighbourhood is the same size as the structuring element.

Here is what the above code is Doing:
1. You’re creating a structuring element of size 2 x 2.
2. You’re scanning from left to right and top to bottom of your image.
3. For each pixel, you’re grabbing a 2 x 2 neighbourhood around it.
4. You’re comparing the 2 x 2 neighbourhood to the structuring element.
5. If the 2 x 2 neighbourhood is the same as the structuring element, you’re setting the pixel of interest to 255.
6. If the 2 x 2 neighbourhood is not the same as the structuring element, you’re setting the pixel of interest to 0.

Similar Posts