In [1]:
%matplotlib inline
from matplotlib import pyplot as plt, cm
import cv2
In [5]:
# load the image and convert it to grayscale
image = cv2.imread("./data/retina.png")
orig = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# the area of the image with the largest intensity value
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
cv2.circle(image, maxLoc, 5, (255, 0, 0), 2)
# display the results of the naive attempt
plt.figure(figsize=(16,12))
plt.subplot(121), plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), cmap = 'gray')
plt.title('Original Image')
# apply a Gaussian blur to the image then find the brightest region
# I showed you why it is critical to apply Gaussian blurring prior to finding the brightest spot in an image
gray = cv2.GaussianBlur(gray, (41, 41), 0)
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray)
image = orig.copy()
cv2.circle(image, maxLoc, 41, (255, 0, 0), 2)
# display the results of our newly improved method
plt.subplot(122), plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB), cmap = 'gray')
plt.title('Robust Image')
Out[5]:
In [ ]: