Let’s just remove some additional noise before applaying the Otsu threshold. In this tutorial we use Otsu thresholding. There are a lot of different ways to use image thresholding, try them and find out which works best in your case, you can read more about it here. We can create a manual threshold with: # Manual image thresholding _, EdgeImage = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) Next we are going to use image thresholding to set values that are near black to black and set values that are near white to white. Let us first convert it to a greyscale image: # Convert the image to greyscale (1D) img_lp_im_grey = cv2.cvtColor(img_lp_im, cv2.COLOR_BGR2GRAY) img_lp_gb_grey = cv2.cvtColor(img_lp_gb, cv2.COLOR_BGR2GRAY) img_lp_mb_grey = cv2.cvtColor(img_lp_mb, cv2.COLOR_BGR2GRAY) img_lp_al_grey = cv2.cvtColor(img_lp_al, cv2.COLOR_BGR2GRAY)Įach variable now contains a 1-dimensional array instead of a 3-dimensional array. We need an image preferably black and white that we can use as a mask. The image with all the filters is the sharpest, which comes in handy in a bit. You can now see that Laplacian of the original image detected a lot of noise. Photo by Daniel Gomez on Unsplash - Edited by author We can of course also visualise the results to see the differences. That is why we will apply some image filtering before applying the laplace filter: Filtering # Apply some Gaussian blur on the image img_gb = cv2.GaussianBlur(img, (7, 7) ,0) # Apply some Median blur on the image img_mb = cv2.medianBlur(img_gb, 5) # Apply a bilateral filer on the image img_bf = cv2.bilateralFilter(img_mb, 5, 80, 80) The Laplacian filter is a very nice filter (read more about it here). In this tutorial I will use a laplacian filter to detect image edges. If you play around with the Notebook (see the end of this article), you see that for the plotting I converted the image from BGR to RGB. A little note, cv2 open the image as BGR (order of the spectrum) and not RGB as most people are used to. We can use the cv2 library to directly open an image: # Opens an image with cv2 img = cv2.imread('DanielGomez.jpg')Ĭv2 uses numpy to open images, the 'img' variable now contains a numpy array of 3 dimensions. We start with importing both libraries: # Import necessary libraries import cv2 import numpy as np
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |