I have a image and I want to do HE or CLAHE on specific area of the image. I already have a mask for the image. Is there any possible way to do so?
I have a image and I want to do HE or CLAHE on specific area of the image. I already have a mask for the image. Is there any possible way to do so?
Here is the code to achieve that :
import cv2 as cv
import numpy as np# Load your color image
#src = cv.imread("___YourImagePath__.jpg",
#cv.IMREAD_COLOR)#Create random color image
src = np.random.randint(255, size=(800,800,3),dtype=np.uint8)
cv.imshow('Random Color Image',src)
cv.waitKey(0)# conver to gray
gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)# process gray image
equalized = cv.equalizeHist(gray)# create a mask (binary image with same size as source image )
height,width,depth = src.shape
mask = np.zeros((height,width))
cv.circle(mask,( int(width/2),int(height/2)),int(width/3),1,thickness=-1)# display mask
cv.imshow('Mask',mask)
cv.waitKey(0)# Copy processed region using the mask
ProcessedRegion = np.where(mask!=0,equalized,gray)#display result
cv.imshow('Processed region result', ProcessedRegion)
cv.waitKey(0)
Output :