Professional Documents
Culture Documents
P4-Log - Power, Contrast, Histo, Threshol, Halftoning
P4-Log - Power, Contrast, Histo, Threshol, Halftoning
def log_transformation(image):
epsilon = 1e-10 # Small value to avoid division by zero
c = 255 / np.log(1 + np.max(image))
image_log = np.log(1 + image + epsilon)
log_transformed = c * image_log
log_transformed = np.array(log_transformed, dtype=np.uint8)
return log_transformed
def histogram_equalization(image):
equalized = cv2.equalizeHist(image)
return equalized
def halftoning(image):
_, binary = cv2.threshold(image, 128, 255, cv2.THRESH_BINARY)
return binary
# Read an image
image_path = r'C:\Users\Lenovo\Downloads\flower.jpeg'
image = cv2.imread(image_path, 0) # Read as grayscale
if image is None:
print("Error: Unable to read the image file.")
exit() # Exit the program or handle the error appropriately
# Apply transformations
log_transformed = log_transformation(image)
power_transformed = power_law_transformation(image, gamma=0.5) # Example gamma
value
adjusted_contrast = contrast_adjustment(image, alpha=1.5, beta=0) # Example alpha
and beta values
equalized = histogram_equalization(image)
thresholded = thresholding(image, threshold=128) # Example threshold value
halftoned = halftoning(image)
plt.tight_layout()
plt.show()