Created
September 13, 2016 03:20
-
-
Save sriharsha0806/45d0a22cbcdb40f66d354488905281ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Aug 31 16:29:33 2016 | |
Reference: opencvpython.blogspot.com/2013/03/histograms-2-histogram-equalization.html | |
@author: sriharsha | |
""" | |
import cv2 | |
import numpy as np | |
from matplotlib import pyplot as plt | |
img = cv2.imread('Fig0228(a)(angiography_mask_image).tif') | |
cv2.imshow('Mask_image',img) | |
cv2.waitKey(100) | |
img1 = cv2.imread('Fig0228(b)(angiography_live_ image).tif') | |
cv2.imshow('live_image',img1) | |
cv2.waitKey(100) | |
diff = cv2.subtract(img,img1) | |
diff = np.absolute(diff-175) | |
[X,Y,Z]=diff.shape | |
#diff = cv2.resize(Diff,(2*X,2*Y)) | |
cv2.imshow('Difference_2images',diff) | |
cv2.waitKey(1000) | |
cv2.imwrite('Digital subtraction Angiography.tif',diff) | |
#equ = cv2.equalizeHist(Diff) | |
#res = np.hstack(diff,equ) | |
#cv2.imwrite('res.tif',res) | |
# numpy implementation | |
hist,bins = np.histogram(diff.flatten(),256,[0,256]) | |
cdf = hist.cumsum() | |
cdf_normalized = cdf*hist.max()/cdf.max() # this line is not necessary | |
plt.plot(cdf_normalized,color='b') | |
plt.hist(diff.flatten(),256,[0,256],color='r') | |
plt.xlim([0,256]) | |
plt.legend(('cdf','histogram'),loc='upper left') | |
plt.show() | |
cdf_m = np.ma.masked_equal(cdf,0) | |
cdf_m = (cdf_m-cdf_m.min())*255/(cdf_m.max()-cdf_m.min()) | |
cdf = np.ma.filled(cdf_m,0).astype('uint8') | |
img2 = cdf[diff] | |
cv2.imshow('img2',img2) | |
cv2.waitKey() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment