![]() Img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) Img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) Return cv2.inRange(img_hsv, lower, upper) Here is the original image, the pre-masked image, and the completely-masked image, in that order: Print("(hMin = %d, sMin = %d, vMin = %d), (hMax = %d, sMax = %d, vMax = %d)" % (hMin, sMin, vMin, hMax, sMax, vMax))įor this, I used two simple HSV masks one to fade out the logo (using a simple formula), and one to finish off the masking by completely removing the logo. If((phMin != hMin) | (psMin != sMin) | (pvMin != vMin) | (phMax != hMax) | (psMax != sMax) | (pvMax != vMax) ): # Print if there is a change in HSV value Result = cv2.bitwise_and(image, image, mask=mask) # Convert to HSV format and color threshold # Set minimum and maximum HSV values to display VMax = cv2.getTrackbarPos('VMax', 'image') SMax = cv2.getTrackbarPos('SMax', 'image') HMax = cv2.getTrackbarPos('HMax', 'image') ![]() VMin = cv2.getTrackbarPos('VMin', 'image') SMin = cv2.getTrackbarPos('SMin', 'image') HMin = cv2.getTrackbarPos('HMin', 'image') PhMin = psMin = pvMin = phMax = psMax = pvMax = 0 HMin = sMin = vMin = hMax = sMax = vMax = 0 # Set default value for Max HSV trackbars Just change the image path import cv2Ĭv2.createTrackbar('HMin', 'image', 0, 179, nothing)Ĭv2.createTrackbar('SMin', 'image', 0, 255, nothing)Ĭv2.createTrackbar('VMin', 'image', 0, 255, nothing)Ĭv2.createTrackbar('HMax', 'image', 0, 179, nothing)Ĭv2.createTrackbar('SMax', 'image', 0, 255, nothing)Ĭv2.createTrackbar('VMax', 'image', 0, 255, nothing) To determine the HSV lower/upper ranges, you can use this HSV thresholder script with sliders so you don't need to guess and check. Result = cv2.cvtColor(colored, cv2.COLOR_BGR2GRAY)Ĭv2.imshow('result before removal', result)Ĭv2.imshow('result after removal', result)ĭepending on the image, you may need to adjust the lower/upper HSV ranges. # Convert to grayscale then remove pink contours Mask_two = cv2.inRange(colored_hsv, lower_two, upper_two) Kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3))ĭilate = cv2.dilate(mask, kernel, iterations=1)Ĭolored = cv2.bitwise_and(original, original, mask=dilate)Ĭolored_hsv = cv2.cvtColor(colored, cv2.COLOR_BGR2HSV) Hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) # Load image, convert to HSV, then HSV color threshold So now we generate a 2nd mask for the remaining pink.Ģnd mask -> convert to grayscale + invert -> applied 2nd mask to get result Notice how the background pink is gone but there are still pink artifacts around letters. Input image -> 1st HSV mask + dilation -> bitwise-and Finally we apply the result of the 2nd pass HSV mask to get our final result. We convert the result of the 1st HSV color threshold to gray then switch the background from black to white. ![]() To remove them, we perform a 2nd pass HSV threshold to remove pink around characters by generating a new mask.Ĭonvert image to grayscale then remove pink contours. Now we bitwise-and the original image with the 1st pass HSV mask to get an intermediate result but there are still pink artifacts. Because any type of thresholding will cause the letters to become washed out, we need to repair contours by dilating to reconstruct some of the characters.Ģnd pass HSV color threshold. Load the image, convert to HSV format, then HSV color threshold for binary image.ĭilate to repair contours. Here's a potential solution:ġst pass HSV color threshold. The first pass is to remove the majority of the watermark while keeping letters intact, the second is to filter out even more pink. Since we know the watermark is pink colored, we can use a two pass HSV color threshold approach. Is there a better solution that can be added? An ideal solution would be the removal of the watermark borders without affecting the text lying beneath it. Sizes = stats components = components - 1īut as shown, the resulting images are respectively inconsistent as for the watermark contours' remains and the letters washed out. Sharpened = (255*sharpened).clip(0,255).astype(np.uint8)Ĭomponents, output, stats, centroids = cv2.connectedComponentsWithStats(sharpened, connectivity=8) ![]() Sharpened = filters.unsharp_mask(division1, radius=3, amount=7, preserve_range=False) Smooth1 = cv2.GaussianBlur(gray, (5,5), 0)ĭivision1 = cv2.divide(gray, smooth1, scale=255) Gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY) Using the following code segment import skimage.filters as filters Where I'm trying to get rid of the logo itself while preserving the underlying text. And another variant of it with the exact same logo ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |