Viktor Modroczký (vktr274 on GitHub)
Computer Vision @ FIIT STU
Used Methods: color space conversions, manual thresholding, adaptive thresholding, Otsu's thresholding, changing contrast, Laplacian edge detection, erosion, dilation, finding and drawing contours, calculating contour areas to remove smaller contours
Notebook: histology.ipynb
- left: green dots are cells we found (2248 cells found)
- right: original image
Zoomed in images to see the cells better:
- Load and resize the image and display each channel separately (R, G, B).
- Use R channel because it has the most contrast.
- Apply Gaussian blur to the image with a kernel size of 3 to remove noise.
- Apply inverted mean adaptive thresholding to the image with a block size of 5 and a constant of 10 because there are less visible cells in the image (some cells are not so dark therefore there is less contrast between the cells and background).
- Find contours in the image and draw them (2248 contours found).
Notebook: beer.ipynb
- left: green contours are bubbles we found (409 bubbles found)
- right: original image
- Load and resize the image and display each channel separately (R, G, B).
- Use grayscale image, no benefit from using any channel separately.
- Apply Gaussian blur to the image with a kernel size of 3 to remove noise.
- Try to use Otsu's thresholding, but it doesn't work well, brightness is not uniform over the image.
- Apply Laplacian edge detection to the blurred and unblurred image.
- Use the edge image created from the unblurred image because it has less noise.
- Dilate the edge image using a 5x5 elliptic structuring element to make the edges thicker and fuller.
- Apply manual inverted thresholding to the dilated edge image using a threshold of 20.
- Find contours in the image and draw them (409 contours found).
Notebook: blood_cells.ipynb
- left: green contours are cells we found (48 cells found)
- right: original image
- Load and resize the image and display each channel separately (R, G, B).
- Use grayscale image, no benefit from using any channel separately.
- Increase contrast of the image by using
$\alpha * img + \beta$ where$\alpha = 1.2$ and$\beta = 0$ . The chosen$\alpha$ value increases the contrast and the chosen$\beta$ value leaves the brightness unchanged. This is done to make the cells more separable from each other. Next, the values in the image are clipped to the range [0, 255]. - Use S channel from the HSV color space to create a mask of the white blood cells so we can remove them and not count them as red blood cells. The S channel is used because it has the most contrast between the white blood cells and red blood cells which is beneficial for Otus's thresholding.
- Create mask by applying Otsu's thresholding to the S channel.
- Remove small unwanted contours from the mask by calculating the area of each contour and only keeping the ones with an area greater than the mean area of all contours (
thresh = np.mean(areas)
). - Dilate the mask using a 11x11 elliptic structuring element to make the area to be removed larger to make sure we remove all the areas with white blood cells.
- Invert the mask using bitwise not.
- Denoise the original grayscale image by applying median blur with a kernel size of 5.
- Apply inverted mean adaptive thresholding to the denoised image with a block size of 61 and a constant of 5.
- Apply the mask to the thresholded image to remove the white blood cells.
- Remove small unwanted contours from the thresholded image by calculating the area of each contour and only keeping the ones with an area greater than the difference of the mean area of all contours and the standard deviation of all contour areas (
thresh = np.mean(areas) - np.std(areas)
) - Erode the binary image using a 5x5 elliptic structuring element to improve the separation of the red blood cells.
- Find contours in the image and draw them (48 contours found).
The biggest challenge was to separate the overlapping red blood cells in the image. We found that here is a trade-off between good cell separation and the accuracy of the contours. The chosen method of increasing the contrast and using erosion to separate the cells worked pretty well. However, the contours do not represent cell shapes very well. If we were to use different adaptive threshold parameters and/or no erosion, we could copy the actual outside contours of the cells, but this would lead to less cells being found due to worse separation, and multiple cells being identified as one due to the overlaps.