Okay guys, I am stuck trying to create a histogram matching for two images; a template image and a destination image(destination meaning the image where i want to match the template image). Rather than displaying the matched image, i get a blank image. I feel like i am exhausted at this hence why i came to SO. Can someone guide me in the right direction?
Any Help in the right direction would be appreciated.
def matching(template, target, numberOfBins=256):
templateHist, bins1 = np.histogram(template.flatten(), numberOfBins, density = False)
targetHist, bins2 = np.histogram(target.flatten(), numberOfBins, density = False)
cdfTemplate = templateHist.cumsum() #Cumulative distributed function
cdfTemplate = (255 * cdfTemplate / cdfTemplate[-1]) #normalize
cdfTarget = targetHist.cumsum()
cdfTarget = (255 * cdfTarget / cdfTarget[-1]).astype(np.float64)
im2 = np.interp(template.flatten(), cdfTemplate, bins1[:-1])
im3 = np.interp(im2, cdfTarget, bins2[:-1])
result = im3.reshape((template.shape))
return result