Spaces:
Runtime error
Runtime error
Update image enhancement module
Browse files1 unmodified line2345673 unmodified lines1112131415161718191 unmodified line21222324252647 unmodified lines7475767778798081821 unmodified lineimport osfrom config import file_Directoryimport numpy as npclass Image_Enhance():def __init__(self, image_path) -> None:3 unmodified lines# Load the imageimage = cv2.imread(self.image_path)#Plot the original imagealpha = 1.5# control brightness by 50beta = -150image2 = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)#Save the image# imagepth = os.path.join(os.path.dirname(self.image_path), 'Brightness & contrast.jpg')1 unmodified linecv2.imwrite(imagepth, image2)return imagepthdef sharpen(self, imagepth):image = cv2.imread(imagepth)# Create the sharpening kernel47 unmodified linescv2.imwrite(imagepath, image2)obj = Image_Enhance(r"/home/vrush/Catalog-Digitization-/src/module/data/Catalog Digitization/ONDC Test Data _ Images/Product Images/Bru_Instant_Coffee_Powder.png")pth = obj.brightness_Adjust()sharpen = obj.sharpen(pth)lapacian_sharpen = obj.lapacian_sharpen(sharpen)noise = obj.removing_noise(pth)obj.enhance_color(noise)1 unmodified line234567893 unmodified lines1314151617181920211 unmodified line232425262728293031323334353637383940414243444546474849505152535447 unmodified lines1021031041051061071081091101111 unmodified lineimport osfrom config import file_Directoryimport numpy as npfrom PIL import Imageclass Image_Enhance():def __init__(self, image_path) -> None:3 unmodified lines# Load the imageimage = cv2.imread(self.image_path)#Plot the original imagealpha = -1.1# control brightness by 50beta = 70image2 = cv2.convertScaleAbs(image, alpha=alpha, beta=beta)#Save the image# imagepth = os.path.join(os.path.dirname(self.image_path), 'Brightness & contrast.jpg')1 unmodified linecv2.imwrite(imagepth, image2)return imagepthdef remove_flash(self, imagepth):image = cv2.imread(imagepth)# cv2.cvtColor is applied over thegray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# Apply adaptive thresholding to segment the textthresh = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 11, 4)# Apply Gaussian blur to the grayscale image to reduce noiseblurred = cv2.GaussianBlur(gray, (5, 5), 0)# Threshold the blurred image to create a binary mask for the flashlight glare_, mask = cv2.threshold(blurred, 240, 255, cv2.THRESH_BINARY_INV)# Combine the text and glare masksmask = cv2.bitwise_or(mask, thresh)# Apply morphological closing to further remove small areas of glarekernel = np.ones((5,5),np.uint8)mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)# Apply the mask to the original image to remove flashlight glareresult = cv2.bitwise_and(image, image, mask=mask)cv2.imwrite(os.path.join(file_Directory, 'remove_flash.jpg'), result)def sharpen(self, imagepth):image = cv2.imread(imagepth)# Create the sharpening kernel47 unmodified linescv2.imwrite(imagepath, image2)obj = Image_Enhance(r"data/Catalog Digitization/ONDC Test Data _ Images/Product Images/Bru_Instant_Coffee_Powder.png")pth = obj.brightness_Adjust()sharpen = obj.sharpen(pth)lapacian_sharpen = obj.lapacian_sharpen(sharpen)noise = obj.removing_noise(sharpen)obj.enhance_color(noise)obj.remove_flash(sharpen)
src/module/image_enhance.py+34-5