Logo elodees  elodees

A caring AI for a better world













Only alphabetic characters accented or not as well as the space are accepted

Logo IA




Histogram matching





No account yet ?

Sign up to access all content








Source : https://scikit-image.org/docs/stable/auto_examples/color_exposure/plot_histogram_matching.html





Tensorflow playground


Tensorflow playground




Tested in Anaconda and Python 3.7

import numpy as np
import cv2
from matplotlib import pyplot as plt
 
asli = cv2.imread('dst.jpg')
 
plt.imshow(cv2.cvtColor(asli, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.title('Destination image')
plt.show()
 
equ = np.copy(asli)
 
for i  in range (3) :
    equ[:,:,i] = cv2.equalizeHist(asli[:,:,i])
 
referensi =  cv2.imread('ref.jpg')
 
plt.imshow(cv2.cvtColor(referensi, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.title('Reference image')
plt.show()
 
hasilmatch = np.copy(asli)
 
def hist_match(asli, referensi):
 
    asli_shape = asli.shape
 
    asli = asli.ravel()
    referensi = referensi.ravel()
 
    o_values, bin_idx, o_counts = np.unique(asli, return_inverse=True,return_counts=True)
    b_values, b_counts = np.unique(referensi, return_counts=True)
 
    o_quantiles = np.cumsum(o_counts).astype(np.float64)
    o_quantiles /= o_quantiles[-1]
    b_quantiles = np.cumsum(b_counts).astype(np.float64)
    b_quantiles /= b_quantiles[-1]
 
    interp_t_values = np.interp(o_quantiles, b_quantiles, b_values)
 
    return interp_t_values[bin_idx].reshape(asli_shape)
 
for i  in range (3) :
    hasilmatch[:,:,i] = hist_match(asli[:,:,i], referensi[:,:,i])
 
plt.imshow(cv2.cvtColor(hasilmatch, cv2.COLOR_BGR2RGB))
plt.axis('off')
plt.title('Histogram matching')
plt.show()
 


Source

Histogram matching destination

Reference

Histogram matching reference

Histogram matching

Histogram matching


Source

Histogram matching destination

Reference

Histogram matching reference

Histogram matching

Histogram matching












Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !

Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License