This map below conveys a lot of information using color. Topographic lines are brown, water features are blue. It’s a visually complex map. I wanted to see if I removed non-text blue and brown features on the map, could I improve optical character recognition of the text in black. This is a quick note about the process.
I used this short program to filter the color so that features in black were retained while lighter colors were changed to white (255,255,255).
import cv2 import numpy as np # This is the 1 map tile we'll use for this example: from google.colab.patches import cv2_imshow img = cv2.imread('/content/drive/MyDrive/crane_maps_syria/maps_large/Djeble_georef/jpg_tiles/r07c09.jpg',-1) print("before") cv2_imshow(img) # Thanks to https://stackoverflow.com/questions/50210304/i-want-to-change-the-colors-in-image-with-python-from-specific-color-range-to-an hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV) # Define lower and uppper limits of what we call "black" color_lo=np.array([0,0,0]) color_hi=np.array([90,90,115]) # Mask image to only select black text mask=cv2.inRange(hsv,color_lo,color_hi) img[mask==0]=(255,255,255) cv2.imwrite("result.png",img) img2 = cv2.imread('result.png',-1) print("after") cv2_imshow(img2)
Below is the result of transcription and there is no visible benefit here. However this appears to be a useful method for separating analysis of map elements using color.